Question

I have to test some things on a project which has been developed by others, but is new to me. They are using Hibernate as a JPA implementation.

I got a virtual machine in which everything is set up, but when I want to start any Testclient (small console programs, no Unittesting). I always get the same error.

Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
    at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
    ...    
Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
    at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
    at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
    at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
    ... 7 more

The project structure looks like this. Strangely enough I already had this thing running (before my summerholdays.

|-- bin
|-- lib
|-- rsc
|   |-- META-INF
|   |   `-- persistence.xml
|-- src
|   |-- org 
|   |    | ... all sourcecode below 
`-- target

I tried to narrow down the problem, therefore I deleted the whole META-INF folder. Still the same error. That was not what I expected and led me to believe that persistence.xml is not found at all. I don't know why they put META-INF in the rsc folder (as I mentioned, it's not my project) but when I put it in the root folder or in the src folder the error remains.

How can I make sure that persistence.xml has been found? Is there any documentation where META-INF should be placed. (And why is this errormessage so misleading?)

Was it helpful?

Solution

It depends on your build process where the compiled files/jar will end up, when starting your test app. I'm pretty sure, you won't start from src-folder. You'll get some build or test folder to run your app from. Then the folder structure should typically be like this:

|- build
   |- classes
      |- org (packages)
         |- ...
      |- META-INF
         |- persistence.xml
         |- ... (other config files)

You could also check this link.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top