Pages

Implementing Naming Convention

Implementing Naming Convention

Hibernate has been provided a NamingStrategy interface to apply the naming convention automatically for database table name and column name. 
Let say database table name should be started by "AB_". So you have to create a class that have to extend it  from ImprovedNamingStrategy class and override the following methods.

public class ABNamingStrategy extends ImprovedNamingStrategy {

private static final long serialVersionUID = 1L;

@Override
public String classToTableName(String className) {
return StringHelper.unqualify(className);
}
@Override
public String propertyToColumnName(String propertyName) {
return propertyName;
}
@Override
public String tableName(String tableName) {
return "AB_"+tableName.toUpperCase();
}
@Override
public String columnName(String columnName) {
return columnName;
}

@Override
public String propertyToTableName(String className, String propertyName) {
return "AB_" + classToTableName(className) + "_" +   
                           propertyToColumnName(propertyName);
}
}

classToTableName method will be call when class mapping do not have explicitly table name,  propertyToColumnName method will be call when property element do not have explicitly column name.

Now, you have to do some change in HibernateUtil class,

sessionFactory = new Configuration().setNamingStrategy(new  CENamingStrategy()).configure().buildSessionFactory();   
 


Making Entity Immutable

Making Entity Immutable

You can use mutable attribute of class element in class mapping metadata. Default value of this attribute is true. If you make class as a immutable i.e mutable="false" than no UPDATE SQL statement will not be execute for this class or Entity.

If i run the following code than it will not execute any UPDATE SQL statement, 
Note: we have set mutable="false" for this case,


public class HibernateTest {
private final static Logger LOGGER = Logger.getLogger(HibernateTest.class); 
/**
* @param args
*/
public static void main(String[] args) {
LOGGER.info("starting of main method");
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction txn = session.beginTransaction();
Item item = (Item) session.get(Item.class, 1L);
item.setItemName("Nokia");
session.saveOrUpdate(item);
txn.commit();
session.close();
HibernateUtil.shutDown();
}
}
 
See the generated comments on console:

Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Oct 10, 2012 4:11:12 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 10, 2012 4:11:12 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 10, 2012 4:11:12 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 10, 2012 4:11:12 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: HibernateTest.item
Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [created_date, modified_date, item_name, item_id, item_amount]
Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Oct 10, 2012 4:11:12 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Oct 10, 2012 4:11:12 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
Hibernate: /*load com.Item*/select item0_.ITEM_ID as ITEM1_0_, item0_.ITEM_NAME as ITEM2_0_0_, item0_.ITEM_AMOUNT as ITEM3_0_0_, item0_.CREATED_DATE as CREATED4_0_0_, item0_.MODIFIED_DATE as MODIFIED5_0_0_ from ITEM item0_ where item0_.ITEM_ID=?
Oct 10, 2012 4:11:12 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing



Use of dynamic-insert and dynamic update

Dynamic-insert and Dynamic-update in XML mapping metadata

There are two attribute for disabling CRUD SQL generation on startup which are available for <class> mapping. 

<class name="category" dynamic-insert="false" dynamic-update="false">
....
</class>

Note : default values of these attributes are false. 
If you set dynamic-insert="true" in your class mapping metadata than null property values will not include in your INSERT SQL statement.
If you set dynamic-update="true" in your class mapping metadata than it includes only modified property values in UPDATE SQL statement.

Example :
I have an Item entity which have some property as follows,














I am trying to store item object into database. i run following code. default setting is dynamic-insert = "false" in class mapping metadata.
















See the following comments on console.

14:59:10,286      INFO HibernateTest:19 - starting of main method
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0rc1
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: com/Item.hbm.xml
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.Item -> ITEM
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 10, 2012 2:59:10 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Oct 10, 2012 2:59:10 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Oct 10, 2012 2:59:10 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 10, 2012 2:59:10 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: null at URL: jdbc:mysql://localhost:3306/HibernateTest
Oct 10, 2012 2:59:10 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {autocommit=true, password=****, user=root}
Oct 10, 2012 2:59:10 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: true
Oct 10, 2012 2:59:10 PM org.hibernate.connection.C3P0ConnectionProvider configure
WARNING: No JDBC Driver class was specified by property hibernate.connection.driver_class
14:59:10,538      INFO MLog:80 - MLog clients using log4j logging.
14:59:10,773      INFO C3P0Registry:204 - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
14:59:10,830      INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@3c719ea5 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@39948757 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|cdd17f, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@888ae846 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|693a5, jdbcUrl -> jdbc:mysql://localhost:3306/HibernateTest, properties -> {autocommit=true, password=******, user=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|c0c9d0, numHelperThreads -> 3 ]
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Oct 10, 2012 2:59:11 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Oct 10, 2012 2:59:11 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Oct 10, 2012 2:59:11 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 10, 2012 2:59:11 PM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Anuj/Jars/HibernateLib/ehcache-1.1.jar!/ehcache-failsafe.xml
Oct 10, 2012 2:59:11 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Oct 10, 2012 2:59:11 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Oct 10, 2012 2:59:11 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: null at URL: jdbc:mysql://localhost:3306/HibernateTest
Oct 10, 2012 2:59:11 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {autocommit=true, password=****, user=root}
Oct 10, 2012 2:59:11 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: true
Oct 10, 2012 2:59:11 PM org.hibernate.connection.C3P0ConnectionProvider configure
WARNING: No JDBC Driver class was specified by property hibernate.connection.driver_class
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
14:59:11,443      INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@8d706a49 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@3dca4175 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|b86609, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@9b5ebf12 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|188af79, jdbcUrl -> jdbc:mysql://localhost:3306/HibernateTest, properties -> {autocommit=true, password=******, user=******} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkj87tz1bbb5y0|2a6e6c, numHelperThreads -> 3 ]
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 10, 2012 2:59:11 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: HibernateTest.item
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [created_date, modified_date, item_name, item_id, item_amount]
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Oct 10, 2012 2:59:11 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Oct 10, 2012 2:59:11 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
14:59:11,535      INFO HibernateTest:28 - before save or update

