-->
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: Bi-directinal OneToMany with EmbeddedId
PostPosted: Thu Aug 26, 2010 3:50 pm 
Newbie

Joined: Thu Aug 26, 2010 3:37 pm
Posts: 6
I'm using Hibernate Entity Manager 3.3.2 and am trying to create a bi-directional OneToMany association with the OneToMany side being the owning side. My two tables are set up like so:

Table 1
APPID primary key generated by a sequence on the database

Table 2
APPID foreign key to Table 1 and part of primary key
OFF_NO part of primary key
OFF_BANK part of primary key

Table 1 Entity looks like this
Code:
public class AppDetails implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @SequenceGenerator(name="APP_ID_GEN", sequenceName="PTS_APP_DTL_APPID_SEQ")
    @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="APP_ID_GEN")
    private long appid;

    @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinColumn(name="APPID", nullable=false)
    @org.hibernate.annotations.Cascade({
        org.hibernate.annotations.CascadeType.SAVE_UPDATE,
        org.hibernate.annotations.CascadeType.DELETE_ORPHAN
    })
    private Set<OfficerDetails> ptsOfficerDetails = new HashSet<OfficerDetails>();

    ...
}


Table 2 entity looks like this:
Code:
public class OfficerDetails implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private OfficerDetailsPK id;

    @ManyToOne
    @JoinColumn(name="APPID", insertable=false, updatable=false, nullable=false)
    private AppDetails ptsAppDetail;

   ...
}


OfficerDetailsPK looks like:
Code:
@Embeddable
public class OfficerDetailsPK implements Serializable {

    private static final long serialVersionUID = 1L;

    private long appid;

    @Column(name="OFF_BANK")
    private String offBank;

    @Column(name="OFF_NO")
    private String offNo;

    ...
}


I'm getting the following error when a save is done on my Table 1 entity:
org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): OfficerDetails

I don't think my bi-directional annotations are quite right. Any help is greatly appreciated.


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.