Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to build entity manager factory  RSS feed

 
Brian Jones Jr.
Ranch Hand
Posts: 39
2
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Rob Spoor
Sheriff
Posts: 20934
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • 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: 39
2
Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!