Hi,
I'm trying to use a custom PropertyAccessor to see how this works, but I don't get it working. It seems that my own PropertyAccessor is not being used at all?
Hibernate version is 2.1.2.
This is the exception I get:
Code:
10:56:27,406 INFO Configuration:329 - Mapping resource: persistence/hibernate/testbench/OwnPropertyTestObject.hbm.xml
10:56:27,984 INFO Binder:229 - Mapping class: persistence.hibernate.testbench.OwnPropertyTestObject -> OwnPropertyTestObject
10:56:28,078 ERROR Configuration:252 - Could not compile the mapping document
net.sf.hibernate.MappingException: Problem trying to set property type by reflection
at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(SimpleValue.java:181)
at net.sf.hibernate.cfg.Binder.createProperty(Binder.java:1044)
at net.sf.hibernate.cfg.Binder.propertiesFromXML(Binder.java:1037)
at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:352)
at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1229)
at net.sf.hibernate.cfg.Configuration.add(Configuration.java:249)
at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:285)
at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:333)
at persistence.hibernate.testbench.HibernateTestCaseUtil.createConfiguration(HibernateTestCaseUtil.java:64)
at persistence.hibernate.testbench.HibernateTestCaseUtil.<init>(HibernateTestCaseUtil.java:29)
at persistence.hibernate.testbench.HibernateTestCaseUtil.getInstance(HibernateTestCaseUtil.java:44)
at persistence.hibernate.testbench.HibernateAwareTest.getCurrentSession(HibernateAwareTest.java:25)
at persistence.hibernate.testbench.OwnPropertyAccessorTest.testStoringAndRetrievingObject(OwnPropertyAccessorTest.java:28)
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 junit.textui.TestRunner.doRun(TestRunner.java:116)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner.main(TextTestRunner.java:12)
Caused by: net.sf.hibernate.PropertyNotFoundException: field not found: name
at net.sf.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:74)
at net.sf.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:80)
at net.sf.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:88)
at net.sf.hibernate.util.ReflectHelper.getter(ReflectHelper.java:65)
at net.sf.hibernate.util.ReflectHelper.reflectedPropertyType(ReflectHelper.java:70)
at net.sf.hibernate.mapping.SimpleValue.setTypeByReflection(SimpleValue.java:170)
... 27 more
This is my mapping document:
Code:
<?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 package="persistence.hibernate.testbench">
<class name="OwnPropertyTestObject">
<id name="id" column="uid" type="long" unsaved-value="-1">
<generator class="native"/>
</id>
<property name="name" access="persistence.hibernate.testbench.KrijgPropertyAccessor"/>
</class>
</hibernate-mapping>
This is my Java class:
Code:
public class OwnPropertyTestObject
{
private Long _id;
private String _name;
public Long getId()
{
return _id;
}
public void setId( Long id )
{
_id = id;
}
public String krijgName()
{
return _name;
}
public void vulInName( String name )
{
_name = name;
}
}