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