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 ????:(