-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Composite-Id parent-child relationship, child loading error
PostPosted: Tue Feb 17, 2004 11:38 am 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
I use latest hibernate with oracle

I have 2 tables (parent-child)

parent table: MITGLIEDSCHAFT_SCHUTZBRIEF

it's composite key ->

INSTANZ VARCHAR2 17, 17, 0 Not Null false
BEGINNDATUM DATE 0 Not Null false

many fiels

child table: KINDERLEISTUNGSART

it's composite key

INSTANZ VARCHAR2 17, 17, 0 Not Null false
BEGINNDATUM DATE 0 Not Null false
ERFASSUNGSBEGINN DATE 0 Not Null false

Mapping files

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="classes.MitgliedschaftSchutzbrief" table="MITGLIEDSCHAFT_SCHUTZBRIEF">
<composite-id name="compId" class="classes.MitgliedschaftSchutzbrief$CompositeId">
<key-property name="instanz" column="instanz" type="string"/>
<key-property name="beginndatum" column="beginndatum" type="date"/>
</composite-id>
<property name="aktion"/>
<property name="bankleitzahl"/>
<property name="ck_hauptmitglied"/>
<property name="clubkarten_nr"/>
<property name="clubkarten_nr_hauptmitglied"/>
<property name="einschreibgebuehr"/>
.......................
<set name="kinderleistungsarts" cascade="all" lazy="true">
<key>
<column name="instanz"/>
<column name="beginndatum"/>
</key>
<one-to-many class="classes.Kinderleistungsart"/>
</set>
</class>
</hibernate-mapping>

and the child one

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>
<class name="classes.Kinderleistungsart" table="KINDERLEISTUNGSART">
<composite-id name="compId" class="classes.Kinderleistungsart$CompositeId">
<key-many-to-one name="mitgliedschaftSchutzbrief" class="classes.MitgliedschaftSchutzbrief">
<column name="instanz"/>
<column name="beginndatum"/>
</key-many-to-one>
<key-property name="erfassungsbeginn" column="erfassungsbeginn" type="date"/>
</composite-id>
<property name="clubkarteerwuenscht"/>
<property name="geburtsdatum"/>
<property name="geschlecht"/>
<property name="letztesverarbeitungsdatum"/>
<property name="name"/>
<property name="verarbeitungsstatus"/>
<property name="vorname"/>
</class>

</hibernate-mapping>

and the java classes (I kicked out the unnecessary bean setters/getters)

