2

I am in the process of learning JPA - Hibernate.

I am following this article In Dog.java it is mentioned as @Table(name = "dog"). In persistence.xml I have the following

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

Does this creates table dog in database? I have not created table Dog in database. So in production environment this could be dangerous though. In such scenarios what should be ideal value for hibernate.hbm2ddl.auto?

Any suggestions?

4 Answers 4

4

it's dangerous in all senses, your application user should not have DDL permissions (alter table, create tables) your application user should only do DML (SELECT, INSERT,UPDATE,DELETE, etc)

Sign up to request clarification or add additional context in comments.

2 Comments

If application user should do only DML, then what should be the value for hibernate.hbm2ddl.auto? Is it none? Thanks
just don't add it, comment it out. Reason behind is someone can manipulate that connection in order to drop a table or something. more secure if you don't manipulate with same user.
2

Yes, it does create the new table every time that your app is deployed. Better to use:

<property name="hibernate.hbm2ddl.auto" value="validate"/>

if you already have data in place.

Here are the possible options:

  • validate: validate the schema, makes no changes to the database.
  • update: update the schema.
  • create: creates the schema, destroying previous data(!)
  • create-drop: drop the schema at the end of the session(!)

Comments

1

Do not set <property name="hibernate.hbm2ddl.auto" value="create"/> in production, because whenever you restart the server, all tables will be deleted and newly created again. You can make use of this property(hibernate feature) if you are migrating from one database to another.

If you want to set then set <property name="hibernate.hbm2ddl.auto" value="update"/> in development(not in production). This will update the schema if there are any changes you have made in pojo classes(annotations).

Also check : Hibernate: hbm2ddl.auto=update in production?

Hibernate hbm2ddl.auto possible values and what they do?

Comments

1

Set it to "none" in a production environment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.