-->
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: IllegalArgumentException occurred calling getter
PostPosted: Thu Apr 20, 2006 5:17 am 
Newbie

Joined: Wed Apr 19, 2006 12:27 pm
Posts: 2
Hi,

i see this thread that is looks like my problem but it seems not.

And this code works with hibernate annotations beta6
and hibernate version 3.1 rc1

No change have been made on this part of code.

Hibernate version:

Hibernate 3.2cr1
annotation 3.1 beta 9

Mapping documents:

Code:
public class Produit {
(...)
    @ManyToOne(fetch = FetchType.LAZY )
    @JoinColumn(name = "destination")
    public Destination getDestination() {
        return destination;
    }
(...)
}


Code:
public class Destination {
    @Id
    @Column(name = "destination_id")
    public long getId() {
       return destination_id;
    }   

    public void setId(long destination_id) {
       this.destination_id = destination_id;
    }

(...)
}


Code between sessionFactory.openSession() and session.close():

Code:
      List listProduit = s
            .createQuery(
                  " from Produit where disponibleseul = 'TRUE' and destination = ?  ")
            .setParameter(0,((Destination) listDes.get(nDes)).getId())
            .list();


Exception happen on .list().

Full stack trace of any exception that occurs:


Code:
10:10:23,500 ERROR BasicPropertyAccessor:167 - IllegalArgumentException in class: (...).produit.destination.Destination, getter method of property: id
Exception in thread "main" org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of (...)..produit.destination.Destination.id
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
   at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
   at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3368)
   at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:3084)
   at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
   at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:215)
   at org.hibernate.type.EntityType.getIdentifier(EntityType.java:108)
   at org.hibernate.type.ManyToOneType.nullSafeSet(ManyToOneType.java:77)
   at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
   at org.hibernate.loader.Loader.doQuery(Loader.java:661)
   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
   at org.hibernate.loader.Loader.doList(Loader.java:2145)
   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
   at org.hibernate.loader.Loader.list(Loader.java:2024)
   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
   at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
   at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
   at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1109)
   at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
   at (...).main(GenerationPanier.java:480)
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(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:145)
   ... 20 more


Name and version of the database you are using:

Posgresql 8.0

Others comments

Exception happen on .list().
I execute the program in debug mode and i saw that hibernate invoke() the getid() method with a parameter of type long and value of the good destination id.


Is more tags is needed now for a ManyToOne relation ?
Is this a bug ?


Many thanks
Igor Devor


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 5:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Yes, it's a bug in your code. Your mapping says that the destination attribute of Produit is of type Destination, but in your query you're checking it against an object of type Long. Hence the exception. Drop the "getId()" part in the setParameter method call.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 21, 2006 4:05 am 
Newbie

Joined: Wed Apr 19, 2006 12:27 pm
Posts: 2
Thanks for your help, that work.

Yesterday, i came back to hibernate annotations beta6 and hibernate version 3.1 rc1, to be sur that i am not become crazy.
And that's work too.

I have spend last 3 days to search why it did not work.
I read changelog many time, and i can't find where it is written that we do not need to called the getid anymore on setParameter (or something on this subject).

How can we avoid that next time ?


Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 23, 2006 5:31 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Nothing has changed here. You never would have put the getId() in that sort of place before. There's nothing that can be done to avoid that wasted time beyond reading the ref docs.


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.