Reputation: 2197
I have such hibernate.cfg.xml:
<hibernate-configuration>
<session-factory>
<property name="connection.url">jdbc:postgresql://host:5432/app-dev</property>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="hbm2ddl.auto">validate</property>
...many mappings
</session-factory>
And the problem is that it's trying to update my database schema, but I want to disable that feature.
log from my application:
2015-08-29 16:29:57 ERROR SchemaUpdate:261 - HHH000388: Unsuccessful: create table myschema.public.mytable (id int4 not null, count int4, anotherid int4, onemoreid int4, primary key (id))
2015-08-29 16:29:58 ERROR SchemaUpdate:262 - ERROR: syntax error at or near "-" <<(mydatabase name contains "-" sign)
Position: 27
I also tried to leave hbm2ddl.auto tag empty or include 'none' value in it.
Upvotes: 0
Views: 896
Reputation: 1
Validate is the default property of hbm2ddl.auto, even if you dont specify hbm2ddl.auto property, then also it is by default validate. Secondly there is no such value as "none", there are only 4 options :
validate- it simply checks that table and its columns are existing in database or not an if a table does not exist or any column does not exist than Exception is thrown.
create - If the value is create than hibernate drops the table if it already exist and then creates a new table and executes the operation, this is not used in real time as the old data is lost from database.
update - If the values is update than hibernate uses existing table and if the table does not exist than creates a new table and executes operation. This is mostly and often used in real time and it is recommended.
create-drop - if the value is create-drop than hibernate creates a new table and after executing the operation it drops the table, this value is used while testing hibernate code.
Thanks Njoy Coding
Upvotes: 0
Reputation: 26077
Remove Hibernatehbm2ddl.auto
defaults to Hibernate
not doing anything.
From the docs
The hbm2ddl.auto option turns on automatic generation of database schemas directly into the database. This can also be turned off by removing the configuration option, or redirected to a file with the help of the SchemaExport Ant task.
Upvotes: 0
Reputation: 5297
Remove the property <property name="hbm2ddl.auto">validate</property>
entirely.
By default all options will be false and hibernate will not attempt to do any updates.
Upvotes: 2