public class MitgliedschaftSchutzbrief implements IMitgliedschaftSchutzbrief, Serializable {

//CompositeKey Mapper
private CompositeId compId;

//Bi-Directional Obj.
private Set kinderleistungsarts;

//Bean Properties
private String instanz; /* 17, 17, 0 not null */
private java.sql.Date beginndatum; /* date 0 not null */

/**
* @return
*/
public java.sql.Date getBeginndatum() {
return beginndatum;
}

public String getInstanz() {
return instanz;
}


/**
* @param date
*/
public void setBeginndatum(java.sql.Date date) {
beginndatum = date;
}

public void setInstanz(String string) {
instanz = string;
}

/**
* @return
*/
public CompositeId getCompId() {
return compId;
}

/**
* @param id
*/
public void setCompId(CompositeId id) {
compId = id;
}


public String toString() {
return new ToStringBuilder(this);
}

public boolean equals(Object arg0) {
if (!(arg0 instanceof MitgliedschaftSchutzbrief)) return false;
if (arg0 == null) return false;
if (this == arg0) return true;

MitgliedschaftSchutzbrief that = (MitgliedschaftSchutzbrief) arg0;
return new EqualsBuilder()
.append(this.getCompId(), that.getCompId())
.append(this.getInstanz(), that.getInstanz())
.append(this.getBeginndatum(), that.getBeginndatum())
.append(this.getSatzart(), that.getSatzart())
.append(this.getVerarbeitungsstatus(), that.getVerarbeitungsstatus())
.append(this.getLetztesverarbeitungsdatum(), that.getLetztesverarbeitungsdatum())
.append(this.getClubkarten_nr(), that.getClubkarten_nr())
.append(this.getName(), that.getName())
.append(this.getVorname(), that.getVorname())
.append(this.getTitel(), that.getTitel())
.append(this.getGeschlecht(), that.getGeschlecht())
.append(this.getGeburtsdatum(), that.getGeburtsdatum())
.append(this.getTelefon(), that.getTelefon())
.append(this.getEmail(), that.getEmail())
.append(this.getStaat(), that.getStaat())
.append(this.getPlz(), that.getPlz())
.append(this.getStrasse(), that.getStrasse())
.append(this.getHaus_nr(), that.getHaus_nr())
.append(this.getHausnummernzusatz(), that.getHausnummernzusatz())
.append(this.getLeistungsart(), that.getLeistungsart())
.append(this.getKat(), that.getKat())
.append(this.getMitgliedsbetrag(), that.getMitgliedsbetrag())
.append(this.getEinschreibgebuehr(), that.getEinschreibgebuehr())
.append(this.getSchutzbriefbetrag(), that.getSchutzbriefbetrag())
.append(this.getCk_hauptmitglied(), that.getCk_hauptmitglied())
.append(this.getClubkarten_nr_hauptmitglied(), that.getClubkarten_nr_hauptmitglied())
.append(this.getText(), that.getText())
.append(this.getAktion(), that.getAktion())
.append(this.getBankleitzahl(), that.getBankleitzahl())
.append(this.getKonto_nr(), that.getKonto_nr())
.append(this.getKfz_kennzeichen(), that.getKfz_kennzeichen())
.append(this.getLenker(), that.getLenker())
.append(this.getWiederaufleben(), that.getWiederaufleben())
.append(this.getMitarbeiter_nummer(), that.getMitarbeiter_nummer())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(this.compId)
.append(this.instanz)
.append(this.beginndatum)
.append(this.satzart)
.append(this.verarbeitungsstatus)
.append(this.letztesverarbeitungsdatum)
.append(this.clubkarten_nr)
.append(this.name)
.append(this.vorname)
.append(this.titel)
.append(this.geschlecht)
.append(this.geburtsdatum)
.append(this.telefon)
.append(this.email)
.append(this.staat)
.append(this.plz)
.append(this.strasse)
.append(this.haus_nr)
.append(this.hausnummernzusatz)
.append(this.leistungsart)
.append(this.kat)
.append(this.mitgliedsbetrag)
.append(this.einschreibgebuehr)
.append(this.schutzbriefbetrag)
.append(this.ck_hauptmitglied)
.append(this.clubkarten_nr_hauptmitglied)
.append(this.text)
.append(this.aktion)
.append(this.bankleitzahl)
.append(this.konto_nr)
.append(this.kfz_kennzeichen)
.append(this.lenker)
.append(this.wiederaufleben)
.append(this.mitarbeiter_nummer)
.hashCode();
}

public static class CompositeId implements Serializable {
private String instanz = null;
private java.sql.Date beginndatum = null;
/**
* @return
*/
public java.sql.Date getBeginndatum() {
return beginndatum;
}

/**
* @return
*/
public String getInstanz() {
return instanz;
}

/**
* @param date
*/
public void setBeginndatum(java.sql.Date date) {
beginndatum = date;
}

/**
* @param string
*/
public void setInstanz(String string) {
instanz = string;
}

public String toString() {
return new ToStringBuilder(this)
.append("instanz",this.instanz)
.append("beginndatum",this.beginndatum).toString();
}

public boolean equals(Object arg0) {
if (!(arg0 instanceof CompositeId)) return false;
if (arg0 == null) return false;
if (this == arg0) return true;


CompositeId that = (CompositeId) arg0;
return new EqualsBuilder()
.append(this.getInstanz(), that.getInstanz())
.append(this.getBeginndatum(), that.getBeginndatum())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(this.instanz)
.append(this.beginndatum).hashCode();
}

}

/**
* @return
*/
public Set getKinderleistungsarts() {
return kinderleistungsarts;
}

/**
* @param set
*/
public void setKinderleistungsarts(Set set) {
kinderleistungsarts = set;
}

}


