0

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

3
  • A stack trace would be helpful, this question gives very little info. Commented 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.invoke Commented Jun 5, 2010 at 4:32
  • you can edit your question to add this stack trace and delete the comment... it would look better. Commented Jun 5, 2010 at 6:00

4 Answers 4

1

Check if you have @Entity on your Equipment class.

This annotation (@Entity) is marking a class as Hibernate (JPA) entity.

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

Comments

0

For me it was a refactoring issue. I refactored my entity package but forgot to change the component scan path to the new package name. After that was realized and changed, it worked!

Comments

0

Try adding following Annotation on top of your Entity Class Equipment. Change the table name accordingly if required :

@Entity
@Table(name = "Equipment")
@XmlRootElement

Comments

-1
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

it is better to add a small description about your code

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.