From: <leg...@at...> - 2003-08-15 10:11:58
|
The following comment has been added to this issue: Author: Florian H=C3=BCbner Created: Fri, 15 Aug 2003 4:54 AM Body: Hmmm, forgot to tell you that I now tested whith all types and it works fin= e, so maybe this is all u got to path...=20 --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?= key=3DHB-261 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-261 Summary: Problems with the increment-generator using int or short as id= entifier Type: Bug Status: Unassigned Priority: Major Project: Hibernate2 Versions: 2.0.2 Assignee:=20 Reporter: Florian H=C3=BCbner Created: Fri, 15 Aug 2003 4:50 AM Updated: Fri, 15 Aug 2003 4:50 AM Environment: Java: 1.4.1_01, Oracle9 Description: As I use integer-type primary keys in the db I wanted to use the increment-= generator to keep them unique. While trying to dump a test-object to the db, I got the following error: 15.08.2003 11:32:26 net.sf.hibernate.util.ReflectHelper$Setter set SCHWERWIEGEND: IllegalArgumentException in class: de.fzi.dbs.cwb.Customer, = setter method of property: cid 15.08.2003 11:32:26 net.sf.hibernate.util.ReflectHelper$Setter set SCHWERWIEGEND: expected type: int, actual value: java.lang.Long net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred= while calling: argument type mismatch setter of de.fzi.dbs.cwb.Customer.ci= d java.lang.IllegalArgumentException: argument type mismatch =09at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) =09at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.= java:39) =09at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces= sorImpl.java:25) =09at java.lang.reflect.Method.invoke(Method.java:324) =09at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45) =09at net.sf.hibernate.persister.AbstractEntityPersister.setIdentifier(Abst= ractEntityPersister.java:251) =09at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:674) =09at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605) =09(...) rethrown as net.sf.hibernate.PropertyAccessException: IllegalArgumentExcept= ion occurred while calling: argument type mismatch setter of de.fzi.dbs.cwb= .Customer.cid =09at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:71) =09at net.sf.hibernate.persister.AbstractEntityPersister.setIdentifier(Abst= ractEntityPersister.java:251) =09at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:674) =09at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:605) =09at de.fzi.dbs.cwb.test.test.main(test.java:56) Caused by: java.lang.IllegalArgumentException: argument type mismatch =09at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) =09at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.= java:39) =09at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces= sorImpl.java:25) =09at java.lang.reflect.Method.invoke(Method.java:324) =09at net.sf.hibernate.util.ReflectHelper$Setter.set(ReflectHelper.java:45) =09... 4 more While debugging, I figured out, that the class' generator method returns "n= ew Long(next++)" in any case - which causes the type-mismatch while trying = to set the cid (customer id in my example).=20 My solution to this is adding the following to generate-method in=20 net.sf.hibernate.id.IncrementGenerator: =09public synchronized Serializable generate(SessionImplementor session, Ob= ject object) =09=09throws SQLException, HibernateException { =09=09=09 =09=09if (sql!=3Dnull) { =09=09=09getNext( session.connection() ); =09=09} // added code: // determine the return type via SessionImplementor =09=09Type identifierType =3D session.getPersister(object).getIdentifierTyp= e(); =09=09if (identifierType instanceof net.sf.hibernate.type.IntegerType) { =09=09=09return new Integer((int)next++); =09=09} else if (identifierType instanceof net.sf.hibernate.type.ShortType)= { =09=09=09return new Short((short)next++); =09=09} else { =09=09=09return new Long(next++); =09=09} =09=09 =09} --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators= .jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |