Simple error trying to use Hibernate + JPA

Asked

Viewed 63 times

1

Good morning, I’m starting to create a simple register with Hibernate.

I have the following classes

Java link. http://pastebin.com/vgDn9U3Y

Hibernate.cfg.xml http://pastebin.com/06kA87Lv

Form action http://pastebin.com/2iPB1HU1

And when performing the record it returns the following:

INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
Exception in thread "AWT-EventQueue-0" org.hibernate.HibernateException
/hibernate.cfg.xml not found
at
org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:2093)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2074)
at org.hibernate.cfg.Configuration.configure(Configuration.java:2054)

Could someone please help?

  • The error seems to occur because it does not find the xml file. Make sure it is in the Resources folder?

  • Gustavo, I’m a little young and I don’t know if I’m answering you right. Since it’s just a test registration I didn’t work with mvc and the directories are organized as follows: ... Controller 2.0 src Linx Inside you have all the files including xml

  • No problem, man, everybody’s got to learn sometime, that’s the law. In the case of configuration files, there are specific places to be, such as pom.xml, or web.xml, in web projects. Hibernate.cfg.xml must be in the src/main/Resources folder, otherwise it will be read and encoded for classpath. Try creating this folder structure there.

  • 1

    Gustavo, thank you very much, I was mecher in the properties of the project and added the folder of the package called Linx, after that solved and worked normally. It seems that he was looking for the files in src but the project was in a package named Linx. Thank you very much!

  • 1

    @Viniciusleonardo Nowadays we practically only use the file persistence.xml. Then gives a study about it.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.