Hibernate version: 3.2.3GA
Oracle: 10.2:
I have a parent-child-grandchild relp similar to the following:
Code:
public class Parent {
Set<Child> children ;
...
@OneToMany(mappedBy="parent")
@JoinColumn(name="PARENT_ID")
@Cascade( {CascadeType.SAVE_UPDATE, CascadeType.REFRESH})
public Set<Child> getChildren() {
return children ;
}
public void setChildren( Set<Child> _set ){
children = _set ;
}
}
public class Child {
Parent parent ;
Set<GrandChild> grandChildren ;
Language language ;
@OneToMany(mappedBy="child")
@JoinColumn(name="CHILD_ID")
@Cascade( {CascadeType.SAVE_UPDATE, CascadeType.REFRESH})
public Set<Child> getGrandChildren() {
return grandChildren ;
}
public void setGrandChildren( Set<GrandChild> _set ){
grandChildren = _set ;
}
@ManyToOne
@JoinColumn(name="LANGUAGE_ID")
public Language getLanguage() {
return language ;
}
public void setLanguage( Language lang ) {
language = lang ;
}
@ManyToOne
@JoinColumn(name="PARENT_ID")
public Parent getParent() {
return parent ;
}
public void setParent( Parent _parent) {
parent = _parent ;
}
}
public class GrandChild {
Language language ;
Child child ;
@ManyToOne
@JoinColumn(name="LANGUAGE_ID")
public Language getLanguage () {
return language ;
}
public void setLLanguage ( Language lang ) {
language = lang ;
}
@ManyToOne
@JoinColumn(name="CHILD_ID")
public Parent getChild() {
return child;
}
public void setChild( Child _parent) {
child = _parent ;
}
}
AND
public class Language {
Child child ;
GrandChild grandChild;
String description ;
@ManyToOne
@JoinColumn(name="LANGUAGE_ID")
public Parent getChild() {
return child;
}
public void setChild( Child _parent) {
child = _parent ;
}
@ManyToOne
@JoinColumn(name="LANGUAGE_ID")
public Parent getGrandChild() {
return grandChild;
}
public void setGrandChild( GrandChild _parent) {
grandChild = _parent ;
}
}
When I insert a new Child to the parent, I have no problems with a refresh on the Parent. But when I
insert a grandchild, and perform refresh on the Parent, it seems that the grandchild is not refreshed.
Here is the code snipped of update / refresh ( within one @Transactional method ) .
Code:
session.flush( parent ) ;
session.persist( parent ); /// Inserts gc to the DB.
session.refresh( parent );
...
// Following generates null pointer exception
for ( GrandChild gc : child.getGrandChildren() ) {
System.out.println( gc.getLanguage().getDescription ) ;
// -- the getLanguage on the gc recently added is null
}
When I turn sql debugger on - I can see that the SQL call to Language table is not being called for
the inserted object ( it is being called at initial retrieval time ) .
I'm at a loss here why the grandchildren is behaving differently - Am hoping someone can shed some light.
Thanks in advance ..