-->
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.  [ 3 posts ] 
Author Message
 Post subject: Custom PropertyAccessor not working?
PostPosted: Thu Mar 18, 2004 6:09 am 
Newbie

Joined: Tue Jan 06, 2004 5:52 am
Posts: 17
Location: Belgium
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;
   }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 6:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You need to provide an explicit type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 6:27 am 
Newbie

Joined: Tue Jan 06, 2004 5:52 am
Posts: 17
Location: Belgium
Thank you, now it works. Maybe you should add that do the documentation or make it work without specifing explicitly a type?


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