In summary this thread is about whether <dynamic-class> should be tied to use Map. This may be a bit long, but please bare with me.

I started a thread on the forums (http://forum.hibernate.org/viewtopic.php?t=933984&highlight=), but after thinking about it thought it was better suited for this list. Once a consensus is made, a post to the forum, FAQ, or docs can be made.

Gavin, you said that I am one of the first people to use Hibernate in such a way, ie (custom persistent object), so I feel it's important to get all of the committer's feedback on this issue.


Background: We are using a custom persistent object that is neither a Map or a POJO.

Description of our custom persistent object (http://meta-jb.sourceforge.net/)
"Meta-JB extends the Java Beans concept providing more generic access to object attributes and descriptions. The descriptions of a class's properties (the MetaClass) and access to an object's attributes are decoupled from actual implementations by adapters implementing a Map-like name/value interface (the MetaObject). Because the thin framework is built on generic interfaces, it is not tied directly to real Java bean implementations and can also be used for anything that can access values by name. (Some examples might be SQL result sets, HTTP request data, or simple hash maps.) Once a "class" has been described, the information can even be applied to different underlying implementations."


In our case the underlying storage mechanism is actually a map, but that is not exposed by the object. I was able to successfully get a MetaObject to be saved and loaded using Hibernate using the following 3 classes:

MetaObjectInterceptor.java
MetaObjectAccessor.java
SimpleMetaObjectPersister.java

http://cvs.sourceforge.net/viewcvs.py/meta-jb/dev/src/java/org/progeeks/meta/hibernate/

The interceptor was used to create the actual metaobject. The accessor was used to get/set the values on the created object. I created the SimpleMetaObjectPersister yesterday after finding that finding that I needed to override EntityPersister.isInstance(Object) for loading instances that were already found in the session cache.

For now I have been using the dynamic-class mapping:

<dynamic-class entity-name="person" table="person" persister="org.progeeks.meta.hibernate.SimpleMetaObjectPersister" >
<cache usage="read-only" />


<id name="id" column="id" type="long" unsaved-value="0" access="org.progeeks.meta.hibernate.MetaObjectAccessor">
<generator class="native">
<param name="sequence">person_seq</param>
</generator>
</id>


        <property name="firstName"
            column="first_name"
            type="string"
            length="50"
            insert="true"
            update="true"
            access="org.progeeks.meta.hibernate.MetaObjectAccessor"/>
</dynamic-class>

This works well, but Gavin states that <dynamic-class> assumes an underlying map. From my research and digging through the code, <class> assumes that there is a POJO and uses reflection, hence my decision to override the use of <dynamic-class>. I could be wrong about this assumption! If I declare the mapping to use <class> i will get a ClassNotFoundException:

Exception in thread "main" org.hibernate.MappingException: entity class not found: person
at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:145)
at org.hibernate.persister.AbstractEntityPersister.<init>(AbstractEntityPersister.java:575)
at org.hibernate.persister.BasicEntityPersister.<init>(BasicEntityPersister.java:304)
at org.hibernate.persister.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java
:108)
at org.progeeks.meta.hibernate.SimpleMetaObjectPersister.<init>(SimpleMetaObjectPersister.ja
va:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.hibernate.persister.PersisterFactory.create(PersisterFactory.java:82)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:53)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:169)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:914)


If there are any other things I can do in order to hook into the Hibernate framework, please let me know. If you need any clarification about the framework that I am using for the persisten objects, please please ask!

Thanks for all of the hard work you guys (and gals?) have put into Hibernate.
-Matt


--
======== mailto:[EMAIL PROTECTED] ============

Matt Veitas
Software Developer

Object Sciences Corporation
6359 Walker Lane, Suite 100
Alexandria, VA 22310
voice:   +1.703.253.1104
cell:    +1.571.437.9654

========== http://www.objectsciences.com/ ============


------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel

Reply via email to