If a POJO has multiple set() methods for the same property (with different signatures, of course), which one does Hibernate use?
I have set up a mapping and the following works just fine:
Code:
public void setProp(String val) {this.prop = new Prop(val);}
However, I get an Exception when I add a second set method, such as:
Code:
public void setProp(Prop val) {this.prop = val;}
It seems like whenever I have two setters with different signatures for the same property, I get an exception. I have tried various combinations of property types and set methods, and it seems that my basic problem is that two setters on the same property generates an exception.
Is there a way that I can persuade Hibernate to use the correct setter and ignore the others?
Thanks,
Dave
<hr/>
Here is the exception:
org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of dtpitb.businessobjects.invivo.InvivoExperimentPlain.expID
at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:70)
at org.hibernate.tuple.AbstractTuplizer.setPropertyValues(AbstractTuplizer.java:207)
at org.hibernate.tuple.PojoTuplizer.setPropertyValues(PojoTuplizer.java:176)
at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2919)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:530)
at org.hibernate.loader.Loader.doQuery(Loader.java:436)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:218)
at org.hibernate.loader.Loader.doList(Loader.java:1593)
at org.hibernate.loader.Loader.list(Loader.java:1577)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:395)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:271)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:844)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at dtpitb.businessobjects.invivo.InvivoHibernateTestProgram.main(InvivoHibernateTestProgram.java:32)
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 org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:40)
... 14 more
14:45:56,500 ERROR BasicPropertyAccessor:66 - expected type: dtpitb.wrappers.ExpIDInvivo, actual value: java.lang.String
Exception in thread "main"