• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing hibernate.cfg.xml from web project through JAR file

 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

I have a JAR file, created by me, that contains a HibernateUtil class, reponsable to open sessions and transactions using Hibernate. I added this JAR file into another project (J2EE), to use HibernateUtil.

I need to use hibernate.cfg.xml file from J2EE project, but i don't have idea how to use this file into HibernateUtil class from JAR.

Follow the code that i use in jar file to load hibernate.cfg.xml.



HibernateUtil.jar
- HibernateUtil.class
- GenericDAO.class
- GenericDAOImpl.class

J2EE Project
- HibernateUtil.jar
- hibernate.cfg.xml
- CustomerDAO.java (extends GenericDAOImpl)


How i can make this?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the jar file is loaded into the classpath, I don't think you need to do anything special as opposed to having un-jarred class files.

But I'm far from a Hibernate guru, so I'll let the more Hibernate-savvy weight in with any special considerations Hibernate might have.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nope, no special considerations for Hibernate. Like Bear says if its on your classpath you can access it.

You may want to change your code to report exceptions though...
 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the Java see the file hibernate.cfg.xml (File.exists() and File.canRead() returns true), but the message "fine!" after sessionFactory doesn't appears, doesn't catch an exception and the connection with database not works. I don't have idea what is wrong.



Follow my hibernate.cfg.xml:



Thanks for help.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First is your database connection data work without hibernate (i.e: are you able to use same data within a simple Java program which connects to the database)?
...but the message "fine!" after sessionFactory doesn't appears, doesn't catch an exception and the connection with database not works.

Why do you say so, any out put when running the code?
 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is that a required JAR (antlr.jar) not is in classpath.

Sorry, but my class doesn't was generating an exception.

Thanks for help!
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... but my class doesn't was generating an exception.

How did you find out the error then, anyway hope it's solved now?
 
Tiago Hillebrandt
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a new project from scratch, so the Exception was generated. But in the project that i was working doesn't works.
 
Vijitha Kumara
Bartender
Pie
Posts: 3930
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tiago Hillebrandt wrote:... But in the project that i was working doesn't works.

Aren't you able to trace it? There should be some way to see what's wrong (as previously mentioned by logs etc...)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic