-->
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.  [ 9 posts ] 
Author Message
 Post subject: Should I use XDoclet with Hibernate 2?
PostPosted: Wed Nov 12, 2003 6:05 am 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
In my project, I use xdoclet to generate hbm.xml files from java bean objects, but I found the xdoclet for hibernate is very mess, I have some problems as following:
(1) xdoclet supports hibernate 1.X only, many features of hibernate can not use!
(2) can not support multi-columns of collection's key element!
(3) can not support foreign property of ID generator!
(4) maybe not support using column element?
(5) and so on...

but how can i continue my project? re-work from beginning? could you please help me!!!


Top
 Profile  
 
 Post subject: We Are Using Hibernate and XDoclet
PostPosted: Wed Nov 12, 2003 3:38 pm 
Newbie

Joined: Fri Nov 07, 2003 6:57 pm
Posts: 1
Location: GA
We're using Hibernate 2.1b6 with XDoclet (built from CVS) and it works great. I ran into the multi-column collection key problem, but I changed hibernate-collections.xdt to handle multiple @hibernate.collection-key elements. I've included a patch below to make this change, I don't know what's going to happen with line wrapping, so be careful if you use it. This change works just fine for single column and multiple column. Again, this patch is again hibernate-collections.xdt. Once you patch it, you have to rebuild XDoclet, or at least replace this file in xdoclet-hibernate-module-1.2b3.jar

23,28c23,27
< <key
< column="<XDtMethod:methodTagValue tagName="hibernate.collection-key" paramName="column" />"
< <XDtMethod:ifHasMethodTag tagName="hibernate.collection-key" paramName="length">
< length="<XDtMethod:methodTagValue tagName="hibernate.collection-key" paramName="length" />"
< </XDtMethod:ifHasMethodTag>
< />
---
> <key>
> <XDtMethod:forAllMethodTags tagName="hibernate.collection-key">
> <column name="<XDtMethod:methodTagValue tagName="hibernate.collection-key" paramName="column" />"/>
> </XDtMethod:forAllMethodTags>
> </key>
93c92
<
\ No newline at end of file
---
>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 7:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Could you submit your fixes and problem to the XDoclet JIRA. I am not sure who is active but these should be recorded. A large percentage of used do use Xdoclet (and top-to-bottom development) as the primary development approach. I would like to see this area maintained and improved.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 10:29 pm 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
I have three tables like following:

Code:
-------------ClassA.hbm.xml-----------------------
<?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>
  <class name="ClassA" table="TableA" dynamic-update="false" dynamic-insert="false">
 
    <id column="ID" type="string" length="8">
      <generator class="assigned" />
    </id>
   
    <property name="cola1" type="string" update="true" insert="true" column="ColA1" length="20"/>
    <property name="cola2" type="string" update="true" insert="true" column="ColA2" length="20"/>
   
    <one-to-one name="a-b" class="ClassB" cascade="save-update" outer-join="false" constrained="true"/>
    <one-to-one name="a-c" class="ClassC" cascade="save-update" outer-join="false" constrained="true"/>
  </class>
</hibernate-mapping>



-------------ClassB.hbm.xml-----------------------
<?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>
  <class name="ClassB" table="TableB" dynamic-update="false" dynamic-insert="false">
    <id column="ID" type="string" length="8">
      <generator class="foreign">
        <param name="property">terminal</param>
      </generator>
    </id>
   
    <one-to-one name="terminal" class="ClassA" constrained="true" outer-join="auto" />
   
    <property name="colb1" type="string" length="20" update="true" insert="true" column="ColB1"/>
  </class>
</hibernate-mapping>



-------------ClassC.hbm.xml-----------------------
<?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>
  <class name="ClassC" table="TableC" dynamic-update="false" dynamic-insert="false">
    <id column="ID" type="string" length="8">
      <generator class="foreign">
        <param name="property">terminal</param>
      </generator>
    </id>
   
    <one-to-one name="terminal" class="ClassA" constrained="true" outer-join="auto" />
   
    <property name="colc1" type="string" length="20" update="true" insert="true" column="ColC1"/>
  </class>
