5

Correct me if i am wrong!.
Generally, if hbm2ddl.auto is set to "UPDATE", hibernate checks if the table exists in db or not, if not it creates that table and pushes the data, if table exists it just adds data to that table.
for hbm2ddl.auto = update, What i observed is, before every insertion, hibernate is trying to create the table. though the table exists, it throws exception in log and then hibernate come to know that about the existence of table.
is this a normal behavior ? or i am missing something ?

please find below log generated with the help of log4j in console..

Hibernate: create table UsersCC (userID int4 not null, userDOB date, userEmail varchar(255), userPswd varchar(255), primary key (userID))
23:02:27,799  WARN ExceptionHandlerLoggedImpl:27 - GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL via JDBC Statement
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:67)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlString(AbstractSchemaMigrator.java:524)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.applySqlStrings(AbstractSchemaMigrator.java:470)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.createTable(AbstractSchemaMigrator.java:273)
    at org.hibernate.tool.schema.internal.GroupedSchemaMigratorImpl.performTablesMigration(GroupedSchemaMigratorImpl.java:71)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.performMigration(AbstractSchemaMigrator.java:203)
    at org.hibernate.tool.schema.internal.AbstractSchemaMigrator.doMigration(AbstractSchemaMigrator.java:110)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.performDatabaseAction(SchemaManagementToolCoordinator.java:183)
    at org.hibernate.tool.schema.spi.SchemaManagementToolCoordinator.process(SchemaManagementToolCoordinator.java:72)
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:309)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:445)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:710)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
    at com.hibernate.Setup.SetupTest.main(SetupTest.java:19)
Caused by: org.postgresql.util.PSQLException: ERROR: relation "userscc" already exists
    at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2310)
    at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2023)
    at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:217)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:421)
    at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:318)
    at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:310)
    at org.hibernate.tool.schema.internal.exec.GenerationTargetToDatabase.accept(GenerationTargetToDatabase.java:54)
    ... 13 more
Hibernate: insert into UsersCC (userDOB, userEmail, userPswd, userID) values (?, ?, ?, ?)
23:02:27,998 TRACE BasicBinder:65 - binding parameter [1] as [DATE] - [Sun Jan 01 23:02:25 IST 2017]
23:02:27,999 TRACE BasicBinder:65 - binding parameter [2] as [VARCHAR] - [motogg@support.com]
23:02:28,000 TRACE BasicBinder:65 - binding parameter [3] as [VARCHAR] - [lenovo18]
23:02:28,004 TRACE BasicBinder:65 - binding parameter [4] as [INTEGER] - [101]
23:02:28,013  INFO pooling:230 - HHH10001008: Cleaning up connection pool [jdbc:postgresql://localhost:5432/campusCafeDb]

if its normal, then isn't it a performance issue ?

lovelyim92
  • 141
  • 2
  • 9
  • thanks.. i made hbm2ddl.auto silent. :D. anyway, could you please shed some light on VALIDATE, which you mentioned in your comment ? – lovelyim92 Jan 01 '17 at 18:01

2 Answers2

0

hbm2ddl.auto Validate : If the value is validate then hibernate only validates whether the table and columns are exist or not. If the table doesn’t exist then hibernate throws an exception. Validate is the default value for hbm2ddl.auto.

hbm2ddl.auto update : If the value is update then hibernate checks for the table and columns. If table doesn’t exist then it creates a new table and if a column doesn’t exist it creates new column for it.

This link has beautiful explanation on all of the values.

http://www.onlinetutorialspoint.com/hibernate/hbm2ddl-auto-example-hibernate-xml-config.html

none is unofficial value i guess. I found it somewhere in stackoverflow but I forgot where.

Faraz
  • 6,025
  • 5
  • 31
  • 88
0

This is what worked for me temporarily, I commented the "hibernate.hbmddl.auto" property entirely and hibernate stopped attempting to create the tables that already exist, see below.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Connection settings -->
<property name="hibernate.connection.url">******</property>
<property name="hibernate.connection.username">******</property>
<property name="hibernate.connection.password">******</property>
<property 
name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="hibernate.connection.isolation">2</property>
<property name="hibernate.connection.provider_class">
org.hibernate.service.jdbc.connections.internal.
C3P0ConnectionProvider
</property>
<property name="hibernate.c3p0.acquire_increment">5</property>
<property name="hibernate.connection.driver_class">
org.postgresql.Driver
</property>
<property name="hibernate.c3p0.unreturnedConnectionTimeout">30
</property>
<property  name="hibernate.c3p0.
debugUnreturnedConnectionStackTraces">true</property>
<property name="show_sql">true</property>
<!--<property name="hibernate.hbm2ddl.auto">update</property>-->
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">100</property>
<property name="hibernate.c3p0.timeout">120</property>
<mapping resource="dbstructure.hbm.xml" />
</session-factory>
</hibernate-configuration>

However I had to ensure additional update to the tables are well mapped in the mapping file and the POJO classes respectively

And if there was going to be any error, I would see it in the log when it attempt to perform any DDL or DML operation

Cheers

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 22 '22 at 13:14