I have the following domain object with overloaded setter methods.
Code:
public class Customer extends AbstractCustomerValue {
...
public void setKey(UUID key) {
this.key = key.toString();
}
public void setKey(String key) {
this.key = key
}
}
public abstract class AbstractCustomerValue {
...
protected String key;
...
}
When I try to load this object from the database, I get the following error. However when I interchange the setters as below it works fine
Code:
public class Customer extends AbstractCustomerValue {
...
public void setKey(String key) {
this.key = key;
}
public void setKey(UUID key) {
this.key = key.toString();
}
}
CustomerHome:
Code:
....
public Customer findById(java.lang.String id) {
log.debug("getting Customer instance with id: " + id);
try {
Session session = sessionFactory.getCurrentSession();
session.beginTransaction();
Customer instance = (Customer) session
.get("com.xyz.coherence.model.Customer", id);
if (instance == null) {
log.debug("get successful, no instance found");
} else {
log.debug("get successful, instance found");
}
session.close();
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
..........
ERROR:
4781 [main] ERROR org.hibernate.property.BasicPropertyAccessor - IllegalArgumentException in class: com.xyz.coherence.model.Customer, setter method of property: key
4781 [main] ERROR org.hibernate.property.BasicPropertyAccessor - expected type: java.util.UUID, actual value: java.lang.String
4781 [main] INFO org.hibernate.event.def.DefaultLoadEventListener - Error performing load command
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xyz.coherence.model.Customer.key
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:227)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:368)
at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3620)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1303)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1292)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1323)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1885)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy0.get(Unknown Source)
at com.xyz.jpa.CustomerHome.findById(CustomerHome.java:101)
at com.xyz.jpa.CustomerHome.main(CustomerHome.java:150)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)
... 29 more
Mar 17, 2010 6:45:18 PM com.xyz.jpa.CustomerHome findById
SEVERE: get failed
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of com.xyz.coherence.model.Customer.key
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:128)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.setIdentifier(AbstractEntityTuplizer.java:227)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:368)
at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:3620)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1303)
at org.hibernate.impl.SessionImpl.instantiate(SessionImpl.java:1292)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1323)
at org.hibernate.loader.Loader.getRow(Loader.java:1230)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:603)
at org.hibernate.loader.Loader.doQuery(Loader.java:724)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1885)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:71)
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:65)
at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3062)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:434)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:415)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:165)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:223)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:126)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:906)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:843)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy0.get(Unknown Source)
at com.xyz.jpa.CustomerHome.findById(CustomerHome.java:101)
at com.xyz.jpa.CustomerHome.main(CustomerHome.java:150)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:66)
... 29 more
HBM:
Code:
<hibernate-mapping>
<class name="com.xyz.coherence.model.Customer" table="customer" catalog="xyz">
<id name="key" type="string">
<column name="CUSTOMERID" length="30" />
<generator class="assigned" />
</id>
<property name="firstName" type="string">
<column name="FIRSTNAME" length="200" />
</property>
<property name="middleName" type="string">
<column name="MIDDLENAME" length="200" />
</property>
<property name="lastName" type="string">
<column name="LASTNAME" length="200" />
</property>
<property name="source" type="string">
<column name="SOURCE" length="50" />
</property>
</class>
</hibernate-mapping>
Does the order of the setters matter while I load the object from the database?