Skip to content
Advertisement

org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [/HibernateTest/src/hibernate.cfg.xml]

I am trying to connect to Postgresql9.1 in ubuntu with pgadmin3. My Pgadmin3 GUI tool does not give any option to create tables by right clicking the database, but it is available in some videos I saw. Therefore, I used terminal to create the database and it showed up in pgadmin3.

my file structure

My Userdetails file

JavaScript

My HibernateCaller file

JavaScript

Hibernate.cfg.xml

JavaScript

I am getting following error

JavaScript

After making few changes (could not use session.close() in finally block I think that should not cause this error)

JavaScript

Advertisement

Answer

If you have your hibernate.cfg.xml in the root of the source folder, just do

JavaScript

If it is in the package, for an example in the org.nitish.caller, specify path by this way

JavaScript

You need to close the session (in the finally block). Don’t forget to add rollback code.

Please, add @Table annotation to the UserDetails.

Update

The reason of the error that Hibernate can’t find org.postgresql.Driver class. It resides in postgresql jar. You have that jar at your image, but may be you don’t add it to the classpath. Refer How to Add JARs to Project Build Paths in Eclipse (Java).

To close a session in the finally block you need to have session variable outside the try block.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement