0

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!

L.Butz
  • 2,466
  • 25
  • 44
  • What do you mean by 'run my class' ? How do you run it ? The problem is probably that /src/test/java is not on your classpath. – Simeon Jun 10 '11 at 13:33
  • 1
    See http://stackoverflow.com/questions/4885836/no-autodetection-of-jpa-entities-in-maven-verify – axtavt Jun 10 '11 at 14:02

2 Answers2

3

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.

Robin
  • 24,062
  • 5
  • 49
  • 58
  • Ok, now I run the class through a JUnit test which is started by maven. But i still have java.lang.IllegalArgumentException: Unknown entity: ch.itartis.relman.entities.code.ReferenceCode problem. I think there might be a problem, because the "ReferenceCode"-Class is located in an other project. How can I make sure that my hibernate finds the class from the other project? – L.Butz Jun 14 '11 at 14:06
0

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

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588