• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate.cfg.xml and hibernate.properties

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Vivek Raju
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Vivek Raju
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ramesh

Thank you very much for replying.

I problem has been resolved.

THanks and Best wishes

With Regards
S.R.K.Vivek Raju.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any chance on telling what you did to resolve?
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You've gotta fight it! Don't give in! Read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic