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!

2
  • 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. Commented Jun 10, 2011 at 13:33
  • 1
    See stackoverflow.com/questions/4885836/… Commented Jun 10, 2011 at 14:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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?
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.