</hibernate-mapping>


I want two one-to-one relations from TableA to TableB and from TableA and TableC, and the TableA is parent of TableB and TableC.

When I use SchemaExport to generate database schema from these xml files, the relationship is wrong, like following:
Code:
alter table TableB add constraint FK40D42F9928CEC8B7 foreign key (ID) references TableA;
alter table TableC add constraint FK256DA2AC28CEC8B7 foreign key (ID) references TableA;
alter table TableA add constraint FKEAF0462728CEC8B7 foreign key (ID) references TableC;
--the third line should not be generated!


when i write one-to-one mapping from tableA to tableC before tableA to tableB in ClassA.hbm.xml, the error is tableB.

what is wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 10:58 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use constrained="false" if you don't want a constraint on a <one-to-one>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2003 11:08 pm 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
Sorry, I made a mistake, i should not set constrained="true" at the hand of ClassA.

But, how can write this relation with XDOCLET?

sorry again and thanks a lot!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 8:54 am 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
jzhuo wrote:
Sorry, I made a mistake, i should not set constrained="true" at the hand of ClassA.

But, how can write this relation with XDOCLET?

sorry again and thanks a lot!


OK, I find the methods to solve these two problems:
(1) to foreign generator class, I find a undocumented paramater named "hibernate.generator-param" that can define the "prperty" param of foreign generator-class.
(2) to multi-column element of key, I try to modify the hibernate-collections.xdt file in xdoclet-hibernate-module-1.2b4.jar as following:
before modified:
Code:
          <XDtMethod:ifHasMethodTag tagName="hibernate.collection-key">
              <key
                <XDtHibernate:setCurrentTag name="hibernate.collection-key" mappingElement="key">
                  <XDtMerge:merge file="xdoclet/modules/hibernate/resources/hibernate-column.xdt">
                  </XDtMerge:merge>
                </XDtHibernate:setCurrentTag>
          </XDtMethod:ifHasMethodTag>


after modified:
Code:
          <XDtMethod:ifHasMethodTag tagName="hibernate.collection-key">
              <key
                <XDtConfig:ifConfigParamEquals paramName="version" value="2.0">
                  <XDtMethod:ifHasMethodTag tagName="hibernate.collection-key" paramName="foreign-key">
                    foreign-key="<XDtMethod:methodTagValue tagName="hibernate.collection-key" paramName="foreign-key" />"
                  </XDtMethod:ifHasMethodTag>
                </XDtConfig:ifConfigParamEquals>
                <XDtConfig:ifConfigParamEquals paramName="version" value="1.1">
                  <XDtMethod:ifHasMethodTag tagName="hibernate.collection-key" paramName="length">
                    length="<XDtMethod:methodTagValue tagName="hibernate.collection-key" paramName="length"/>"
                  </XDtMethod:ifHasMethodTag>
                </XDtConfig:ifConfigParamEquals>
                <XDtHibernate:setCurrentTag name="hibernate.collection-key" mappingElement="key">
                  <XDtMerge:merge file="xdoclet/modules/hibernate/resources/hibernate-column.xdt">
                  </XDtMerge:merge>
                </XDtHibernate:setCurrentTag>
          </XDtMethod:ifHasMethodTag>


David, is it OK? can you help me check the synax?thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I am not an expert in XDoclet templete language. Having said that I assume you tested it and it works for you - then great. Now joeyGibson showed his changes that uses a loop construct to allow multiple keys (which is required) so review his changes and integrate them. Then send it to XDoclet JIRA for inclusion into the XDoclet code base. I do not know who is maintaining the XDoclet tags for hibernate at this point. I am sure someone is I just don't know who is.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 11:45 pm 
Beginner
Beginner

Joined: Fri Sep 26, 2003 2:50 am
Posts: 32
OK, thanks!


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