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: Nested Composite Keys
PostPosted: Wed Aug 29, 2012 3:21 pm 
Newbie

Joined: Mon Oct 27, 2008 3:27 pm
Posts: 7
I have a set of composite keys, that later became a part of a Foreign key in other entity, and resulted in becoming part of the Primary key of such entity. So I ended having the following Embeddable objects.
Code:
@Embeddable
public class ProductId implements Serializable {
    @Column(name = "Id", columnDefinition = "bigint identity(1,1)")
    private Long id;

    @Column(name = "ProductTypeName")
    private String name;
....
}

@Embeddable
public class ApplicationId implements Serializable{
    @Column(name = "Id", columnDefinition = "bigint identity(1,1)",
            nullable = false, insertable = false, updatable = false)
    private Long id;
    @Embedded
    @AttributeOverride(name="id",
                       column=@Column(name="ProductId",
                                      columnDefinition = "bigint identity(1,1)",
                                      nullable = false, insertable = false,
                                      updatable = false))
    private ProductId productId;
....
}


So I have to different embeddable objects, one for the PK of an entity called Product, and the other for an entity called Application.
The problems comes when hibernate scanned my Application entity (see snippet below)
Code:
@Entity(name = "Application")
@Table(name = "Application")
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Application {

    @EmbeddedId
    private ApplicationId applicationPk;

    @MapsId("productId")
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumns({@JoinColumn(name = "ProductId", referencedColumnName = "Id",
                              nullable = false, insertable = true,
                              updatable = true),
                  @JoinColumn(name = "ProductTypeName",
                              referencedColumnName = "ProductTypeName",
                              nullable = false, insertable = true,
                              updatable = true)})
    @ForeignKey(name = "FK_Application_Product")
    private Product product;
....}


Hibernate complains with the following error
Code:
Caused by: org.hibernate.MappingException: Unable to find column with logical name: ProductId in Application


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.