-->
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.  [ 14 posts ] 
Author Message
 Post subject: nicorrect XML being generated - node repeated
PostPosted: Mon May 09, 2005 8:54 am 
Newbie

Joined: Mon May 09, 2005 7:57 am
Posts: 5
hello.
i'm (new to hibernate and) using verion 3.0.1 to generate an XML view of my data in Sybase 12, using jdk1.4.2_04.

it seems to work fairly fine for me (i still have to tweak some mappings), except that i have a type called TaskItem, which has two associations to classes OF THE SAME TYPE: TaskEvent.
one association is called "taskEventByCreateEventId" and the other is called "taskEventByLastEventId". both these names are sniffed from the foreign keys in the database schema, by MiddleGen2.1.

now, when i do a retrieval from the database, the generated XML document correctly retrieves all the data i want, but the TaskItem node (the root node) has two sub-elements called either "taskEventByCreateEventId" or "taskEventByLastEventId". the name depends on which association i have defined second in my TaskItem.hbm descriptor. what i want is one association called "taskEventByCreateEventId" and one called "taskEventByLastEventId".

note that this only happens if i specify the attribute embed-xml="true" FOR BOTH ASSOCIATIONS. if i set embed-xml="false", even for only one of the associations, then the associations (nodes in my XML doc) are named correctly!

and it only happens if the referenced TaskEvents have the same ID.

is there some config which i am neglecting, or some optimisation that is happening that i don't know about?

find below the relevant sections of config files.

many thanks.
donall.

from TaskItem.hbm:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.ebzc.utils.taskpersistence.TaskItem"
    table="TASK_ITEM"
    node="TaskItem"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="TASK_ITEM"
    </meta>

    <!-- bi-directional many-to-one association to TaskEvent -->
    <many-to-one
        name="taskEventByLastEventId"
        class="com.blah.TaskEvent"
        not-null="true"
        embed-xml="true"
    >
        <meta attribute="field-description">
           @hibernate.many-to-one
            not-null="true"
           @hibernate.column name="LAST_EVENT_ID"         
        </meta>
        <column name="LAST_EVENT_ID" />
    </many-to-one>
    <!-- bi-directional many-to-one association to TaskEvent -->
    <many-to-one
        name="taskEventByCreateEventId"
        class="com.blah.TaskEvent"
        not-null="true"
        embed-xml="true"
    >
        <meta attribute="field-description">
           @hibernate.many-to-one
            not-null="true"
           @hibernate.column name="CREATE_EVENT_ID"         
        </meta>
        <column name="CREATE_EVENT_ID" />
    </many-to-one>

</class>
</hibernate-mapping>



from TaskEvent.hbm:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin 2.1

    http://boss.bekk.no/boss/middlegen/
    http://www.hibernate.org/
-->

<class
    name="com.blah.TaskEvent"
    table="TASK_EVENT"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="TASK_EVENT"
    </meta>

    <id
        name="eventId"
        type="java.math.BigDecimal"
        column="EVENT_ID"
    >
        <meta attribute="field-description">
           @hibernate.id
            generator-class="assigned"
            type="java.math.BigDecimal"
            column="EVENT_ID"

        </meta>
        <generator class="assigned" />
    </id>

    <property
        name="eventTimestamp"
        type="java.sql.Timestamp"
        column="EVENT_TIMESTAMP"
        length="23"
    >
        <meta attribute="field-description">
           @hibernate.property
            column="EVENT_TIMESTAMP"
            length="23"
        </meta>   
    </property>

    <!-- Associations -->

</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject: nicorrect XML being generated - repeated node
PostPosted: Mon May 09, 2005 10:00 am 
Newbie

Joined: Mon May 09, 2005 7:57 am
Posts: 5
re: my earlier post, i notice that the POJOs generated from the data are correct, in that the TaskItem POJO has methods called
getTaskEventByCreateEventId()
and
getTaskEventByLastEventId()

so is this a problem with the XML generator?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 9:56 am 
Newbie

Joined: Tue Oct 18, 2005 9:51 am
Posts: 4
I also have this problem and it still occurs using 3.1rc2.

<many-to-one
name="fk1"
class="FKClass"
column="FK1_ID"
fetch="join"
embed-xml="true"
/>

<many-to-one
name="fk2"
class="FKClass"
column="FK2_ID"
fetch="join"
embed-xml="true"
/>

this generates two "fk1" elements instead of a "fk1" and a "fk2" element.


Top
 Profile  
 
 Post subject: Re: nicorrect XML being generated - repeated node
PostPosted: Tue Oct 18, 2005 11:20 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
donall05 wrote:

so is this a problem with the XML generator?


I believe it is a problem with the XML Generator because all objects are of org.dom4j.Element.

I haven't noticed a lot of development on this part in a while but one way I got it to work is to create a second mapping for the associated Class using a different entity-name and specifying that as the entity-name on the many-to-one.

Code:
<class name="FKClass" entity-name="TaskEventByCreateEvent" table="xxx">
...
</class>

<class entity-name="TaskEventByLastEvent" table="xxx" mutable="false">
...
</class>



