YOUR FEEDBACK
wrote: Trackback Added: Who is Technology’s Highest Paid CEO?; Who is Technology&...


2008 East
DIAMOND SPONSOR:
Data Direct
Frontiers in Data Access: The Coming Wave in Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
Intel
Virtualization – Path to Predictive Enterprise
Green Hills
IT Security in a Hostile World
JBoss / freedom oss
Practical SOA Approach
GOLD SPONSORS:
Software AG
The Art & Science of SOA: How Governance Enables Adoption
PlateSpin
Effective Planning for Virtual Infrastructure Growth
Fujitsu
Automated Business Process Discovery & Virtualization Service
Ceedo
Workspace Virtualization
Click For 2007 West
Event Webcasts

2008 East
PLATINUM SPONSORS:
Appcelerator
Think Fast: Accelerate AJAX Development with Appcelerator
GOLD SPONSORS:
DreamFace Interactive
The Ultimate Framework for Creating Personalized Web 2.0 Mashups
ICEsoft
AJAX and Social Computing for the Enterprise
Kaazing
Enterprise Comet: Real–Time, Real–Time, or Real–Time Web 2.0?
Nexaweb
Now Playing: Desktop Apps in the Browser!
Sun
jMaki as an AJAX Mashup Framework
POWER PANELS:
The Business Value
of RIAs
What Lies Beyond AJAX?
KEYNOTES:
Douglas Crockford
Can We Fix the Web?
Anthony Franco
2008: The Year of the RIA
Click For 2007 Event Webcasts
SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


Uday Kumar's Java Blog – Getting Hibernate 3.x Up and Running with Tomcat
A Few Minor Changes to the Hibernate Tutorial at Hibernate.org

Hibernate Tutorial - Small Corrections

I am back again after a hiatus. I was busy dealing with some work issues and some health issues.

I was reviewing the Hibernate tutorial at http://www.hibernate.org/hib_docs/v3/reference/en/html/quickstart.html and am publishing a few minor changes which might help the new initiate to get up and running quickly. This link refers to getting Hibernate 3.x up and running with Tomcat 4.1. I ran it with Tomcat 5.5.2.

The tutorial uses PostgreSQL 7.4 and I used MySQL 4.0.21. So the driver file to copy is mysql-connector-java-3.0.15-ga-bin.jar. This can be ideally copied to the TOMCAT_HOME \shared\lib directory ( where TOMCAT_HOME is where you installed Tomcat ). The reason for placing it in the shared\lib as opposed to the common\lib is because, as the Tomcat documentation states: the files placed in common are visible to Tomcat internal code and all webapps whereas those in shared\lib are visible to all web apps only. In this case the MySql drivers are not needed for the internal code.

The following libraries were copied to the context class path which in the case of the tutorial would typically be:

TOMCAT_HOME\webapps\quickstart\WEB_INF\lib  (the context created in my case was called quickstart)

ant-antlr.jar

asm.jar, cglib-2.1.2.jar, commons-collections-2.1.1.jar,commons-dbcp-1.2.1.jar, commons-logging-1.0.4.jar,

commons-pool-1.2.jar, dom4j-1.6.1.jar, ehcache-1.1.jar,  hibernate3.jar, log4j-1.2.11.jar

The next section in the tutorial refers to the creation of a Context. The only change here is based on style: the tutorial recommends adding this Context entry to TOMCAT-HOME\conf\server.xml. However for Tomcat 5.x the documentation recommends that these type of context entries shouldnt be placed directly into the server.xml but instead should be in a separate set of directories that are either web application specific as in META_INF\context.xml or in TOMCAT_HOME\conf sub-directories.

I chose to place the context definitions in TOMCAT_HOME\conf\Catalina\HOST_NAME in a file called quickstart.xml.

The next change is with reference to the cfg.xml file. Hibernate uses a hibernate.properties file as the default for loading config information. Thus if you were to code as follows for getting a SessionFactory instance:

