Hi.
I installed hibernate, created standalone and servlet demo programs and everything worked fine. Now I'm trying to run my classes under junit and I get strange exception. The mapping and the Java class seem to be correct. Could this be some kind of problem related to running the code in different environment (maybe I omitted some class from classpath?)? I looked at Hibernate code and didn't see anything terribly wrong. Any hints are appreciated.
The exception looks like this:
Code:
IllegalArgumentException occurred calling getter of ee.pria.marsa.entity.example.DBExampleDog.id
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of ee.pria.marsa.entity.example.DBExampleDog.id
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:111)
at net.sf.hibernate.persister.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:310)
at net.sf.hibernate.proxy.HibernateProxyHelper.getIdentifier(HibernateProxyHelper.java:50)
at net.sf.hibernate.type.EntityType.toString(EntityType.java:84)
at net.sf.hibernate.type.PersistentCollectionType.toString(PersistentCollectionType.java:81)
at net.sf.hibernate.impl.Printer.toString(Printer.java:49)
at net.sf.hibernate.impl.Printer.toString(Printer.java:82)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2228)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1732)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3436)
at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:177)
at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:322)
at ee.pria.marsa.model.example.ExampleOwner.findByName(Unknown Source)
at ee.pria.marsa.model.example.DogAndOwnerTest.doFinders(Unknown Source)
at ee.pria.marsa.model.example.DogAndOwnerTest.testDogAndOwner(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
Caused by: java.lang.IllegalArgumentException: java.lang.ClassCastException@ebcdbb
at sun.reflect.GeneratedMethodAccessor7.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:97)
... 28 more
The mapping file for the dog class is:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="ee.pria.marsa.entity.example.DBExampleDog" table="example_dog">
<id name="id" type="long">
<generator class="native"/>
</id>
<property name="name" type="string" length="50">
<meta attribute="finder-method">findByName</meta>
<column name="`name`" length="50"/>
</property>
<many-to-one name="owner" class="ee.pria.marsa.entity.example.DBExampleOwner" column="owner_id"/>
<!-- timestamp column="last_modified" name="lastModified"/ -->
<component name="collar" class="ee.pria.marsa.entity.example.DBExampleDogCollar">
<property name="size" type="integer">
<column name="`size`"/>
</property>
<property name="colour" type="string" length="50"/>
</component>
</class>
</hibernate-mapping>
The DBExampleDog.java is automatically generated from the mapping file:
Code:
/** @author Hibernate CodeGenerator */
public class DBExampleDog implements Serializable {
/** identifier field */
private Long id;
/** nullable persistent field */
private String name;
/** nullable persistent field */
private ee.pria.marsa.entity.example.DBExampleOwner owner;
/** persistent field */
private ee.pria.marsa.entity.example.DBExampleDogCollar collar;
/** full constructor */
public DBExampleDog(String name, ee.pria.marsa.entity.example.DBExampleOwner owner, ee.pria.marsa.entity.example.DBExampleDogCollar collar) {
this.name = name;
this.owner = owner;
this.collar = collar;
}
/** default constructor */
public DBExampleDog() {
}
/** minimal constructor */
public DBExampleDog(ee.pria.marsa.entity.example.DBExampleDogCollar collar) {
this.collar = collar;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
...