开发者

Example for creating a configuration

i am facing some difficulties in creating a session. Can anyone pr开发者_JS百科ovide 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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