L.Butz
L.Butz

Reputation: 2616

JPA Hibernate Maven testing --> unknown class

I'm trying to run a simple dataImport class which is using JPA and Hibernate.

If I run my class, i always have the following error:

Exception in thread "main" java.lang.IllegalArgumentException: Unknown entity: ch.itartis.relman.entities.code.ReferenceCode
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:675)
    at ch.itartis.relman.service.test.dataimport.DataImport.doSave(DataImport.java:111)
    at ch.itartis.relman.service.test.dataimport.DataImport.main(DataImport.java:43)

My Class is located in the src/test/java/ folder, I have a service-config.xml in src/test/resources/ and I also have a persistence.xml in src/test/resources/META-INF/.

If I run the class in in the src/main/java/... folder, it works. But if I want to have the class in src/test/java/, it doesn't.

What am I doing wrong?

Thanks a lot!

Upvotes: 0

Views: 854

Answers (2)

Sean Patrick Floyd
Sean Patrick Floyd

Reputation: 299178

To complete Robin's answer: if you are running the class using exec:java set classpathScope to test and everything will be fine.

Upvotes: 0

Robin
Robin

Reputation: 24282

You are running the code from your own main method, which I am guessing means it isn't being run by maven. The code in test is not included as part of the artifact generated by maven, it is only included during mavens test phase for running unit tests.

If you are using maven, why not simply create JUnit tests that maven will run as part of the build process instead of rolling your own.

Upvotes: 3

Related Questions