I am relatively new to hibernate. I am evaluating hibernate as O/R tool for my company. I have a legacy database and I am trying out a simple load operation using composite key. I have a primary class created by middle gen
Hibernate version:
3.1
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.sungard.octagon.maintenance.Dictionary"
table="dictionary"
>
<composite-id name="comp_id" class="com.sungard.octagon.maintenance.Dictiona
ryPK">
<key-property
name="DictCode"
column="dict_code"
type="java.lang.String"
length="12"
/>
<key-property
name="SubCode"
column="sub_code"
type="java.lang.String"
length="12"
/>
</composite-id>
<property
name="codeDesc"
type="java.lang.String"
column="code_desc"
not-null="true"
length="30"
/>
<property
name="subDesc"
type="java.lang.String"
column="sub_desc"
not-null="true"
length="30"
/>
<property
name="updateUser"
type="java.lang.String"
column="update_user"
not-null="true"
length="12"
/>
<property
name="updateDate"
type="java.sql.Date"
column="update_date"
not-null="true"
length="26"
/>
<!-- Associations -->
<!-- derived association(s) for compound key -->
<!-- end of derived association(s) -->
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
dictPk = new DictionaryPK();
System.out.println("After PK1");
dictPk.setDictCode(dictCode);
System.out.println("After setDictCode"+ dictCode);
dictPk.setSubCode(subCode);
System.out.println("After setSubCode"+ subCode);
Dictionary dict = new Dictionary();
System.out.println("After dict init");
dict.setComp_id(dictPk);
System.out.println("After setComp_id dictcode="+ dict.ge
tComp_id().getDictCode());
//dictData = (Dictionary) session.load(Dictionary.class,
dictPk);
dictData = (Dictionary) session.load(Dictionary.class,di
ct);
Full stack trace of any exception that occurs:
After session open---|#]
[#|2006-03-27T15:15:40.710-0600|SEVERE|sun-appserver-pe8.1_01|org.hibernate.prop
erty.BasicPropertyAccessor|_ThreadID=29;|IllegalArgumentException in class: com.
sungard.octagon.maintenance.DictionaryPK, getter method of property: DictCode|#]
[#|2006-03-27T15:15:40.713-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in class: class com.sungard.octagon.maintenance.Dictio
naryPK|#]
[#|2006-03-27T15:15:40.714-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in property: DictCode|#]
[#|2006-03-27T15:15:40.714-0600|INFO|sun-appserver-pe8.1_01|javax.enterprise.sys
tem.stream.out|_ThreadID=29;|
Property Access Exception in class: IllegalArgumentException occurred calling ge
tter of com.sungard.octagon.maintenance.DictionaryPK.DictCode|#]
[#|2006-03-27T15:15:40.718-0600|WARNING|sun-appserver-pe8.1_01|javax.enterprise.
system.stream.err|_ThreadID=29;|org.hibernate.PropertyAccessException: IllegalAr
gumentException occurred calling getter of com.sungard.octagon.maintenance.Dicti
onaryPK.DictCode
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPro
pertyAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(Abstra
ctComponentTuplizer.java:121)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(Abstr
actComponentTuplizer.java:133)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoCompo
nentTuplizer.java:88)
at org.hibernate.type.ComponentType.getPropertyValues(ComponentType.java
:307)
at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:158)
at org.hibernate.engine.EntityKey.getHashCode(EntityKey.java:69)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:42)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEv
entListener.java:76)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
Name and version of the database you are using:
Ingres 2.6
The generated SQL (show_sql=true):
Nothing generated
Debug level Hibernate log excerpt:
I have tested the connectivity to the database using other simple hibernate tests and they worked fine
The java files are as follows
package com.sungard.octagon.maintenance;
// Generated Mar 22, 2006 1:45:36 PM by Hibernate Tools 3.1.0 beta3
import java.sql.Timestamp;
/**
* Dictionary generated by hbm2java
*/
public class Dictionary implements java.io.Serializable {
// Fields
private DictionaryPK comp_id;
private String codeDesc;
private String subDesc;
private String updateUser;
private Timestamp updateDate;
// Constructors
/** default constructor */
public Dictionary() {
}
/** full constructor */
public Dictionary(DictionaryPK comp_id, String codeDesc, String subDesc, Str
ing updateUser, Timestamp updateDate) {
this.comp_id = comp_id;
this.codeDesc = codeDesc;
this.subDesc = subDesc;
this.updateUser = updateUser;
this.updateDate = updateDate;
}
// Property accessors
public DictionaryPK getComp_id() {
return this.comp_id;
}
public void setComp_id(DictionaryPK comp_id) {
this.comp_id = comp_id;
}
public String getDictCode() {
return this.comp_id.getDictCode();
}
public void setDictCode(String dictCode) {
this.comp_id.setDictCode(dictCode);
}
public String getSubCode() {
return this.comp_id.getSubCode();
}
public void setSubCode(String subCode) {
this.comp_id.setSubCode(subCode);
}
public String getCodeDesc() {
return this.codeDesc;
}
public void setCodeDesc(String codeDesc) {
this.codeDesc = codeDesc;
}
public String getSubDesc() {
return this.subDesc;
}
public void setSubDesc(String subDesc) {
this.subDesc = subDesc;
}
public String getUpdateUser() {
return this.updateUser;
}
public void setUpdateUser(String updateUser) {
this.updateUser = updateUser;
}
public Timestamp getUpdateDate() {
return this.updateDate;
}
public void setUpdateDate(Timestamp updateDate) {
this.updateDate = updateDate;
}
package com.sungard.octagon.maintenance;
// Generated Mar 22, 2006 1:45:38 PM by Hibernate Tools 3.1.0 beta3
/**
* DictionaryPK generated by hbm2java
*/
public class DictionaryPK implements java.io.Serializable {
// Fields
private String DictCode;
private String SubCode;
// Constructors
/** default constructor */
public DictionaryPK() {
}
/** full constructor */
public DictionaryPK(String dictCode, String subCode) {
System.out.println("In DictionaryPK");
this.DictCode = dictCode;
this.SubCode = subCode;
System.out.println("After DictionaryPK");
}
// Property accessors
public String getDictCode() {
return this.DictCode;
}
public void setDictCode(String dictCode) {
this.DictCode = dictCode;
}
public String getSubCode() {
return this.SubCode;
}
public void setSubCode(String subCode) {
this.SubCode = subCode;
}
public boolean equals(Object other) {
if(this == other)
return true;
if ( !(other instanceof DictionaryPK) ) return false;
DictionaryPK castOther = (DictionaryPK) other;
if(this.getDictCode().equals(castOther.getDictCode()) &&
this.getSubCode().equals(castOther.getSubCode()))
return true;
return false;
}
public int hashCode() {
return (getDictCode() + getSubCode())
.hashCode();
}
}