Hibernate: /*insert com.Item*/insert into ITEM (ITEM_NAME, ITEM_AMOUNT, CREATED_DATE, MODIFIED_DATE, ITEM_ID) values (?, ?, ?, ?, ?)

Oct 10, 2012 2:59:11 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing

Item instance values stores into database. 







Now i change dynamic-insert="true" into class mapping metadata and i run the following code.

public static void main(String[] args) {
LOGGER.info("starting of main method");
Session session = HibernateUtil.getSessionFactory().openSession();
Transaction txn = session.beginTransaction();
Item item = new Item();
item.setItemName("Samsung");
//item.setItemAmount(23.2);
item.setCreatedDate(new Date());
item.setModifiedDate(new Date());
LOGGER.info("before save or update");
session.saveOrUpdate(item);
txn.commit();
session.close();
HibernateUtil.shutDown();
}


See the generated comments as below.

15:19:47,316      INFO HibernateTest:19 - starting of main method
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0rc1
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: com/Item.hbm.xml
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.Item -> ITEM
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 10, 2012 3:19:47 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Maximum outer join fetch depth: 2
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: enabled
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Oct 10, 2012 3:19:47 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Oct 10, 2012 3:19:47 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 10, 2012 3:19:47 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: null at URL: jdbc:mysql://localhost:3306/HibernateTest
Oct 10, 2012 3:19:47 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=root, password=****, autocommit=true}
Oct 10, 2012 3:19:47 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: true
Oct 10, 2012 3:19:47 PM org.hibernate.connection.C3P0ConnectionProvider configure
WARNING: No JDBC Driver class was specified by property hibernate.connection.driver_class
15:19:47,566      INFO MLog:80 - MLog clients using log4j logging.
15:19:47,797      INFO C3P0Registry:204 - Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
15:19:47,852      INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@9b56470a [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@e63b9c89 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bs1yqt8qkjyqbv13nan4b|750e30, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@d5ed1f41 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkjyqbv13nan4b|693a5, jdbcUrl -> jdbc:mysql://localhost:3306/HibernateTest, properties -> {user=******, password=******, autocommit=true} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkjyqbv13nan4b|c0c9d0, numHelperThreads -> 3 ]
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch size: 15
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC batch updates for versioned data: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): enabled
Oct 10, 2012 3:19:48 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Oct 10, 2012 3:19:48 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.EhCacheProvider
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Oct 10, 2012 3:19:48 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 10, 2012 3:19:48 PM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Anuj/Jars/HibernateLib/ehcache-1.1.jar!/ehcache-failsafe.xml
Oct 10, 2012 3:19:48 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Oct 10, 2012 3:19:48 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.MySQLDialect
Oct 10, 2012 3:19:48 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: C3P0 using driver: null at URL: jdbc:mysql://localhost:3306/HibernateTest
Oct 10, 2012 3:19:48 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: Connection properties: {user=root, password=****, autocommit=true}
Oct 10, 2012 3:19:48 PM org.hibernate.connection.C3P0ConnectionProvider configure
INFO: autocommit mode: true
Oct 10, 2012 3:19:48 PM org.hibernate.connection.C3P0ConnectionProvider configure
WARNING: No JDBC Driver class was specified by property hibernate.connection.driver_class
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
15:19:48,457      INFO AbstractPoolBackedDataSource:462 - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@d184a321 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ed215ed6 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1bs1yqt8qkjyqbv13nan4b|32f90a, idleConnectionTestPeriod -> 3000, initialPoolSize -> 5, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 300, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@9caee9da [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkjyqbv13nan4b|b86609, jdbcUrl -> jdbc:mysql://localhost:3306/HibernateTest, properties -> {user=******, password=******, autocommit=true} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1bs1yqt8qkjyqbv13nan4b|1b79249, numHelperThreads -> 3 ]
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Oct 10, 2012 3:19:48 PM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: HibernateTest.item
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [created_date, modified_date, item_name, item_id, item_amount]
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [primary]
Oct 10, 2012 3:19:48 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Oct 10, 2012 3:19:48 PM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
15:19:48,526      INFO HibernateTest:28 - before save or update
Hibernate: /*insert com.Item*/insert into ITEM (ITEM_NAME, CREATED_DATE, MODIFIED_DATE, ITEM_ID) values (?, ?, ?, ?)
Oct 10, 2012 3:19:48 PM org.hibernate.impl.SessionFactoryImpl close
INFO: closing

In comments, it ignore the ITEM_AMOUNT column in the INSERT SQL statement.

check the database again and see the item record values in this case.








Dynamic-update also works in same way.