-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: JPA: java.lang.IllegalArgumentException: Unknown entity
PostPosted: Mon Jan 18, 2010 1:50 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
Hi,

I am trying to run examples from book 'Pro Apache Struts Web 2.0 Projects'.

the persistence.xml file is as below:

Code:
persistence>
   <persistence-unit name="s2app">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
         <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource" />
         <property name="hibernate.connection.url" value="jdbc:mysql://localhost/s2app" />
         <property name="hibernate.connection.username" value="root" />
         <property name="hibernate.connection.password" value="xyzabd" />
         <property name="hibernate.hbm2ddl.auto" value="update"/>
         <property name="hibernate.archive.autodetection" value="class"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
      </properties>
   </persistence-unit>
</persistence>


My test case is this:
Code:
public void testCreateFind() throws Exception{
      User u = new User();
      u.setEmail("test@test.com");
      u.setFirstName("firstName");
      u.setLastName("lastName");
      u.setPassword("password");
      entityMgr.persist(u);
      entityMgr.flush();
      
      User test = entityMgr.find(User.class, u.getEmail());
      assertNotNull(test);
      assertEquals(u.getEmail(), test.getEmail());
      assertEquals(u.getFirstName(), test.getFirstName());
      assertEquals(u.getLastName(), test.getLastName());
      assertEquals(u.getPassword(), test.getPassword());
   }


When I run
Code:
mvn test
, I get the IllegalArgumentException: Unknown entity error

Here is the trace:
Code:
java.lang.IllegalArgumentException: Unknown entity: com.personal.domain.User
   at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:215)
   at com.personal.hibernate.UserTestCase.testCreateFind(UserTestCase.java:13)


What am I missing and how do I make it work the correct way? Please help me.


Top
 Profile  
 
 Post subject: Re: JPA: java.lang.IllegalArgumentException: Unknown entity
PostPosted: Tue Jan 19, 2010 3:53 pm 
Beginner
Beginner

Joined: Tue Aug 01, 2006 4:57 am
Posts: 25
Please help...


Top
 Profile  
 
 Post subject: Re: JPA: java.lang.IllegalArgumentException: Unknown entity
PostPosted: Wed Jan 20, 2010 6:26 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
I don't know the examples from book 'Pro Apache Struts Web 2.0 Projects'.
but apparently you problem is that you don't have com.personal.domain.User in classpath.
So please check your runtime classpath,
if it don't works, you alternatively can pack the compiled persistent classes into a jar file and specify it explicitely in your persistence.xml file as follows:

Code:
<persistence-unit name="s2app">
   <jar-file>../mypath/persistency.jar</jar-file>
   <properties>
     <!-- Scan for annotated classes and Hibernate mapping XML files -->
     <property name="hibernate.archive.autodetection" value="class, hbm"/>
     ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.