-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-to-many and sets
PostPosted: Mon Mar 01, 2004 10:10 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
I'm having a problem grasping the many-to-ones, one-to-many, and set declarations in the Hibernate mapping files.

In my database (MySQL), I have a CUSTOMER table and CONTACT table. The CONTACT table has Many to One relationship with the CUSTOMER table, meaning that many CONTACTS can be associated with one CUSTOMER. Originally, I only had many-to-one mappings in my mapping file, but I started to get errors along the line of a TransientObjectException, or something like that. After reading in the forum for awhile, I started using sets and one-to-many mappings in 1 of my 15 or so mapping files (for the parent table of the two tables that were being manipulated, CONTACT). This files looked like this:

<?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="com.mypackage.db.dao.Ctc" table="CTC_CONTACT">

<!-- Map columns -->
<!-- Unique id to be used as a type of Primary Key -->
<id name="Uid" type="java.lang.Long" unsaved-value="null">
<column name="CTC_UID" sql-type="long" not-null="true"/>
<generator class="increment"/>
</id>

<set name="CusItems" inverse="true" cascade="all">
<key column="CTC_UID"/>
<one-to-many class="com.mypackage.db.dao.Cus"/>
</set>

<property name="Id" type="java.lang.String">
<column name="CTC_ID" sql-type="varchar(12)" not-null="true"/>
</property>

<many-to-one name="Cus" column="CTC_CUS_UID" class="com.mypackage.db.dao.Cus" cascade="save-update" insert="true"/>

<property name="Surname" type="java.lang.String">
<column name="CTC_SURNAME" sql-type="varchar(30)" not-null="true"/>
</property>

<property name="Forename" type="java.lang.String">
<column name="CTC_FORENAME" sql-type="varchar(30)" not-null="true"/>
</property>

<property name="Middlename" type="java.lang.String">
<column name="CTC_MIDDLENAME" sql-type="varchar(30)" not-null="true"/>
</property>

<property name="FormattedName" type="java.lang.String">
<column name="CTC_FORMATTED_NAME" sql-type="varchar(94)" not-null="true"/>
</property>

<property name="Title" type="java.lang.String">
<column name="CTC_TITLE" sql-type="varchar(10)" not-null="true"/>
</property>

<property name="Gender" type="java.lang.String">
<column name="CTC_GENDER" sql-type="varchar(1)" not-null="true"/>
</property>

<property name="Phone" type="java.lang.String">
<column name="CTC_PHONE" sql-type="varchar(20)" not-null="true"/>
</property>

<property name="Fax" type="java.lang.String">
<column name="CTC_FAX" sql-type="varchar(20)" not-null="true"/>
</property>

<property name="City" type="java.lang.String">
<column name="CTC_CITY" sql-type="varchar(40)" not-null="true"/>
</property>

<property name="Email" type="java.lang.String">
<column name="CTC_EMAIL" sql-type="varchar(20)" not-null="true"/>
</property>

<property name="DateCreated" type="java.util.Date">
<column name="CTC_DATE_CREATED" sql-type="null" not-null="true"/>
</property>

<property name="UsrCreatedBy" type="java.lang.Long">
<column name="CTC_USR_CREATED_BY" sql-type="numeric(8)" not-null="true"/>
</property>

<property name="DateUpdated" type="java.util.Date">
<column name="CTC_DATE_UPDATED" sql-type="null" not-null="true"/>
</property>

<property name="UsrUpdatedBy" type="java.lang.Long">
<column name="CTC_USR_UPDATED_BY" sql-type="numeric(8)" not-null="true"/>
</property>

</class>
</hibernate-mapping>

After I did, I stopped getting exceptions about Transient Objects, so I thought everything was solved. I went and made similar changes to all of my mapping files, and now I'm getting errors like this:

IllegalArgumentException in class: com.mypackage.db.dao.Res, setter method of property: InlItems

Below is a copy of my res.hbm.xml file, followed by my com.mypackage.db.dao.Res file:

<?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="com.mypackage.db.dao.Res" table="RES_RESOURCE">


<!-- Map Columns -->

<!-- Unique ID to be used as a type of Primary Key -->
<id name="Uid" type="java.lang.Long" unsaved-value="null">
<column name="RES_UID" sql-type="numeric(8)" not-null="true"/>
<generator class="increment"/>
</id>

<property name="Id" type="java.lang.String">
<column name="RES_ID" sql-type="varchar(10)" not-null="true"/>
</property>

<many-to-one name="Inl" column="RES_INL_CODE" class="com.mypackage.db.dao.Inl"/>

<set name="InlItems" inverse="true" cascade="all">
<key column="RES_UID"/>
<one-to-many class="com.mypackage.db.dao.Inl"/>
</set>

<many-to-one name="Inc" column="RES_INC_CODE" class="com.mypackage.db.dao.Inc"/>

<set name="IncItems" inverse="true" cascade="all">
<key column="RES_UID"/>
<one-to-many class="com.mypackage.db.dao.Inc"/>
</set>

<many-to-one name="Ver" column="RES_VER_CODE" class="com.mypackage.db.dao.Ver"/>

<set name="VerItems" inverse="true" cascade="all">
<key column="RES_UID"/>
<one-to-many class="com.mypackage.db.dao.Ver"/>
</set>

<property name="Revision" type="java.lang.Long">
<column name="RES_REVISION" sql-type="numeric(2)" not-null="true"/>
</property>

<property name="Value" type="java.lang.String">
<column name="RES_VALUE" sql-type="varchar(2000)" not-null="true"/>
</property>

</class>
</hibernate-mapping>
package com.mypackage.db.dao;

import java.util.*;
import com.mypackage.db.dao.*;


public class Res implements com.mypackage.middletier.Pojo {

private java.lang.Long uid;
private java.lang.String id;
private Inl inl;
private Inc inc;
private Ver ver;
private java.lang.Long revision;
private java.lang.String value;
private Inl inlItems;
private Inc incItems;
private Ver verItems;

public Res() {
//Empty Constructor
}



public Inl getInlItems() {
return inlItems;
}
public void setInlItems (Inl pInlItems) {
pInlItems = inlItems;
}


public Inc getIncItems() {
return incItems;
}
public void setIncItems (Inc pIncItems) {
pIncItems = incItems;
}


public Ver getVerItems() {
return verItems;
}
public void setVerItems (Ver pVerItems) {
pVerItems = verItems;
}


public java.lang.Long getUid() {
return uid;
}
public void setUid(java.lang.Long pUid) {
uid = pUid;
}

public java.lang.String getId() {
return id;
}
public void setId(java.lang.String pId) {
id = pId;
}

public Inl getInl() {
return inl;
}
public void setInl(Inl pInl) {
inl = pInl;
}
public Inc getInc() {
return inc;
}
public void setInc(Inc pInc) {
inc = pInc;
}
public Ver getVer() {
return ver;
}
public void setVer(Ver pVer) {
ver = pVer;
}
public java.lang.Long getRevision() {
return revision;
}
public void setRevision(java.lang.Long pRevision) {
revision = pRevision;
}

public java.lang.String getValue() {
return value;
}
public void setValue(java.lang.String pValue) {
value = pValue;
}

}//class

Can anyone see anything wrong with the way I'm going about this? If anyone can help, I would really appreciate it. Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 4:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
How is your getter for the set called? if it is getInlItems(), your property name should be inlItems, as per the java beans spec.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 2:45 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
Thank you very much for the reply Michael. I'll give it a try today.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 10:59 pm 
Newbie

Joined: Tue Mar 02, 2004 10:56 pm
Posts: 12
Did this resolve your issue? i have a similar problem. i am working my way through posts, but have not found what i am looking for. working with hib 2.0 i used middlegen to create hbm files - and i am getting a problem with my set definitions - i checked the CASE of my getter/setters and they seem to follow bean standards - looking for other solutions.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.