This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Unable to build entity manager factory

 
Ranch Hand
Posts: 39
2
Mac Java 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.
 
Sheriff
Posts: 21974
106
Eclipse IDE Spring VI Editor Chrome Java Ubuntu 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
Mac Java 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.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic