Creating table automatically using Hibernate

I tried GenerationType.IDENTITY to my Entity class. it looks ike this

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private int id;

and added

property name="hibernate.hbm2ddl.auto " as “update”

to hibernate.cfg file. But it didn’t created the Entity to schema automatically.
When i used

GenerationType.AUTO

it works fine. I am new in hibernate. Any explanation ?

You need to paste the stack trace to see what happens. You say it does not work, but let’s see that in the output.

I am using the hibernate.hbm2ddl.auto feature to create the tables. I know that it is not advised to use it in production.

But, what I want to do, is to use it to create the table only when the database is void. When database is not empty, i would like my app to work with this setting off.

How could i do it (the easiest way).

You can use set the hibernate.hbm2ddl.auto property to create-only.

<property name="hibernate.hbm2ddl.auto" value="create-only" />