1

I have a junit test class in which I have to specify the new persistent unit name suppose say "B" with properties connecting to the DB. From this test class I am invoking a JPA REST service which in turn calls a business logic java class. In this business logic class, I have written entitymanager with the persistent xml unit suppose say "A".

Question here is how can I specify the persistent unit B in junit test class so that the business class uses persistent unit B instead of A?

agrawalsp
  • 31
  • 10
  • persistence-unit is specified in a file persistence.xml NOT in a class. Define better what you mean – Neil Stockton Feb 07 '17 at 09:00
  • We can specify a new persistence unit in class like this: http://stackoverflow.com/a/18733128 I have checked this but did not work for me. Please understand what is being asked in question. – agrawalsp Feb 08 '17 at 07:08
  • That is not a "new persistence unit". That is the SAME persistence unit with some extra properties that override those specified in the persistence.xml. – Neil Stockton Feb 08 '17 at 07:14

1 Answers1

0

You can override your

src/main/resources/META-INF/persistence.xml

with

src\test\resources\META-INF\persistence.xml

jklee
  • 2,198
  • 2
  • 15
  • 25
  • I have seen this but the problem is that my junit class takes src/main/resources/META-INF/persistence.xml instead of src\test\resources\META-INF\persistence.xml, I think because I need to specify this path somewhere. – agrawalsp Feb 08 '17 at 07:15
  • Which framework do you use for JPA Unit Tests? Only junit? – jklee Feb 09 '17 at 07:35