This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark ""No identifier specified" when using InheritanceType.JOINED" Watch ""No identifier specified" when using InheritanceType.JOINED" New topic
Author

"No identifier specified" when using InheritanceType.JOINED

Peter Irmstadt
Greenhorn

Joined: Mar 01, 2009
Posts: 24
Hi!

I am using JBoss Seam and MySQL to develop a web application.
There are few kind of users that may login to my application. To reduce overhead I want to create a class for each usertype that may login.

This is what I did:

The main class:


and this a sample "child"


But when trying to publish these two classes I get the following error:

org.hibernate.AnnotationException: No identifier specified for entity: de.my-project.entity.LoginBenutzer


I looked for some examples but none of them had a primary key on the child entity. Where is my mistake? Whan can I do to solve that problem?

Thank you in advance!
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

Does each table have its own id field? This is where the join occurs.

I have three classes that participate in inheritance in my JOIN example, and you will notice that each has its own id field:




I have a little tutorial on mapping inheritance that you might find interesting. A Joined table mapping is provided as an example:

The Three Forms of Inheritance Mapping with Hibernate: A Simple Tutorial


Joined Table Inheritance

One of the ugly aspects of the TABLE_PER_CLASS inheritance type is the fact that properties get duplicated down the class hierarchy. For example, why should the child table declare columns of type id and nationality when they are already defined in the ancestor table? The JOINED inheritance type addresses this problem by having tables only maintain data that maps directly to the properties in the associated class. Subclasses are then linked to their inherited properties through common primary key fields in the tables, linking as UNION joins at runtime.

To use a JOIN for mapping inheritance, all we have to do is edit the @Inheritance annotation of the Ancestor class, and set the strategy attribute to InheritanceType.JOINED:

@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class Ancestor { ... }
When using a JOINED strategy for our problem domain, Hibernate expects three database tables, with each table mapping to the various properties defined in each class. The id field then forms a union between tables. So, if an Ancestor instance is saved, a record will be created in only the ancestor table, whereas if a Child instance is created, the fields of the instance will be saved in all three tables, with the records in each table associated, or joined, through a common value for the id field. In essence, the class hierarchy of an instance is JOINED together from all of the individual tables.


Goodl luck!

-Cameron McKenzie
Peter Irmstadt
Greenhorn

Joined: Mar 01, 2009
Posts: 24
thank you for your answer!

Unfortunalety this doesn't seem to help me. I added an ID to the fields, but this became only a unique ID of the tables of the subclasses.
I bought a hibernate book that says (translated from German): "Use @Inheritance to set the inheritance type to JOINED. There's no need for further settings or annotations in the subclasses. If you want to rename the id field that is used to join the child classes with the parent ones you can use "@PrimaryKeyJoinColumn" in front of the class".

But no matter if I use it or not, I still get the same error. Any other ideas where my mistake might be?
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

I feel I've been challenged.

What's your development environment and what version of Hibernate/JPA are you using? Maybe I'll give this a try on my own.

Regards,

-Cameron
Peter Irmstadt
Greenhorn

Joined: Mar 01, 2009
Posts: 24
thank you for your answer!

I am using

  • Eclipse 3.4.2
  • JBoss Seam 2.1.1.GA
  • Newest version of JBoss Tools
  • Java version 1.6.0_13
  • Hibernate 3.2.4.sp1
  • Hibernate EntityManager 3.2.1.GA
  • Hibernate Annotations 3.2.1.GA
  • JBoss AS 4.2.1.GA

  • Thank you in advance!
    Douglas Ferguson
    Greenhorn

    Joined: Sep 07, 2009
    Posts: 2
    Did you ever figure this out?
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: "No identifier specified" when using InheritanceType.JOINED
     
    Similar Threads
    table not mapped error when compiling entity bean
    Mysql auto generated PK used for another table and JPA
    composite key and Criteria API [Hibernate]
    Could not determine type for: java.util.Set
    JPA returning collection of type PersistentBag instead of ArrayList