public class Kinderleistungsart implements IKinderleistungsart, Serializable {

//CompositeKey Mapper
private CompositeId compId;

// Bean properties
public String instanz; /* varchar2 17, 17, 0 not null */
public java.sql.Date beginndatum; /* date 0 not null */
public java.sql.Date erfassungsbeginn; /* date 0 not null */
public String verarbeitungsstatus; /* varchar2 1, 1, 0 nullable */
public java.sql.Date letztesverarbeitungsdatum; /* date 0 nullable */
public String name; /* varchar2 27, 27, 0 nullable */
public String vorname; /* varchar2 17, 17, 0 nullable */
public String geschlecht; /* varchar2 1, 1, 0 nullable */
public java.sql.Date geburtsdatum; /* date 0 nullable */
public int clubkarteerwuenscht; /* number 21, 1, 0 nullable */

/**
* @return
*/
public java.sql.Date getBeginndatum() {
return beginndatum;
}

/**
* @return
*/
public int getClubkarteerwuenscht() {
return clubkarteerwuenscht;
}

/**
* @return
*/
public java.sql.Date getErfassungsbeginn() {
return erfassungsbeginn;
}

/**
* @return
*/
public java.sql.Date getGeburtsdatum() {
return geburtsdatum;
}

/**
* @return
*/
public String getGeschlecht() {
return geschlecht;
}

/**
* @return
*/
public String getInstanz() {
return instanz;
}

/**
* @return
*/
public java.sql.Date getLetztesverarbeitungsdatum() {
return letztesverarbeitungsdatum;
}

/**
* @return
*/
public String getName() {
return name;
}

/**
* @return
*/
public String getVerarbeitungsstatus() {
return verarbeitungsstatus;
}

/**
* @return
*/
public String getVorname() {
return vorname;
}

/**
* @param date
*/
public void setBeginndatum(java.sql.Date date) {
beginndatum = date;
}

/**
* @param i
*/
public void setClubkarteerwuenscht(int i) {
clubkarteerwuenscht = i;
}

/**
* @param date
*/
public void setErfassungsbeginn(java.sql.Date date) {
erfassungsbeginn = date;
}

/**
* @param date
*/
public void setGeburtsdatum(java.sql.Date date) {
geburtsdatum = date;
}

/**
* @param string
*/
public void setGeschlecht(String string) {
geschlecht = string;
}

/**
* @param string
*/
public void setInstanz(String string) {
instanz = string;
}

/**
* @param date
*/
public void setLetztesverarbeitungsdatum(java.sql.Date date) {
letztesverarbeitungsdatum = date;
}

/**
* @param string
*/
public void setName(String string) {
name = string;
}

/**
* @param string
*/
public void setVerarbeitungsstatus(String string) {
verarbeitungsstatus = string;
}

/**
* @param string
*/
public void setVorname(String string) {
vorname = string;
}

public static class CompositeId implements Serializable {
private MitgliedschaftSchutzbrief mitgliedschaftSchutzbrief;
private java.sql.Date erfassungsbeginn = null;

public String toString() {
return new ToStringBuilder(this)
.append("mitgliedschaftSchutzbrief", this.mitgliedschaftSchutzbrief)
.append("erfassungsbeginn", this.erfassungsbeginn)
.toString();
}

public boolean equals(Object arg0) {
if (!(arg0 instanceof CompositeId))
return false;
if (arg0 == null)
return false;
if (this == arg0)
return true;

CompositeId that = (CompositeId) arg0;
return new EqualsBuilder()
.append(this.getMitgliedschaftSchutzbrief(), that.getMitgliedschaftSchutzbrief())
.append(this.getErfassungsbeginn(), that.getErfassungsbeginn())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(this.mitgliedschaftSchutzbrief)
.append(this.erfassungsbeginn)
.hashCode();
}

/**
* @return
*/
public java.sql.Date getErfassungsbeginn() {
return erfassungsbeginn;
}

/**
* @param date
*/
public void setErfassungsbeginn(java.sql.Date date) {
erfassungsbeginn = date;
}

/**
* @return
*/
public MitgliedschaftSchutzbrief getMitgliedschaftSchutzbrief() {
return mitgliedschaftSchutzbrief;
}

/**
* @param schutzbrief
*/
public void setMitgliedschaftSchutzbrief(MitgliedschaftSchutzbrief schutzbrief) {
mitgliedschaftSchutzbrief = schutzbrief;
}

}

/**
* @return
*/
public CompositeId getCompId() {
return compId;
}

/**
* @param id
*/
public void setCompId(CompositeId id) {
compId = id;
}

public boolean equals(Object arg0) {
if (!(arg0 instanceof Kinderleistungsart))
return false;
if (arg0 == null)
return false;
if (this == arg0)
return true;

Kinderleistungsart that = (Kinderleistungsart) arg0;
return new EqualsBuilder()
.append(this.getCompId(), that.getCompId())
.append(this.getInstanz(), that.getInstanz())
.append(this.getBeginndatum(), that.getBeginndatum())
.append(this.getErfassungsbeginn(), that.getErfassungsbeginn())
.append(
this.getVerarbeitungsstatus(),
that.getVerarbeitungsstatus())
.append(
this.getLetztesverarbeitungsdatum(),
that.getLetztesverarbeitungsdatum())
.append(this.getName(), that.getName())
.append(this.getVorname(), that.getVorname())
.append(this.getGeschlecht(), that.getGeschlecht())
.append(this.getGeburtsdatum(), that.getGeburtsdatum())
.append(
this.getClubkarteerwuenscht(),
that.getClubkarteerwuenscht())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(this.compId)
.append(this.instanz)
.append(this.beginndatum)
.append(this.erfassungsbeginn)
.append(this.verarbeitungsstatus)
.append(this.letztesverarbeitungsdatum)
.append(this.name)
.append(this.vorname)
.append(this.geschlecht)
.append(this.geburtsdatum)
.append(this.clubkarteerwuenscht)
.hashCode();
}

public String toString() {
return new ToStringBuilder(this)
.append("compId", this.compId)
.append("instanz", this.instanz)
.append("beginndatum", this.beginndatum)
.append("erfassungsbeginn", this.erfassungsbeginn)
.append("verarbeitungsstatus", this.verarbeitungsstatus)
.append("letztesverarbeitungsdatum", this.letztesverarbeitungsdatum)
.append("name", this.name)
.append("vorname", this.vorname)
.append("geschlecht", this.geschlecht)
.append("geburtsdatum", this.geburtsdatum)
.append("clubkarteerwuenscht", this.clubkarteerwuenscht)
.toString();
}

}


