Hi.
I have an issue with addPackage(), which i don't understand.
From what i can read it is possible to use this metod alone and add en entire package of entitys, but i can get it to work.
If i use addAnnotationdClass() there is not a problem, but den i have to add all the classes by themself.
Currently my code looks like this:
Code:
File configFile = new File(hibernateConfigurationFile);
SessionFactory sessionFactory = null;
if(packageName != null) {
System.out.println("Package name: " + packageName);
System.out.println("Hibernate configuration file: " + hibernateConfigurationFile);
sessionFactory = new AnnotationConfiguration().addPackage(packageName).configure(configFile)
.buildSessionFactory();
} else {
sessionFactory = new AnnotationConfiguration().configure(configFile).buildSessionFactory();
}
System output is this:
Package name: it.courage.api.nas.db
Hibernate configuration file: etc/hibernate-no-datasource.cfg.xml
Error:
Exception in thread "main" org.hibernate.MappingException: Unknown entity: it.courage.api.nas.db.Order
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:548)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:68)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:301)
at $Proxy0.get(Unknown Source)
at it.courage.api.nas.surveillance.SurveillanceApi.getOrder(SurveillanceApi.java:54)
at it.courage.api.nas.surveillance.SurveillanceApiTest.main(SurveillanceApiTest.java:19)
addAnnotatedClass() is working fine:
sessionFactory = new AnnotationConfiguration().addAnnotatedClass(Order.class).configure(configFile).buildSessionFactory();
Can someone tell me what i'm doing wrong???
/Stiwi.