-->
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.  [ 6 posts ] 
Author Message
 Post subject: XDoclet: Generate a <joined-subclass> for an Interface
PostPosted: Fri Dec 09, 2005 7:18 am 
Newbie

Joined: Fri Dec 09, 2005 6:49 am
Posts: 3
Hi,

I have the following classhierarchy :

(Interface)AdditionalData
/ \
Enquiry Contract

I have generated the hbm.xml file earlier manually and it works :

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
   PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--  This hbm.xml must create by hand, cause there is no xdoclet support for
      joined subclasses, which are interfaces -->
<hibernate-mapping>
  <class name="de.chris.AdditionalData" table="ADDITIONALDATA">
    <id name="id" column="DATA_ID" type="long" unsaved-value="null">   
      <generator class="native"/>
    </id>
    <many-to-one name="person" class="de.chris.Person" column="PERSON_ID"/>
    <joined-subclass name ="de.chris.Enquiry">
      <key column ="id" />
      <property name ="stafferName" column ="STAFFERNAME" type="string"/>
   </joined-subclass>
   <joined-subclass name ="de.chris.Contract">
      <key column ="id" />
      <property name ="price" column ="PRICE" type="long"/>
   </joined-subclass>
  </class>
</hibernate-mapping>


Now I want to migrate my example application to xdoclet. All works fine,
unless the joined subclass was not generated by xdoclet.

Now my question : Is it possible to generate a valid hbm.xml when
I have an implements-dependency, or is it necessary for xdoclet
to have an extends-dependency when I am using the @hibernate.joined-subclass tag ?


thx[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 7:32 am 
Beginner
Beginner

Joined: Tue Jun 07, 2005 11:36 pm
Posts: 22
You can use xdoclet to generate a mapping file like you have shown, but only if all mappings are generated by xdoclet and generated at the same time.

So if you have a library with an entity class and a mapping file that you want to extend, xdoclet won't be able to detect the original mapping file and won't generate the one for the subclass. I believe that the new Hibernate Annottions support can handle such a situation, but I am not familiar enough with those to say how.

What I did in such a situation was have xdoclet generate the base class in my library, and I manually maintained the joined-subclass mapping file, since it only had a few fields. I then used an ant task to copy in an "include" line to the subclasses mapping file in the hibernate.xml.cfg file that xdoclet generated.

_________________
Useful? Hit me with a point! Completely off base? Ya, well, what do you expect from a newbie...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 8:48 am 
Newbie

Joined: Fri Dec 09, 2005 6:49 am
Posts: 3
[quote="esword"]You can use xdoclet to generate a mapping file like you have shown, but only if all mappings are generated by xdoclet and generated at the same time.

Yes that's clear, in former times I write all my hbm.xml files self, now I want do this job by xdoclet. But when I define my interface and my classes :


Code:
/**
* @hibernate.class table="data"
*/
public interface AdditionalData


Code:
[
/**
* @hibernate.joined-subclass table="data"
* @hibernate.joined-subclass-key column="id"
*/
public class Enquiry implements AdditionalData


Now when I run xdoclet generation I get the AdditionalData.hbm.xml
without the subclass definitions from the class Enquiry.

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="de.chris.AdditionalData" table="data">

      <id name="id" column="id" type="java.lang.Long">
         <generator class="native">
            <!-- 
               To add non XDoclet generator parameters, create a file named
               hibernate-generator-params-AdditionalData.xml
               containing the additional parameters and place it in your merge dir.
            -->
         </generator>
      </id>

      <discriminator column="type" />
      <many-to-one name="person" class="de.chris.Person" cascade="none" outer-join="auto" update="true" insert="true" column="PERSON_ID" />
      <!--
         To add non XDoclet property mappings, create a file named
         hibernate-properties-AdditionalData.xml
         containing the additional properties and place it in your merge dir.
      -->
   </class>
</hibernate-mapping>


So I wonder have I make a mistake or will xdoclet force me to implement my interface by an abstract class (e.g. AbstractAdditionalData) to have the possibility to manage my data with through hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 09, 2005 12:30 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 11:36 pm
Posts: 22
I believe you should be able to do it with an interface. I see two things which might be causing the problem:

1) Your joined-subclass should have a different table than your base class. So

Code:
/**
* @hibernate.joined-subclass table="Enquiry_Data"
* @hibernate.joined-subclass-key column="id"
*/


2) I'm not sure this will work, but in one case where I has something similar, I also had an "extends" parameter on the joined-subclass notation:

Code:
hibernate.joined-subclass table="MY_APP_USERS" extends="sample.StandardUser"


This was from an old version of the file that I found, and I'm not sure it worked properly, so no guarantees on that one.[/code]

_________________
Useful? Hit me with a point! Completely off base? Ya, well, what do you expect from a newbie...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 4:17 am 
Newbie

Joined: Fri Dec 09, 2005 6:49 am
Posts: 3
esword wrote:
I believe you should be able to do it with an interface. I see two things which might be causing the problem:

1) Your joined-subclass should have a different table than your base class. So

Code:
/**
* @hibernate.joined-subclass table="Enquiry_Data"
* @hibernate.joined-subclass-key column="id"
*/


Ohh thank you I have make a copy and paste error, cause I've try to do the mapping as a @hibernate.discriminator ... but when I change the table
to "Enquiry_Data" the generated hbm.xml file don't change.


2) I'm not sure this will work, but in one case where I has something similar, I also had an "extends" parameter on the joined-subclass notation:

Code:
hibernate.joined-subclass table="MY_APP_USERS" extends="sample.StandardUser"


This was from an old version of the file that I found, and I'm not sure it worked properly, so no guarantees on that one.[/code]


I have looked to :
http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html#@hibernate_joined-subclass__0__1_
and there was no parameter "extends" and according to this it sadly don't work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 7:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
A heap of work has gone into HIbernate 3 support in XDoclet.
For example http://cvs.sourceforge.net/viewcvs.py/xdoclet/xdoclet/modules/hibernate/src/xdoclet/modules/hibernate/resources/hibernate-joined-subclass.xdt?view=markup

Shows the extends attribute is supported (in the CVS version).


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