-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with InheritanceType.JOINED strategy
PostPosted: Wed Feb 04, 2009 2:37 pm 
Newbie

Joined: Mon Feb 02, 2009 12:41 pm
Posts: 5
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);


Top
 Profile  
 
 Post subject: Re: Problem with InheritanceType.JOINED strategy
PostPosted: Tue May 26, 2009 6:08 am 
Newbie

Joined: Tue May 26, 2009 5:20 am
Posts: 1
Hi kemparajuknk,

my domain model has the same structure. I have a mapped superclass AbstractEntity (with id, version, change date, etc) an abstract subclass SectionType (with InheritanceType=JOINED) and concrete subclasses PageSection, ContainerSection and ModuleSection. When I create a PageSection and try to persist it to the database with save/flush I run into the very same problem and get the above mentioned PropertyValueException. Do you have found a solution to your problem?

@HibernateTeam: Any hints what the cause of the problem might be? I can supply more infos about my domain model and configuration if needed.

Hibernate: 3.3.1 GA
Database: MySQL 5.0.51a-27.2

Stacktrace: org.hibernate.PropertyValueException: not-null property references a null or transient value: geneon.genera.domain.PageSection._sectionTypesBackref
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:562)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:550)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:546)
...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.