i'm a total newbie but i've managed to puzzle out (or Google) the answer to most questions i've had in the last two months. But this one has me stumped
i have a class that has a property of type Object. Is there any way to map this or do i need to rewrite my class?
Having searched for this already, i know someone will object "why are you using an object?". Aside from the fact that the Hibernate 3 docs say it's a valid type, it's because i'm saving a property bag (hash of name/value pairings) for a search screen where the value portion can be int, float, string, bool or date, so i store them all as Object
i've tried a dozen ways of mapping this and have spent 8 hours now RTFM and Googling with no luck. Most recently, i'm getting the unintelligble (to me) message:
"property mapping has wrong number of columns: com.pao.SearchCriterion.value type: object"
i'm looking for any way to map a name/value pair collection of type String/Object
Hibernate version: 3
Mapping documents:
Code:
<hibernate-mapping package="com.pao" >
<class name="com.pao.SearchCriterion" table="adoptioncriteria">
<id name="id" column="hibernateID">
<generator class="increment"/>
</id>
<property name="adoptionApplicationID" />
<property name="name" column="attribute" />
<property name="value" type="object" />
<property name="weight" />
<property name="dataType" column="datatype" />
</class>
</hibernate-mapping>
The above are an int, String, Object, int, String (char(1))
Full stack trace of any exception that occurs:For this particular error on this particular mapping file (and i've done this a lot of different ways), it's
Code:
org.hibernate.MappingException: property mapping has wrong number of columns: com.pao.SearchCriterion.value type: object
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:326)
at org.hibernate.mapping.RootClass.validate(RootClass.java:188)
at org.hibernate.cfg.Configuration.validate(Configuration.java:839)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1000)
at com.pao.HibernateUtil.getHibernateSession(HibernateUtil.java:56)
at com.pao.HibernateUtil.executeQuery(HibernateUtil.java:30)
at com.pao.test.AdoptionApplicationManagerTest.testGetAdoptionApplication(AdoptionApplicationManagerTest.java:51)
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:585)
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:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Name and version of the database you are using:mySQL 4
If anyone has an idea on how to do this, that'd be great. Otherwise i have to either rewrite the entire search engine (this is loading saved searches) or write some kind of mapping interface to map whatever Hibernate can save to what the search engine needs
Note that i did try changing Object to String but that doesn't work as well as i expected. Specifically,
Code:
new Integer.parse(myInt.toString())
works but
Code:
new Date(myDate.toString())
oddly does not
-baylor, super n00b