My domain model is as mentionded below.
Class ChildClass1 extends ParentClass using InheritanceType.JOINED.
Parent class has one-to-one relation with Another class.
DummyClass has onetoone relation with ChildClass1 .
When i try to save Parent object which has childclass1 , Another object and DummyClass object, save operation is failing.
It is executing only insert into ParentClass (Version, ToolDescription, ToolName) values (?, ?, ?) this statement and failing. I am getting below exception.
org.springframework.dao.DataIntegrityViolationException: not-null property references a null or transient value: .tool.actions.Another.parentClass; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value:
Could any body please let me know what is the problem with my domain model?
_______________________________________________________________________________________
@MappedSuperclass
@javax.persistence.SequenceGenerator(name = "SEQ_STORE", sequenceName = "my_sequence")
public class IdObject{
protected int id;
protected long version;
@Id
@Column(name = "Id", insertable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Version
@Column(name = "Version")
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
}
_______________________________________________________________________________________
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public class ParentClass extends IdObject {
private String toolName;
private String toolDescription;
private Another another;
@Column(name = "ToolDescription", nullable = true)
public String getToolDescription() {
return toolDescription;
}
public void setToolDescription(String toolDescription) {
this.toolDescription = toolDescription;
}
@Column(name = "ToolName", nullable = false, unique = true)
public String getToolName() {
return toolName;
}
public void setToolName(String toolName) {
this.toolName = toolName;
}
@OneToOne(mappedBy = "parentClass")
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public Another getAnother() {
return another;
}
public void setAnother(Another another) {
this.another = another;
}
}
_______________________________________________________________________________________
@Entity
@PrimaryKeyJoinColumn(name = "ChildId1")
public class ChildClass1 extends ParentClass{
private String name;
private DummyClass dummyClass;
private String placeHolder;
@OneToOne(mappedBy = "childClass1")
@Cascade( { org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public DummyClass getDummyClass() {
return dummyClass;
}
public void setDummyClass(DummyClass dummyClass) {
this.dummyClass = dummyClass;
}
@Column(name = "Name", nullable = false, unique = true)
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Column(name = "placeHolder", nullable = false)
public String getPlaceHolder() {
return placeHolder;
}
public void setPlaceHolder(String placeHolder) {
this.placeHolder = placeHolder;
}
}
_______________________________________________________________________________________
@Entity
public class Another extends IdObject {
private ParentClass parentClass;
@OneToOne
@ForeignKey(name = "FK_TMP_2")
@JoinColumn(name = "ParentId", insertable = true, updatable = false, nullable = false)
public ParentClass getParentClass() {
return parentClass;
}
public void setParentClass(ParentClass parentClass) {
this.parentClass = parentClass;
}
}
_______________________________________________________________________________________
@Entity
public class DummyClass extends IdObject {
private String name1;
private ChildClass1 childClass1;
@OneToOne
@ForeignKey(name = "TEMP_FLK")
@JoinColumn(name = "ParentClassId", insertable = true, updatable = false, nullable = false)
public ParentClass getChildClass1() {
return childClass1;
}
public void setChildClass1(ChildClass1 childClass1) {
this.childClass1 = childClass1;
}
@Column(name = "Name1", nullable = false, unique = true)
public String getName1() {
return name1;
}
public void setName1(String name) {
this.name1 = name;
}
}
When i do the below operations to save Parent object, it is failing.
HibernateTemplate temp = new HibernateTemplate(getSessionFactory());
ParentClass parent = new ChildClass1();
((ChildClass1) parent).setPlaceHolder("Child1PlaceHolder");
((ChildClass1) parent).setName("Test");
parent.setToolName("Child1Tool");
DummyClass dummyClass = new DummyClass();
dummyClass.setName1("Dummy");
((ChildClass1) parent).setDummyClass(dummyClass);
Another another = new Another();
parent.setAnother(another);
temp.save(parent);
|