Reputation: 14731
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?
Upvotes: 2
Views: 5446
Reputation: 159784
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:
Upvotes: 2
Reputation: 16158
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?
Upvotes: 1
Reputation: 2242
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)
Upvotes: 4