<many-to-one name="fk1" class="FKClass" column="FK1_ID" fetch="join" embed-xml="true" entity-name="TaskEventByCreateEvent"/>

<many-to-one name="fk2" class="FKClass" column="FK2_ID" fetch="join" embed-xml="true" entity-name="TaskEventByLastEvent"/>

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 12:17 pm 
Newbie

Joined: Tue Oct 18, 2005 9:51 am
Posts: 4
Unfortunately this problem seems to be more entrenched and can't always be solved with that workaround; for example this is the next problem I'm having with Hibernate and XML:

(shortened mapping)
Code:
<class name="Organisation">
  ...
  <many-to-one name="projectLeader" class="Employee" embed-xml="true"/>

  <set name="permits" embed-xml="true">
    <key column="organisation_id"/>
    <one-to-many class="Permit" embed-xml="true"/>
  </set>
</class>

<class name="Employee">
  ... (at least one property besides ID)
</class>

<class name="Permit">
  ...
  <many-to-one name="approver" class="Employee" embed-xml="true"/>
</class>


This generates:

Code:
<Organisation>
  ...
  <projectLeader>
    ...
  </projectLeader>

  <permits>
     <Permit>
       ...
       <projectLeader> <!-- SHOULD BE "approver" -->
         ...
       </projectLeader>
     </Permit>
  </permits>
</Organisation>


Seems like something goes seriously wrong when looking up the element name. Even if I add node="approver" to the many-to-one in Permit the element name in Organisation/permits/Permit will still be the incorrect "projectLeader".


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 1:02 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
My workaround suggest changing your mapping file like this. And it does work. I use it extensively.
Code:
<class name="Organisation">
  ...
  <many-to-one name="projectLeader" class="Employee" embed-xml="true" entity-name="ProjectLeader"/>

  <set name="permits" embed-xml="true">
    <key column="organisation_id"/>
    <one-to-many class="Permit" embed-xml="true"/>
  </set>
</class>

<class name="Employee" entity-name="ProjectLeader">
  ... (at least one property besides ID)
</class>

<class entity-name="Approver" table="Employee">
  ... (at least one property besides ID)
</class>


<class name="Permit">
  ...
  <many-to-one name="approver" class="Employee" embed-xml="true" entity-name="Approver"/>
</class>

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 5:45 am 
Newbie

Joined: Tue Oct 18, 2005 9:51 am
Posts: 4
These workarounds do indeed work, but for my situation the cure is worse than the disease:

I have to map the same table over and over again for every association as an entity with the name I want to give my association as the entity-name(!). This is not feasible for the size of my model (I'll end up with my POJO's drowned in the redundant entities for all assocations). This workaround also breaks my build system using hbm2java which apparently can't handle POJO's and XML entitites simultaneously.

Will this bug be fixed or do I have to switch to Castor?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 9:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
suggestions to how hbm2java could ever handle you mapping the same class twice is welcome ;)

_________________
Max
Don't forget to rate


Last edited by max on Wed Oct 19, 2005 9:25 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 9:20 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
max wrote:
suggestions to how pojo could ever handle you mapping the same class twice is welcome ;)


Max,

This works without issue in the POJO world. The issue arises only when exporting XML. See JIRA issue HHH-794

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 9:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
My comment where a reply/question on:

Quote:
hbm2java which apparently can't handle POJO's and XML entitites simultaneously


not regarding the xml export stuff which there already is a jira issue for (as I understand it)[/quote]

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 10:09 am 
Newbie

Joined: Tue Oct 18, 2005 9:51 am
Posts: 4
max wrote:
suggestions to how hbm2java could ever handle you mapping the same class twice is welcome ;)

The workaround is mapping the table multiple times, not the class.

I got an error from hbm2java when I implemented the workaround but didn't investigate further as to how I might solve it - I've switched to Castor in the meantime until HHH-794 is fixed.

In case you're interested the exception was:
Code:
org.hibernate.tool.hbm2x.ExporterException: Error while processing template pojo/javaclass.vm
        at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:89)
...
Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'getPackageDeclaration' in  class org.hibernate.tool.hbm2x.Cfg2JavaTool threw exception class java.lang.NullPointerException : null
        at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:246)
        at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:175)
        at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:220)
        at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:230)
        at org.apache.velocity.Template.merge(Template.java:256)
        at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:450)
        at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:419)
        at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelper.java:81)
        ... 17 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 10:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - so this is for an mapped entity without a class ?

could you put it in jira so i wont forget it (at least report some meaningfull message ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 10:31 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
max wrote:
hmm - so this is for an mapped entity without a class ?

could you put it in jira so i wont forget it (at least report some meaningfull message ;)


Max,

I put this in JIRA (HHH-794) a while ago complete with a runable example.

The problem exists whether or not there is a class associated with the mapping, but only when generating the XML. I assume it has something to do with the fact that when generating the XML, all objects are of the same class, org.dom4j.Element.

By assigning a separate entity-name it still works for the POJO using the class specified in the POJO.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 19, 2005 10:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
HHH-794 is still about the bug in the core, i am talking about the issue with hbm2java which is just related and i cant see described in hhh-794

_________________
Max
Don't forget to rate


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