-->
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.  [ 2 posts ] 
Author Message
 Post subject: trouble with generated identifiers and custom user types
PostPosted: Mon Sep 20, 2004 7:44 pm 
Beginner
Beginner

Joined: Mon Aug 09, 2004 3:35 pm
Posts: 22
Location: Minneapolis, MN, USA
All my classes use a custom UserType for the ID. This works fine
with assigned identifers, but when I try to use generated identifiers
(uuid.hex) I get an IllegalArgumentException as Hibernate tries to
set the value directly, losing the benefit of the mapping performed
in the custom UserType.

Is my only way around this creating a custom PropertyAccessor?

Have you considered expanding UserType so that it could perform
the same mappings here as it does for result sets and statements?

thanks,

-r


Hibernate version:

2.1.6

Mapping documents:

<?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="com.opi.domain.User"
table="user"
dynamic-update="true"
dynamic-insert="true"
>

<id
name="id"
column="id"
type="com.opi.common.hibernate.IdUserType"
unsaved-value= "null"
>
<generator class="uuid.hex" />
</id>

<version
name="version"
type="int"
column="version"
access="property"
unsaved-value="null"
/>

<property
name="firstName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="firstname"
length="256"
not-null="true"
/>

<property
name="lastName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="lastname"
length="256"
not-null="true"
/>

<property
name="middleName"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="middlename"
length="256"
not-null="false"
/>
</class>
</hibernate-mapping>

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

Full stack trace of any exception that occurs:

com.opi.common.exception.DaoException: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.opi.domain.User.id
at com.opi.common.hibernate.BaseHibernateDao.createObject(BaseHibernateDao.java:45)
at com.opi.domain.UserHibernateDaoImpl.createUser(UserHibernateDaoImpl.java:25)
at com.opi.domain.DomainHibernateDaosTest.testUserDao(DomainHibernateDaosTest.java:26)
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:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Caused by: net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.opi.domain.User.id
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68)
at net.sf.hibernate.persister.AbstractEntityPersister.setIdentifier(AbstractEntityPersister.java:330)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:844)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:779)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at com.opi.common.hibernate.BaseHibernateDao.createObject(BaseHibernateDao.java:41)
... 17 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
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:324)
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
... 22 more


Name and version of the database you are using:

MySQL 4.1.3b

Debug level Hibernate log excerpt:

2004-09-20 18:11:05,878 [] DEBUG SessionImpl -generated identifier: 402828a4ff1e1bb500ff1e1cd2960001
2004-09-20 18:11:05,878 [] DEBUG SessionImpl -saving [com.opi.domain.User#402828a4ff1e1bb500ff1e1cd2960001]
2004-09-20 18:11:05,878 [] ERROR BasicPropertyAccessor -IllegalArgumentException in class: com.opi.domain.User, setter method of property: id
2004-09-20 18:11:05,888 [] ERROR BasicPropertyAccessor -expected type: com.opi.common.Id, actual value: java.lang.String


Top
 Profile  
 
 Post subject: I have the same problem
PostPosted: Tue Jan 17, 2006 10:30 am 
Newbie

Joined: Wed Sep 28, 2005 4:07 am
Posts: 11
I have the same problem.
What was your solution?

_________________
Lars Fiedler


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