Ok, my problem is, IT LOADS all the PARENT classes, but when I try to access the getter getKinderleistungsarts() which should give me back the children SET, I got a NULL-Pointer exception...

MitgliedschaftSchutzbrief actual;
actual = (MitgliedschaftSchutzbrief) i.next(); --> this works show me the data of this row..
but if I call the getter on it, to get me the children SET
actual.getKinderleistungsarts() I got the NullPointerException

java.lang.NullPointerException
at net.sf.hibernate.collection.Set.toString(Set.java:219)
at java.lang.String.valueOf(String.java:2177)
at java.lang.StringBuffer.append(StringBuffer.java:361)
at at.oeamtc.mmnpo.test.HibernateCase.testConnection(HibernateCase.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)


this is the log ->


[main] test.HibernateCase (testConnection:51) - ### Mitgliedes: at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief@1f4e571[compId=at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief$CompositeId@1efb4be[instanz=OIPC55,beginndatum=1978-08-02],instanz=<null>,beginndatum=<null>,satzart=N,verarbeitungsstatus=<null>,letztesverarbeitungsdatum=<null>,clubkarten_nr=0,name=Bokuvka,vorname=Martin,titel=Ing,geschlecht=M,geburtsdatum=1962-10-04,telefon=<null>,email=<null>,staat=A,plz=3443,strasse=Am Buchgraben,haus_nr=7,hausnummernzusatz=<null>,leistungsart=MG,kat=A,mitgliedsbetrag=67,einschreibgebuehr=3,schutzbriefbetrag=0,ck_hauptmitglied=0,clubkarten_nr_hauptmitglied=0,text=<null>,aktion=PH,bankleitzahl=0,konto_nr=0,kfz_kennzeichen=<null>,lenker=<null>,wiederaufleben=0,mitarbeiter_nummer=7633]
2004-02-17 16:34:42,233 DEBUG [main] impl.SessionImpl (initializeCollection:3218) - initializing collection [at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief.kinderleistungsarts#at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief$CompositeId@1efb4be[instanz=OIPC55,beginndatum=1978-08-02]]
2004-02-17 16:34:42,233 DEBUG [main] impl.SessionImpl (initializeCollection:3219) - checking second-level cache
2004-02-17 16:34:42,233 DEBUG [main] impl.SessionImpl (initializeCollection:3225) - collection not cached
2004-02-17 16:34:42,233 DEBUG [main] impl.BatcherImpl (logOpenPreparedStatement:196) - about to open: 0 open PreparedStatements, 0 open ResultSets
2004-02-17 16:34:42,233 DEBUG [main] hibernate.SQL (getPreparedStatement:237) - select kinderleis0_.instanz as instanz__, kinderleis0_.beginndatum as beginnda2___, kinderleis0_.erfassungsbeginn as erfassun3___, kinderleis0_.instanz as instanz0_, kinderleis0_.beginndatum as beginnda2_0_, kinderleis0_.erfassungsbeginn as erfassun3_0_, kinderleis0_.clubkarteerwuenscht as clubkart4_0_, kinderleis0_.geburtsdatum as geburtsd5_0_, kinderleis0_.geschlecht as geschlecht0_, kinderleis0_.letztesverarbeitungsdatum as letztesv7_0_, kinderleis0_.name as name0_, kinderleis0_.verarbeitungsstatus as verarbei9_0_, kinderleis0_.vorname as vorname0_ from mapl.KINDERLEISTUNGSART kinderleis0_ where kinderleis0_.instanz=? and kinderleis0_.beginndatum=?
Hibernate: select kinderleis0_.instanz as instanz__, kinderleis0_.beginndatum as beginnda2___, kinderleis0_.erfassungsbeginn as erfassun3___, kinderleis0_.instanz as instanz0_, kinderleis0_.beginndatum as beginnda2_0_, kinderleis0_.erfassungsbeginn as erfassun3_0_, kinderleis0_.clubkarteerwuenscht as clubkart4_0_, kinderleis0_.geburtsdatum as geburtsd5_0_, kinderleis0_.geschlecht as geschlecht0_, kinderleis0_.letztesverarbeitungsdatum as letztesv7_0_, kinderleis0_.name as name0_, kinderleis0_.verarbeitungsstatus as verarbei9_0_, kinderleis0_.vorname as vorname0_ from mapl.KINDERLEISTUNGSART kinderleis0_ where kinderleis0_.instanz=? and kinderleis0_.beginndatum=?
2004-02-17 16:34:42,233 DEBUG [main] impl.BatcherImpl (getPreparedStatement:241) - preparing statement
2004-02-17 16:34:42,248 DEBUG [main] type.StringType (nullSafeSet:46) - binding 'OIPC55' to parameter: 1
2004-02-17 16:34:42,248 DEBUG [main] type.DateType (nullSafeSet:46) - binding '02 August 1978' to parameter: 2
2004-02-17 16:34:42,264 DEBUG [main] loader.Loader (handleEmptyCollections:327) - result set contains (possibly empty) collection: [at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief.kinderleistungsarts#at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief$CompositeId@1efb4be[instanz=OIPC55,beginndatum=1978-08-02]]
2004-02-17 16:34:42,264 DEBUG [main] impl.SessionImpl (getLoadingCollection:2996) - new collection: instantiating
2004-02-17 16:34:42,264 DEBUG [main] loader.Loader (doQuery:197) - processing result set
2004-02-17 16:34:42,264 DEBUG [main] loader.Loader (doQuery:226) - done processing result set (0 rows)
2004-02-17 16:34:42,264 DEBUG [main] impl.BatcherImpl (logClosePreparedStatement:203) - done closing: 0 open PreparedStatements, 0 open ResultSets
2004-02-17 16:34:42,264 DEBUG [main] impl.BatcherImpl (closePreparedStatement:261) - closing statement

Thanks for any help! I tryed many things, but I'm totally newbe to Hibernate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 12:06 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Some additional,

if I read the child object, they also read the parent well...

so if I have a child from the DB, that contains the parent..

I gueeess it's really simple what I do wrong. so sorry for me being ignorant.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 2:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Try to simplify your mapping, it's hard to read for us

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:30 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Ok,

I have two objects:

PARENT -> MITGLIEDSCHAFTSCHUTZBRIEF
CHILD -> KINDERLEISTUNGSART


Parent mapping

<hibernate-mapping>
<class name="classes.MitgliedschaftSchutzbrief" table="MITGLIEDSCHAFT_SCHUTZBRIEF">
<!-- the composite id fields -->
<composite-id name="compId" class="classes.MitgliedschaftSchutzbrief$CompositeId">
<key-property name="instanz" column="instanz" type="string"/>
<key-property name="beginndatum" column="beginndatum" type="date"/>
</composite-id>
<!-- this is the child SET which is a one-to-many -->
<set name="kinderleistungsarts" cascade="all" lazy="true">
<key>
<column name="instanz"/>
<column name="beginndatum"/>
</key>
<one-to-many class="classes.Kinderleistungsart"/>
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:32 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
This is a child mapping:

<hibernate-mapping>
<class name="classes.Kinderleistungsart" table="KINDERLEISTUNGSART">
<!-- it has composite key with 3 FIELDS in the db -->
<composite-id name="compId" class="classes.Kinderleistungsart$CompositeId">
<!-- this is for the parent -->
<key-many-to-one name="mitgliedschaftSchutzbrief" class="classes.MitgliedschaftSchutzbrief">
<column name="instanz"/>
<column name="beginndatum"/>
</key-many-to-one>
<key-property name="erfassungsbeginn" column="erfassungsbeginn" type="date"/>
</composite-id>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:35 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
this is the PARENT CLass

public class MitgliedschaftSchutzbrief implements IMitgliedschaftSchutzbrief, Serializable {

//CompositeKey Mapper
private CompositeId compId;

//Bi-Directional Obj.
private Set kinderleistungsarts;

//Bean Properties
private String instanz;
private java.sql.Date beginndatum;


/**
* @return
*/
public CompositeId getCompId() {
return compId;
}

/**
* @param id
*/
public void setCompId(CompositeId id) {
compId = id;
}

this is the static INNER class for the compositeID of this class

public static class CompositeId implements Serializable {
private String instanz = null;
private java.sql.Date beginndatum = null;
/**
* @return
*/
public java.sql.Date getBeginndatum() {
return beginndatum;
}

/**
* @return
*/
public String getInstanz() {
return instanz;
}

/**
* @param date
*/
public void setBeginndatum(java.sql.Date date) {
beginndatum = date;
}

/**
* @param string
*/
public void setInstanz(String string) {
instanz = string;
}


public boolean equals(Object arg0) {
...
}

public int hashCode() {
.....
}

}

// child SET
public Set getKinderleistungsarts() {
return kinderleistungsarts;
}

public void setKinderleistungsarts(Set set) {
kinderleistungsarts = set;
}

}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
How do you load the object ? (code between open and close)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:45 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Definition of the CHILD clss

public class Kinderleistungsart implements IKinderleistungsart, Serializable {

//CompositeKey Mapper
private CompositeId compId;

//PUBLIC INNER CLASS for the COMPOSITE-ID

public static class CompositeId implements Serializable {
private MitgliedschaftSchutzbrief mitgliedschaftSchutzbrief;
private java.sql.Date erfassungsbeginn = null;


public boolean equals(Object arg0) {
...
}

public int hashCode() {
....
}

public java.sql.Date getErfassungsbeginn() {
return erfassungsbeginn;
}


public void setErfassungsbeginn(java.sql.Date date) {
erfassungsbeginn = date;
}

// THE PARENT CLASS
public MitgliedschaftSchutzbrief getMitgliedschaftSchutzbrief() {
return mitgliedschaftSchutzbrief;
}

public void setMitgliedschaftSchutzbrief(MitgliedschaftSchutzbrief schutzbrief) {
mitgliedschaftSchutzbrief = schutzbrief;
}

}

public CompositeId getCompId() {
return compId;
}

public void setCompId(CompositeId id) {
compId = id;
}

public boolean equals(Object arg0) {
...
}

public int hashCode() {
....
}

}

WHEN I load via query the CHILD class the PARENT reference loaded,
and I have the parent as a filled object etc.

WHEN I load the Parent class, the class itself is loaded, but when I call the
getKinderleistungsarts() on the PARENT class which is supposed to give back the child records as a SET, I got a null pointer exception ->

java.lang.NullPointerException
at net.sf.hibernate.collection.Set.toString(Set.java:219)
at java.lang.String.valueOf(String.java:2177)
at java.lang.StringBuffer.append(StringBuffer.java:361)
at at.oeamtc.mmnpo.test.HibernateCase.testConnection(HibernateCase.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:392)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:276)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:167)

