-->
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: Parent id is not being populated to child's reference key
PostPosted: Fri Jan 25, 2013 3:33 am 
Newbie

Joined: Fri Jan 25, 2013 3:07 am
Posts: 1
Hi All,

I have following class structure
-------------------->
Code:
@Entity
@Table(name="APP_SENSOR")
public class Sensor implements Serializable {
   
   private static final long serialVersionUID = 1L;
   
   @Id
   private Integer id;
   
   @Column(name="NAME")
   private String name;
   
   @Column(name="COMMENTS")
   private String comments;
   
   @OneToMany(targetEntity = ApplicationSensorCustomFilter.class,mappedBy="applicationSensor",cascade = CascadeType.ALL)
   private Set<ApplicationSensorCustomFilter> applicationSensorCustomFilter;
   
// getter and setter

}

-------------------->

Code:
@Entity
@Table(name="APP_SENSOR_CUSTOM_FILTER")
public class ApplicationSensorCustomFilter implements Serializable{
   
   private static final long serialVersionUID = 1L;
   
   @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_APP_SENSOR_CUSTOM_FILTER")
   @javax.persistence.SequenceGenerator(name="SEQ_APP_SENSOR_CUSTOM_FILTER", sequenceName="SEQ_APP_SENSOR_CUSTOM_FILTER")
   private Integer id;
   
   @Column(name="APP_SENSOR")
   private Integer applicationSensor;
   
   

   @OneToMany(targetEntity=CustomFilterVendorRel.class,cascade = CascadeType.ALL, fetch = FetchType.LAZY , mappedBy="customFilterVendorRelPK.customFilter")
   private Set<CustomFilterVendorRel> vendors;

// getter and setters

}

-------------------->

Code:
@Entity
@Table(name="CUSTOM_FILTER_VENDOR_REL")
public class CustomFilterVendorRel {
   
   @EmbeddedId
   private CustomFilterVendorRelPK customFilterVendorRelPK;    // this is composite key

    // getter and setter
}



------------------------------>

Code:
public class CustomFilterVendorRelPK implements Serializable{

   private static final long serialVersionUID = 1L;
   
   @ManyToOne(targetEntity=ApplicationSensorCustomFilter.class)
   @JoinColumn(name="CUSTOM_FILTER")
   private Integer customFilter;
   
   @OneToOne
    @JoinColumn(name="VENDOR", nullable=false)
   private Vendor vendor;

   // getter and setter
}


----------------------->

Problem : I have fresh instance of Sensor which is not even stored in db. I have set Id field into it. Inside Sensor instance i have set of ApplicationFilterCustomFilter. here i knw id of Sensor so no problem with parent key. up to now every thing is ok. Now inside ApplicationFilterCustomFilter i have set of CustomFilterVendorRel which have composite key with ApplicationFilterCustomFilter's id and vendor.
Here Id for ApplicationFilterCustomFilter is autogenerated.


As per my understanding when i store Sensor. It should store Sensor then list of ApplicationFilterCustomFilter and then CustomFilterVendorRel.

insert are being fired properly but in CustomFilterVendorRel table id of ApplicationFilterCustomFilter is not getting populated it is inserting null. which is not allowed as filed is not null and it is part of composite key.

I tried to explain my problem as much i can. WHY IT IS INSERTING NULL... m i missing anything ????:(


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.