• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Unable to build entity manager factory

 
Ranch Hand
Posts: 42
2
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My stack:
JBoss Wildfly 10 server
Ubuntu 16.04
Java 8
Postgres 9.5.6
Hibernate 5

I am having problems trying to get my JUnit test to work. The unit tests were created by JBoss and they are used to test if Hibernate is working properly. I got their hibernate5 quickstart tutorial to work, and it was using an H2 database. Now I'm trying to using some of their code (datasource.xml and persistence.xml) for my personal project, and I'm using a Postgres database with Hibernate JPA. I got the following exception when I tried to run the unit test:



Here's the unit test method that corresponds with the exception. The exception is thrown in the try block:



I tried to configure my standalone.xml using this StackOverflow post webpage. Here's what my standalone.xml datasource looks like:




Here's what my module.xml looks like. It's in directory wildfly-10.1.0.final/modules/org/postgres/main:



Here's what my datasource in the WEB-INF folder looks like:




Here's what my persistence.xml looks like from the META-INF folder:



Does anyone know what I need to do in order to fix this exception? Thanks.
 
Sheriff
Posts: 22841
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ignore any JBoss/WildFly specific configuration. You're trying to run a unit test, and that has (more or less) the same rules as a standalone JSE application.

Last time I had to unit test my database code, I simply used a second persistence.xml (in src/test/resources/META-INF) with its own persistence unit name, and used that. This one was mostly identical, except:
1) the transaction-type was RESOURCE_LOCAL instead of JTA.
2) there was no data source, but properties for connecting instead (you already have those).
3) classes were included instead of relying on automatic discovery.
 
Brian Jones Jr.
Ranch Hand
Posts: 42
2
Mac Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:Ignore any JBoss/WildFly specific configuration. You're trying to run a unit test, and that has (more or less) the same rules as a standalone JSE application.

Last time I had to unit test my database code, I simply used a second persistence.xml (in src/test/resources/META-INF) with its own persistence unit name, and used that. This one was mostly identical, except:
1) the transaction-type was RESOURCE_LOCAL instead of JTA.
2) there was no data source, but properties for connecting instead (you already have those).
3) classes were included instead of relying on automatic discovery.



Thanks! I'll give this a try.
reply
    Bookmark Topic Watch Topic
  • New Topic