I don't know why, as the NullPointerException happends
at net.sf.hibernate.collection.Set.toString(Set.java:219)

Thanks for any idea, I just do not know where I should start looking :))

Also I use HIBERN8IDE, and I got the same problem, if I query the child object I got the result back, with the parent object in.
when I query the parent object, I got them back, back when I click on the child field, I got the same nullpointerException

Thanks again!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:46 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
tx = session.beginTransaction();
Query q =
session.createQuery(
"from MitgliedschaftSchutzbrief as mitgliedschaftSchutzbrief ");
q.setMaxResults(maxSize);
result = q.list();
tx.commit();
log.debug("Result list max ("+maxSize+") List size: " + result.size());
MitgliedschaftSchutzbrief actual = null;
for (Iterator i=result.iterator(); i.hasNext() ; ) {
actual = (MitgliedschaftSchutzbrief) i.next();
log.debug("### Mitgliedes: " +actual);
if (actual.getKinderleistungsarts() == null) {
log.debug(" --- Null children: " +actual);
} else {
log.debug(" --- Children: " +actual.getKinderleistungsarts());
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 4:50 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
in the hibernate log I have this line ->

result set contains (possibly empty) collection: [at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief.kinderleistungsarts#at.oeamtc.mmnpo.model.hibernate.MitgliedschaftSchutzbrief$CompositeId@1efb4be[instanz=OIPC55,beginndatum=1978-08-02]]

new collection: instantiating

but when I call the getter, it throws the NullPinterException on the
at net.sf.hibernate.collection.Set.toString

there is a change that the CHILD SET is empty as I have PARENTS which has no CHIDLREN in the DB...

Thx,


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 3:19 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
From the stack trace you gave me, the getter does not throw an exception (should return null I guess).
The toString() does. What is the exact code.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 5:02 am 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Sorrry for answering this late, but in the mean time I had sleep a little ;)

log.debug(" --- Children: " +actual.getKinderleistungsarts());

but it is thrown by the hibernate clas, isn't it ?

at net.sf.hibernate.collection.Set.toString

and it's definatelly not null as I check if the set is null by ->

if (actual.getKinderleistungsarts() == null) {
log.debug(" --- Null children: " +actual);
} else {
log.debug(" --- Children: " +actual.getKinderleistungsarts());
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 10:50 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Open a bug to JIRA on the collection.toString() NPE, please.
Having a simple test case would be great.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 1:15 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
OK,

thanks for the help....

but it think I do something wrong.

as every function call isEmpty, Iterator on the SET object fires a null pointer exception..

if you could explain me one thing, I might be able to locate the problem.

if you have PARENT - CHILD relationship,

and both table has composite-keys...

PARENT table's composite key is fields A, B
CHILD table's composite key is fields A,B,C

would there be a better way mapping them ->

PARENT table mapping:

<class name="ParentClassname" table="PARENT_TABLE">
<composite-id name="compId" class="at.oeamtc.mmnpo.model.hibernate.ParentClass$CompositeId">
<key-property name="A" column="instanz" type="string"/>
<key-property name="B" column="beginndatum" type="date"/>
</composite-id>

<set name="childs" cascade="all" lazy="true">
<key>
<column name="A"/>
<column name="B"/>
</key>
<one-to-many class="ChildClassName"/>
</set>

CHILD table mapping:

<class name="ChildClassName" table="CHILD">
<composite-id name="compId" class="ChildClassName$CompositeId">
<key-many-to-one name="parentName" class="ParentClassName">
<column name="A"/>
<column name="B"/>
</key-many-to-one>
<key-property name="C" column="C" type="date"/>
</composite-id>


Thanks.

ps: ALSO I'm defining the Composition Classes as STATIC INNER CLASS,
I don't know if this could be a problem, is this a good way of doing it, or I should separate them to SEPARATE CLASSES?

Nice thing is it works from the CHILD side, when I don't you the SET, is there any other way to have a collection ?

Thanks a lot for you help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 3:34 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Ok,

I did lot's of testing.

If I kick out the ALL DATE fields from the composite id. it works very well.

if I put any DATE field in, it does with that exception.

Does that make any sense ?


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

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.