-->
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.  [ 1 post ] 
Author Message
 Post subject: Mapping joined entities with composite key in base
PostPosted: Tue Jun 19, 2012 10:53 am 
Newbie

Joined: Tue Jun 19, 2012 10:29 am
Posts: 1
Dear all,

I'm a new user of hibernate v4.0.1 final.
Recently I am trying to use hibernate to map to some tables of a legacy db.

The problem is the joined subclasses only have a part of the composite key of the base.

Base class:
Code:
@Entity
@Table(name="foo")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@IdClass(CompositeId.class)
public abstract class Foo implements Serializable {

  @Id
  @Column(name = "primkey")
  private Long id;

  @Id
  @Column(name = "type")
  private String type;

Composite key class:
Code:
public class CompositeId implements Serializable {

    private Long id;

    private String type;

Sub class with its own table but only one primary key:
Code:
@Entity
@Table(name="bar")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorValue("bartype")
@PrimaryKeyJoinColumn(name = "barkey", referencedColumnName = "primkey")
public class Bar extends Foo {


This is what I get:
Quote:
[INFO] [talledLocalContainer] Caused by: org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key


If I don't use a composite key in the base class I get undesired results.

Any ideas?
Of course I could adapt the tables of the subclasses so that the composite key can be properly mapped with @PrimaryKeyJoinColumns but I'd like to avoid this if possible.


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

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.