I have two jar files with hibernate classes mapped. One jar file is perfectly working and for the next jar file it is not mapped. I get Unknown Entity exception. Persistence.xml is good but i dont know why this is happening. Any guess what mite be the issue???
-
A stack trace would be helpful, this question gives very little info.ashurexm– ashurexm2010-06-05 04:05:54 +00:00Commented Jun 5, 2010 at 4:05
-
sorry i missed it, thanks manyxcxi java.lang.IllegalArgumentException: Unknown entity: com.test.Equipment at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:223) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invokeRaj– Raj2010-06-05 04:32:20 +00:00Commented Jun 5, 2010 at 4:32
-
you can edit your question to add this stack trace and delete the comment... it would look better.Yuval– Yuval2010-06-05 06:00:32 +00:00Commented Jun 5, 2010 at 6:00
Add a comment
|
4 Answers
Check if you have @Entity on your Equipment class.
This annotation (@Entity) is marking a class as Hibernate (JPA) entity.
Comments
package Test;
import java.util.EnumSet;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.tool.schema.TargetType;
import org.junit.Test;
import Entity.Users;
public class TestMain {
public static void main(String[] arg){
try {
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
SessionFactory sessionFactory = new MetadataSources( serviceRegistry ).buildMetadata().buildSessionFactory();
Session session=sessionFactory.openSession();
Transaction transaction=session.beginTransaction();
Users users=new Users();
users.setId(2);
session.save(users);
transaction.commit();
session.close();
sessionFactory.close();
}catch(Throwable th){
System.err.println("Init SessionFactory creation failed" );
System.err.println(th);
throw new ExceptionInInitializerError(th);
}finally {
}
}
}
1 Comment
droidev
it is better to add a small description about your code