Skip to content

Hibernate

July 26, 2011

So I first build the project using maven. Create the facede, and dao class and entity. Then created hibernate config xml file which has SessionFactory belonging to spring using DataSource BasicConnectionPooling. The properties file has to be loaded using context:placeHolder properties.

Define the context annotation scanner in the spring file. Define the hibernate template using the session factory using ref tag and not value tag. The JUnit test class has @Test annotated for test cases and the @RunWith (SpringRunner4JUnit.class) and @ContextConfiguration(“/abc.xml”)

That helps in running the test cases/ the autoDDL in hibernate if set to create recreates the schema everytime – instead to validate if you wish to keep data as it is in db.Otherwise data keeps getting removed.
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.

Logging can be increased by setting:

log4j.logger.org.hibernate.SQL=debug
log4j.logger.org.hibernate.type=trace

Advertisements
No comments yet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: