-->
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: Problem with foreign key in same table
PostPosted: Mon Oct 20, 2008 7:02 am 
Newbie

Joined: Fri Jul 25, 2008 4:03 am
Posts: 7
Hi,

I have a table "Attribute". Attributes can be of kind main, sub or single. Main and sub attributes should be in relation with each other. So I defined a mainAttribute which should be filled when it is a sub attribute.

When I build my attribute set I assign the main attribute object to the mainAttribute member. When I try to insert this, I get: ORA-02291: integrity constraint (USR.FK955EEBD5F5D4109C) violated - parent key not found

I don't know which Ids are set, because this happens in the insert method of hibernate. Can I somehow log the parameters, after the Ids are filled by hibernate?

Is my understanding how to handle such a relation correct or should I modfy my ER-Model? Can such thing modelled into one table?

Code:

public class Attribute  implements java.io.Serializable {

     /**
    *
    */
   private static final long serialVersionUID = -4735854874205612593L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
   private long id;
    @Column(name="attribute_code", length=5)
    private String attributeCode;         
    @Column(name="attribute_kind", length=20)
    private String attributeKind;
   @GeneratedValue (generator = "fkMainAttributeGenerator")   
   @org.hibernate.annotations.GenericGenerator(name=
   "fkMainAttributeGenerator", strategy = "foreign", parameters={
   @Parameter(name="property", value="mainAttribute")})
   @Column (name = "main_attribute_id")
   private long mainAttributeId;
   @ManyToOne (targetEntity = Attribute.class)
    @JoinColumn (name = "main_attribute_id", insertable = false, updatable = false)
    private Attribute mainAttribute;
    @Column(name="description")
    private String description;
    @Column(name="currency", length=5)
    private String currency;
    @Column(name="amount")
    private Float amount;
    @Column(name="attribute_date", length=50)
    private String attributeDate;
    @Column(name="rate_count")
    private int rateCount;
    @Column(name="rate_kind")
    private String rateKind;
    @Column(name="account_number", length=20)
    private String accountNumber;
    @Column(name="attribute_text")
    private String attributeText;
    @Column(name="text")
    private String text;
    @Column(name="negative")
    private boolean negative;
    @ManyToOne (targetEntity = Data.class, fetch = FetchType.LAZY)
    @JoinColumn (name = "_data_id")
    private Data Data;



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.