File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate.cfg.xml and hibernate.properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate.cfg.xml and hibernate.properties" Watch "Hibernate.cfg.xml and hibernate.properties" New topic
Author

Hibernate.cfg.xml and hibernate.properties

S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
Hi all

I have written a simple example for storing data into the Hibernate Example. I have written the client code as follows in the servlet:

try{
System.out.println("**Hello World 1**");
config = new Configuration().configure();

config.addClass(UserDataBO.class);

sessionFactory = config.buildSessionFactory();

System.out.println("**Hello World 2**");
session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();
System.out.println("**Creating Cat**");

session.save(userData);

session.flush();

tx.commit();

System.out.println("**Committing**");

session.close();

}

I have hibernate.properties in the WEB-INF/classes directory, I have placed hibernate3.jar and other jars appearing in lib directory of hibernate installation in WEB-INF/lib directory.

I get the following message on my Jboss-4.0.0 console:-

11:43:53,984 INFO [STDOUT] ************Hello World 1************
11:43:53,984 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
11:43:53,984 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
11:43:54,000 WARN [Configuration] /hibernate.cfg.xml not found
11:43:54,000 INFO [STDOUT] Hibernate Exception :/hibernate.cfg.xml not found

Is it neccessary to have a hibernate.cfg.xml file even when i have a hibernate.properties file in the WEB-INF classes, the control is not entering the config = new Configuration().configure(); in the try block.

Please advice

Thanks in advance.

With Regards
S.R.K.Vivek Raju.
S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
Hi all

I above problem was resolved, that eas coming because of the .configure() after the new configuration();

I have a new problem,
I have the following code

try{
System.out.println("************Hello World 1************");
config = new Configuration();
System.out.println("************Hello World 2************");
config.addClass(UserDataBO.class);
System.out.println("************Hello World 3************");
sessionFactory = config.buildSessionFactory();

System.out.println("************Hello World 4******************");
session = sessionFactory.openSession();

Transaction tx = session.beginTransaction();
System.out.println("************Creating Cat***************");

session.save(userData);

session.flush();

tx.commit();

System.out.println("**************Committing**************");

session.close();

}

When i run the code it gives the following on the jboss console:-

14:00:57,890 INFO [STDOUT] ************Hello World 1************
14:00:57,890 INFO [STDOUT] ************Hello World 2************
14:00:57,890 INFO [Configuration] Mapping resource: com/businessobjects/UserDataBO.hbm
.xml
14:00:57,906 INFO [HbmBinder] Mapping class: com.businessobjects.UserDataBO -> user
14:00:57,906 INFO [STDOUT] ************Hello World 3************
14:00:57,906 INFO [Configuration] processing extends queue
14:00:57,921 INFO [Configuration] processing collection mappings
14:00:57,921 INFO [Configuration] processing association property references
14:00:57,921 INFO [Configuration] processing foreign key constraints
14:00:57,921 INFO [STDOUT] Hibernate Exception :The dialect was not set. Set the property hibernate.dialect.

I have already set my hibernate in my hibernate.properties file.

What should i do , please advice

Thanks in advance

With Regards
S.R.K.Vivek Raju.
Ramesh Donnipadu
Ranch Hand

Joined: Sep 16, 2000
Posts: 100
Raju:

What is the database you are using and what did you enter in the hibernate.properties? Can you post the contents of your hibernate.properties?

Thanks,
Ramesh
S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
Hi Ramesh

Thank you very much for replying.

I problem has been resolved.

THanks and Best wishes

With Regards
S.R.K.Vivek Raju.
j whiting
Greenhorn

Joined: Nov 19, 2004
Posts: 11
Any chance on telling what you did to resolve?
Sujatha Kumar
Ranch Hand

Joined: Jan 05, 2004
Posts: 134

Is it neccessary to have a hibernate.cfg.xml file even when i have a hibernate.properties file in the WEB-INF classes, the control is not entering the config = new Configuration().configure(); in the try block


You can have both hibernate.properties and hibernate.cfg.xml in your classpath. The xml configuration overrides the properties file.

It is preferable to have hibernate.properties along with your xml file
because properties file comes with a lot of default settings.

Even hibernate documentation recommeds to keep both types of file
in your class path.


SCJP,SCWCD,SCBCD,SCEA Part I
S Majumder
Ranch Hand

Joined: Jun 03, 2009
Posts: 244
Hi Sujatha Kumar ,

It is preferable to have hibernate.properties along with your xml file
because properties file comes with a lot of default settings.


Can you tell , what is the default settings all about.

regards,
Satya
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate.cfg.xml and hibernate.properties
 
Similar Threads
Getting exception of org.dom4j.DocumentException : feature read only while deploying war file in tom
Hibernate Exception [Unknown entity com. businessobjects. UserDataBO]
Error reading resource: hbm.xml file
configuration hibernate.cfg.xml in Europa
Hibernate does not save Object / Record