users@jaxb.java.net

JAXB and Hibernate

From: Aleksei Valikov <valikov_at_gmx.net>
Date: Tue, 13 Apr 2004 10:46:16 +0200

Hi.

I guess you've heard about Hibernate - it is a O/R persistence service for Java.
Basically, Hibernate is capable of "storing" Java objects in RDBs. In order to
do it, Hibernate requires a formal definition of O/R mapping. This mapping is
usually defined in an external XML file. However, it could be also defined in
the source code of Java classes themselves using XDoclet mechanism.

Our idea was that if JAXB implementation includes appropriate Hibernate doclets
in the generated Java code, then objects generated by JAXB will be directly
persistable in a relational database.

In the last few weeks we have developed a prototype (based on the Sun's xjc)
that supports generation of the Hibernate doclets in resulting classes.
Generated classes look approximately as follows:

package de.baw.nokis.impl;


/**
  * @hibernate.class
  *
  */
public class ContactImpl implements de.baw.nokis.Contact,
com.sun.xml.bind.JAXBObject, de.baw.nokis.impl.runtime.UnmarshallableObject,
de.baw.nokis.impl.runtime.XMLSerializable,
de.baw.nokis.impl.runtime.ValidatableObject
{
   // ...
     /**
      * @hibernate.property
      *
      */
     public java.lang.String getAdminArea() {
         return _AdminArea;
     }
   // ...
     /**
      * @hibernate.list cascade="all"
      * @hibernate.collection-key column="ContactImpl_id"
      * @hibernate.collection-index column="index"
      * @hibernate.collection-one-to-many class="de.baw.nokis.impl.OnLineResImpl"
      *
      */
     public java.util.List getCntOnlineRes() {
         return _CntOnlineRes;
     }
     /**
      * @hibernate.list cascade="all"
      * @hibernate.collection-key column="ContactImpl_id"
      * @hibernate.collection-index column="index"
      * @hibernate.collection-element column="value" type="java.lang.String"
      *
      */
     public java.util.List getEMailAdd() {
         return _EMailAdd;
     }


     /**
      * @hibernate.property
      *
      */
     public java.lang.String getPostCode() {
         return _PostCode;
     }
    //...
}

The same approach could be used for generating JDO doclets.

I believe that approach with making JAXB object RDB-persistable automatically is
quite valuable. This might be a very useful extension to JAXB.
Therefore I would like to ask JAXB RI authors if this sounds interesting and, if
yes, what would be the process to implement this idea as a JAXB extension.

-- 
Dr. Aleksei Valikov (RUS)
Wissenschaftlicher Mitarbeiter
Forschungszentrum Informatik
Haid-und-Neu Str. 10-14
76131 Karlsruhe, Deutschland
Tel: +49-721-9654716
Fax: +49-721-9654717
E-mail: valikov_at_fzi.de
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
For additional commands, e-mail: users-help_at_jaxb.dev.java.net