-->
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.  [ 2 posts ] 
Author Message
 Post subject: [ANNOTATIONS] MappingException: Unknown entity
PostPosted: Sun Aug 20, 2006 9:14 am 
Newbie

Joined: Thu Mar 09, 2006 11:52 am
Posts: 13
I'm trying to get annotations to work but when I try to load an annotated class object, I get the exception mentioned below. I guess that my annotations are somewhat wrong but I don't know where the error possibly might be. Hope someone can help, thanks in advance.

Hibernate version: 3.1.3

Annotated class:
1.) User
Code:
@Entity
@Table(name = "pnp_user")
public class User implements Serializable
{
   protected Integer userId;
   protected String username;
   protected String forename;
   protected String surname;
   protected EMailAddress email;
   protected String password;
   protected Date signUpDate;
   protected Boolean accountActive;

   public User(Integer userId, String username, String forename,
         String surname, String password, Date signUpDate,
         Boolean accountActive) {
      this.userId = userId;
      this.username = username;
      this.forename = forename;
      this.surname = surname;
      this.password = password;
      this.signUpDate = signUpDate;
      this.accountActive = accountActive;
   }

   public User() {
   }

   @Embedded
   @AttributeOverrides(@AttributeOverride(name = "address", column = @Column(name = "EMAIL_ADDRESS")))
   public EMailAddress getEmail() {
      return email;
   }

   public void setEmail(EMailAddress email) {
      this.email = email;
   }

   @Column(name = "FORENAME", nullable = false, length = 48)
   public String getForename() {
      return forename;
   }

   public void setForename(String forename) {
      this.forename = forename;
   }

   @Column(name = "PASSWORD", nullable = false, length = 32)
   public String getPassword() {
      return password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   @Column(name = "SURNAME", nullable = false, length = 48)
   public String getSurname() {
      return surname;
   }

   public void setSurname(String surname) {
      this.surname = surname;
   }

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   public Integer getUserId() {
      return userId;
   }

   public void setUserId(Integer userId) {
      this.userId = userId;
   }

   @Column(updatable = false, name = "USERNAME", nullable = false, length = 32, unique = true)
   public String getUsername() {
      return username;
   }

   public void setUsername(String username) {
      this.username = username;
   }

   @Temporal(TemporalType.DATE)
   @Column(nullable = false, name = "SIGNUP_DATE")
   public Date getSignUpDate() {
      return signUpDate;
   }

   public void setSignUpDate(Date signUpDate) {
      this.signUpDate = signUpDate;
   }

   @Column(name = "ACCOUNT_ACTIVE", nullable = false)
   public Boolean getAccountActive() {
      return accountActive;
   }

   public void setAccountActive(Boolean accountActive) {
      this.accountActive = accountActive;
   }
}


2.) EMailAddress
Code:
@Embeddable
public class EMailAddress implements Serializable
{
   protected String address;

   public EMailAddress(String address) {
      this.address = address;
   }

   public EMailAddress() {
   }

   public String getAddress() {
      return address;
   }

   public void setAddress(String address) {
      this.address = address;
   }
}


Full stack trace of any exception that occurs:
org.hibernate.MappingException: Unknown entity: com.byteholder.pnp.domain.User
at org.hibernate.impl.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:514)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:66)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:781)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:774)
at com.byteholder.pnp.GenericDAO.findById(GenericDAO.java:70)
... 22 more

Name and version of the database you are using: MySQL 4.1.21

hibernate.cfg.xml:
Code:
<hibernate-configuration>
   <session-factory>
      <property name="connection.datasource">
         java:comp/env/jdbc/pnponline
      </property>
      <property name="dialect">
         org.hibernate.dialect.MySQLInnoDBDialect
      </property>
      <property name="show_sql">true</property>
      <mapping class="com.byteholder.pnp.domain.User" />
      <mapping class="com.byteholder.pnp.domain.EMailAddress" />
   </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 20, 2006 10:27 am 
Newbie

Joined: Thu Mar 09, 2006 11:52 am
Posts: 13
SOLVED: I had an import for org.hibernate.annotations.Entity in my class instead of javax.persistence.Entity.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.