-->
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: Problem with JPA inheritance
PostPosted: Mon Oct 13, 2008 8:09 am 
Regular
Regular

Joined: Sun Sep 25, 2005 11:35 pm
Posts: 57
I have a very simple object hierarchy in my app which uses JPA for inheritence:

Code:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public abstract class Party {
    private Long id;

    @Id @GeneratedValue
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
}


Code:
@Entity
public class Person extends Party {
    private String firstName;
    private String lastName;
   
    public Person() {
    }
   
    public Person(String firstName, String lastName) {
        this.firstName = firstName;
        this.lastName = lastName;
    }

    @NotNull
    @Length(min = 3, max = 40)
    @Pattern(regex="[a-zA-Z]+", message="First name must only contain letters")
    public String getFirstName() {
        return firstName;
    }
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @NotNull
    @Length(min = 3, max = 40)
    @Pattern(regex="[a-zA-Z]+", message="Last name must only contain letters")
    public String getLastName() {
        return lastName;
    }
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }
}


I am able to save and retrieve the Person object in my tests. However, when JBoss tries to load the persitence unit, it gives me the following exception:

Code:
07:48:46.828 WARN  [org.jboss.system.ServiceController] Problem starting service persistence.units:ear=myapp-1.0-SNAPSHOT.ear,unitName=myappDatabase
org.hibernate.AnnotationException: No identifier specified for entity: myapp.domain.party.Party
   at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:627)
   at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
   at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:246)


Clearly, I have specified an identifier for the Party object. Why is JBoss complaining?

Thanks.
Naresh


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 15, 2008 6:02 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
do you have a file named 'persistence.xml' in the directory META-INF defined? and did you define your entity classes in this file?

here is an example of persistence.xml:
Code:
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
             version="1.0">

   <persistence-unit name="prj">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/prjDS</jta-data-source>

      <mapping-file>META-INF/orm_prj.xml</mapping-file>

      <class>org.prj.base.domain.Check</class>
  (....)

_________________
Carlo
-----------------------------------------------------------
please don't forget to rate if this post helped you


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.