I have one table (TEST). For this table I have two classes, one with all data from the table (Test_S), one with the associations (Test_E) (at the moment there is no association) and a one-to-one-Association to the data. The Problem is, I can create instances of Test_E and save them, but I can't get them from the database. Then I get an exception.
Hibernate version:
Current CVS Version
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>
<class name="objects.Test_E" table="TEST" discriminator-value="Test">
<meta attribute="use-in-equals">true</meta>
<composite-id>
<key-many-to-one name="data" class="objects.Test_S">
<column name="ID"/>
<column name="CLASS_TYPE"/>
</key-many-to-one>
</composite-id>
<discriminator column="CLASS_TYPE" type="string" length="32" insert="false"/>
</class>
<class name="objects.Test_S" table="TEST" discriminator-value="Test">
<meta attribute="use-in-equals">true</meta>
<composite-id name="key"
class="key.BigDecimalClasstype">
<key-property name="id" type="big_decimal" column="ID"/>
<key-property name="classtype" type="string" length="32" column="CLASS_TYPE"/>
</composite-id>
<discriminator column="CLASS_TYPE" type="string" length="32" insert="false"/>
<property name="code" column="CODE" type="string" length="3"/>
<property name="bezeichnung" column="BEZEICHNUNG" type="string" length="100"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
GeneratorBigDecimalSequenceClasstypeHibernate generator = new GeneratorBigDecimalSequenceClasstypeHibernate("seq", session);
Test_E e;
Test_S s;
s = (Test_S)session.get(Test_S.class, new BigDecimalClasstype(new java.math.BigDecimal(1), "Test")); //works
e = (Test_E)session.get(Test_E.class, new BigDecimalClasstype(new java.math.BigDecimal(1), "Test")); //didn't work
Class Code (generated by hbm2java, comments removed):
package objects;
public class Test_E implements java.io.Serializable {
private Test_S data;
public Test_E() {
}
public Test_S getData() {
return this.data;
}
public void setData(Test_S data) {
this.data = data;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof Test_E) ) return false;
Test_E castOther = ( Test_E ) other;
return (this.getData()==castOther.getData()) || ( this.getData()!=null && castOther.getData()!=null && this.getData().equals(castOther.getData()) );
}
public int hashCode() {
int result = 17;
result = 37 * result + this.getData().hashCode();
return result;
}
}
package objects;
public class Test_S implements java.io.Serializable {
private key.BigDecimalClasstype key;
private String code;
private String bezeichnung;
public Test_S() {
}
public Test_S(key.BigDecimalClasstype key) {
this.key = key;
}
public key.BigDecimalClasstype getKey() {
return this.key;
}
public void setKey(key.BigDecimalClasstype key) {
this.key = key;
}
public String getCode() {
return this.code;
}
public void setCode(String code) {
this.code = code;
}
public String getBezeichnung() {
return this.bezeichnung;
}
public void setBezeichnung(String bezeichnung) {
this.bezeichnung = bezeichnung;
}
public boolean equals(Object other) {
if ( (this == other ) ) return true;
if ( (other == null ) ) return false;
if ( !(other instanceof Test_S) ) return false;
Test_S castOther = ( Test_S ) other;
return (this.getKey()==castOther.getKey()) || ( this.getKey()!=null && castOther.getKey()!=null && this.getKey().equals(castOther.getKey()) )
&& (this.getCode()==castOther.getCode()) || ( this.getCode()!=null && castOther.getCode()!=null && this.getCode().equals(castOther.getCode()) )
&& (this.getBezeichnung()==castOther.getBezeichnung()) || ( this.getBezeichnung()!=null && castOther.getBezeichnung()!=null && this.getBezeichnung().equals(castOther.getBezeichnung()) );
}
public int hashCode() {
int result = 17;
result = 37 * result + this.getKey().hashCode();
result = 37 * result + ( getCode() == null ? 0 : this.getCode().hashCode() );
result = 37 * result + ( getBezeichnung() == null ? 0 : this.getBezeichnung().hashCode() );
return result;
}
}
Full stack trace of any exception that occurs:
ERROR - IllegalArgumentException in class: objects.Test_E, getter method of property: data
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of objects.Test_E.data
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:121)
at org.hibernate.tuple.AbstractComponentTuplizer.getPropertyValues(AbstractComponentTuplizer.java:133)
at org.hibernate.tuple.PojoComponentTuplizer.getPropertyValues(PojoComponentTuplizer.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:68)
at org.hibernate.engine.EntityKey.<init>(EntityKey.java:41)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:76)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:774)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:714)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:707)
at test.Test.testTest(Test.java:345)
at test.Test.main(Test.java:38)
Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
... 13 more
Name and version of the database you are using:
Oracle 7.3.3.0.0
The generated SQL (show_sql=true):
select test_s0_.ID as ID0_0_, test_s0_.CLASS_TYPE as CLASS2_0_0_, test_s0_.CODE as CODE0_0_, test_s0_.BEZEICHNUNG as BEZEICHN4_0_0_ from TEST test_s0_ where test_s0_.ID=? and test_s0_.CLASS_TYPE=?
Debug level Hibernate log excerpt:
DEBUG - opening JDBC connection
DEBUG - total checked-out connections: 0
DEBUG - using pooled JDBC connection, pool size: 0
DEBUG - select test_s0_.ID as ID0_0_, test_s0_.CLASS_TYPE as CLASS2_0_0_, test_s0_.CODE as CODE0_0_, test_s0_.BEZEICHNUNG as BEZEICHN4_0_0_ from TEST test_s0_ where test_s0_.ID=? and test_s0_.CLASS_TYPE=?
Hibernate: select test_s0_.ID as ID0_0_, test_s0_.CLASS_TYPE as CLASS2_0_0_, test_s0_.CODE as CODE0_0_, test_s0_.BEZEICHNUNG as BEZEICHN4_0_0_ from TEST test_s0_ where test_s0_.ID=? and test_s0_.CLASS_TYPE=?
DEBUG - preparing statement
DEBUG - binding '1' to parameter: 1
DEBUG - binding 'Test' to parameter: 2
DEBUG - about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG - processing result set
DEBUG - done processing result set (0 rows)
DEBUG - about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG - closing statement
DEBUG - total objects hydrated: 0
DEBUG - initializing non-lazy collections
DEBUG - done entity load
DEBUG - after autocommit
ERROR - IllegalArgumentException in class: objects.Test_E, getter method of property: data
DEBUG - after autocommit
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of objects.Test_E.data
at ...
|