views:

70

answers:

2

hi, i am facing some difficulties in creating a session. Can anyone provide me an example or link where a configuration is created by using an external file by giving url,like

Configuration config = new Configuration.configure(url);

the config file is in another hibernate project. is there anything that i should add to classpath or store the config file. My app is just getting hanged there at that statement.Help

+1  A: 

Applications are not referred "projects" in their deployment context. And they are deployed on application servers. If the configuration file resides anywhere in the application server, or (less-preferably) anywhere on the hard drive, and you know its location (for example via a configuration option), then you can construct a File object referencing it. And then you can do (a short example):

new Configuration().configure(configFile).buildSessionFactory();

Hanging might be caused by not being able to connect (using JDBC) to the underlying database. Make sure the database server is accessible and running.

Bozho
thanks for reply but its not working still
Steven
HOW it isn't working? exceptions? nulls?
Bozho
nothing it just gets hanged
Steven
@Steven see my update
Bozho
A: 

As explained in the chapter 3.7. XML configuration file of the Hibernate documentation:

The XML configuration file is by default expected to be in the root of your CLASSPATH.

(...)

With the XML configuration, starting Hibernate is then as simple as:

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

You can select a different XML configuration file using:

SessionFactory sf = new Configuration()
    .configure("catdb.cfg.xml")
    .buildSessionFactory();

So if this file is included in another JAR, just add this JAR to your class path and pass the appropriate location (or nothing if the file is at the root of the class path) when calling the configure() method.

Pascal Thivent