-->
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.  [ 3 posts ] 
Author Message
 Post subject: IllegalArgumentException when running under junit
PostPosted: Thu Jan 29, 2004 9:19 am 
Newbie

Joined: Thu Jan 29, 2004 9:05 am
Posts: 3
Location: Estonia
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;
    }

...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 29, 2004 7:31 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is FAQ and they are here to be read before posting
http://www.hibernate.org/119.html#A3

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 30, 2004 1:37 pm 
Newbie

Joined: Thu Jan 29, 2004 9:05 am
Posts: 3
Location: Estonia
After lot of messing around with JUnit and ant settings, it turned out that the problem was in my test program. :) I managed to put wrong type of items in the hibernate-managed collection. Oops.


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