SessionFactory sessionFactory = new Configuration().buildSessionFactory();

then the hibernate.properties file in the context classpath will be used for loading the configuration information.

If you want instead to use the hibernate.cfg.xml file for loading the configuration information, then the following method call should be done:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

The configure method of the Configuration class is hard coded to use the hibernate.cfg.xml file.

The tutorial uses the cfg.xml file, but I ran into errors because of improper configuration parameters: so I switched to the properties file instead. I just used the default values in the properties file that came with the distribution.  I am sure that I didnt tweak the cfg.xml file properly as I just used the entries given in the tutorial directly but I didnt have the patience to investigate so switched to the less expressive properties file instead.

The mapping file is an important entity here as it is the artifact which allows us to map objects onto the rdbms tables. When making the above switch to the hibernate.properties file for the configuration information, however, there is no place to specify the mapping file name.  So another minor change that is required while building the configuration is as follows:

Configuration cfg = new Configuration().addClass(Cat.class)

where you substitute your persistent class name instead of Cat.class.  The addClass method in Configuration.java will then do a getName call on the Class passed in as input argument and suffix it with hbm.xml after replacing '.' with a '/' and try to get the appropriate mapping file from the same package location as the persistent class. So you would of course place the mapping file in the same package directory structure as your persistent class.

Other than that there are no major changes in the tutorial and things will go smoothly.

posted Sunday, 13 November 2005

About Uday Kumar
Uday Kumar is the vice president of Technology for Covansys Corporation, a U.S.-based corporation that specializes in providing custom application builds and integration services to its customers. He consults as a chief architect and guides development teams building enterprise architecture solutions using J2EE and .NET technologies and also runs the E-Business practice for Covansys’ Western region. His professional interests include operating systems research and virtual machine implementations. Uday is currently researching the comparative merits of virtual machines such as Parrot, Microsoft’s CLR, and the JVM. He builds Perl applications as a hobby.

LATEST JAVA STORIES & POSTS
An applet, a Java program that runs in a browser, often has to access the client resources. However, the security manager prevents an applet from accessing client resources. To access client resources, the applet has to have the proper permission. With this permission the applet ...
Three-letter acronyms (TLAs) are hardly new in Information Technology: EAI, ESB, SOA, BPM, BAM, ETL, MDM; the list goes on and on. This article is about yet another three-letter acronym, EDA, which stands for Event-Driven Architecture. EDA is not a brand new technology, but rathe...
Furthering its dedication to providing Java developers productivity with choice, Oracle announced the Oracle Enterprise Pack for Eclipse, a new component of Oracle Fusion Middleware. This release marks the first free Eclipse 3.4 environment to support Oracle WebLogic Server 10g R...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted...
Red Hat CTO Brian Stevens, Citrix CTO Simon Crosby, Egenera CTO Pete Manca, Allen Stewart, Group Manager, Windows Virtualization at Microsoft, and Brian Duckering, Sr. Director of Products and Alliances at Symantec were the top industry executives who joined Jeremy Geelan in the ...
Government intervention and direction has long been critical to the development of the computer industry. The Internet, after all, was derived from the ARPANET, developed in the early 1970s from a U.S. government-sponsored research project by the Advanced Research Projects Agency...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON FEATURED WHITEPAPERS

SPONSORED BY INFRAGISTICS
There are many forces that influence technological evolution. After a decade of building enterprise ...
2008 is going to be an important year for Rich Internet Applications. Most organizations are deliver...
The OpenAjax Alliance is developing an Ajax industry wishlist for future browsers, using a dedicated...
In every field of design one of the first things students do is learn from the work of others. They ...
Infragistics announced the availability of two Community Technology Preview (CTP) User Interface (UI...
The YUI development team has released version 2.5.2; you can download the new release from SourceFor...
ADS BY GOOGLE
BREAKING JAVA NEWS

SpringSource, a leading provider of infrastructure software and the company behind ...