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.  [ 11 posts ] 
Author Message
 Post subject: The element 'class' has invalid child element 'join'
PostPosted: Fri Sep 14, 2007 10:42 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Hibernate version:
1.2.0-GA
Mapping documents:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ML.SMI.MDS.BusinessObjects" schema="Trades" namespace="ML.SMI.MDS.BusinessObjects">
<class
name="TradeExternalMap"
table="t_trade_external_map"
>
<id
name="Id"
type="Int32"
column="id"
>
<generator class="native"/>
</id>

<property
name="ExternalId"
column="external_id"
type="String"
not-null="false"
length="50"
/>
<many-to-one
name="TradeFeed"
column="feed_id"
class="TradeFeed"
not-null="false"
/>
<many-to-one
name="TradeType"
column="trade_type_id"
class="TradeType"
not-null="false"
fetch="join"
not-found="ignore"
unique="true"
lazy="false"
/>
<many-to-one
name="ProductType"
column="product_type"
class="ProductType"
not-null="false"
fetch="join"
not-found="ignore"
unique="true"
lazy="false"
/>

<join table="link_result_trade_externalmap" optional="true" inverse="true">
<key column="trade_id"/>
<many-to-one
name="MarginResult"
column="result_id"
class="MarginResult"
not-null="false"
cascade="save-update"
lazy="true"
/>
</join>

</class>
</hibernate-mapping>

Full stack trace of any exception that occurs:
2007-09-14 15:23:29,798 [TestRunnerThread]ERROR NHibernate.Cfg.Configuration [HibernateSessionFactory()] &lt;(null)&gt; - ML.SMI.MDS.DatabaseAdapters.HibernateMappingFiles.TradeExternalMap.hbm.xml(48,4): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'join' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'urn:nhibernate-mapping-2.2:property urn:nhibernate-mapping-2.2:many-to-one urn:nhibernate-mapping-2.2:one-to-one urn:nhibernate-mapping-2.2:component urn:nhibernate-mapping-2.2:dynamic-component urn:nhibernate-mapping-2.2:any urn:nhibernate-mapping-2.2:map urn:nhibernate-mapping-2.2:set urn:nhibernate-mapping-2.2:list urn:nhibernate-mapping-2.2:bag urn:nhibernate-mapping-2.2:idbag urn:nhibernate-mapping-2.2:array urn:nhibernate-mapping-2.2:primitive-array urn:nhibernate-mapping-2.2:subclass urn:nhibernate-mapping-2.2:joined-subclass urn:nhibernate-mapping-2.2:loader urn:nhibernate-mapping-2.2:sql-insert urn:nhibernate-mapping-2.2:sql-update urn:nhibernate-mapping-2.2:sql-delete urn:nhibernate-mapping-2.2:filter'.
NHibernate.MappingException: ML.SMI.MDS.DatabaseAdapters.HibernateMappingFiles.TradeExternalMap.hbm.xml(48,4): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'join' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'urn:nhibernate-mapping-2.2:property urn:nhibernate-mapping-2.2:many-to-one urn:nhibernate-mapping-2.2:one-to-one urn:nhibernate-mapping-2.2:component urn:nhibernate-mapping-2.2:dynamic-component urn:nhibernate-mapping-2.2:any urn:nhibernate-mapping-2.2:map urn:nhibernate-mapping-2.2:set urn:nhibernate-mapping-2.2:list urn:nhibernate-mapping-2.2:bag urn:nhibernate-mapping-2.2:idbag urn:nhibernate-mapping-2.2:array urn:nhibernate-mapping-2.2:primitive-array urn:nhibernate-mapping-2.2:subclass urn:nhibernate-mapping-2.2:joined-subclass urn:nhibernate-mapping-2.2:loader urn:nhibernate-mapping-2.2:sql-insert urn:nhibernate-mapping-2.2:sql-update urn:nhibernate-mapping-2.2:sql-delete urn:nhibernate-mapping-2.2:filter'. ---> System.Xml.Schema.XmlSchemaValidationException: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'join' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'urn:nhibernate-mapping-2.2:property urn:nhibernate-mapping-2.2:many-to-one urn:nhibernate-mapping-2.2:one-to-one urn:nhibernate-mapping-2.2:component urn:nhibernate-mapping-2.2:dynamic-component urn:nhibernate-mapping-2.2:any urn:nhibernate-mapping-2.2:map urn:nhibernate-mapping-2.2:set urn:nhibernate-mapping-2.2:list urn:nhibernate-mapping-2.2:bag urn:nhibernate-mapping-2.2:idbag urn:nhibernate-mapping-2.2:array urn:nhibernate-mapping-2.2:primitive-array urn:nhibernate-mapping-2.2:subclass urn:nhibernate-mapping-2.2:joined-subclass urn:nhibernate-mapping-2.2:loader urn:nhibernate-mapping-2.2:sql-insert urn:nhibernate-mapping-2.2:sql-update urn:nhibernate-mapping-2.2:sql-delete urn:nhibernate-mapping-2.2:filter'.
--- End of inner exception stack trace ---

Name and version of the database you are using:
SQL Server 2005


As you can see the mapping file seems to me ok but then I get that error. I have looked at the docs and I think everything is in order unless I am pointing to some incorrect namespace or something. Anyone any ideas.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 2:46 pm 
Newbie

Joined: Mon Jun 04, 2007 12:26 pm
Posts: 13
Location: Houston, Texas
I believe the <join table> element is not available for for NHibernate. I did read about a patch you can apply, NH-466, but have never used it.
See http://jira.nhibernate.org/browse/NH-466


Top
 Profile  
 
 Post subject: <join table>
PostPosted: Fri Sep 14, 2007 3:13 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
I've never tried to use <join table> but have seen a blog about it:
http://andersnoras.com/blogs/anoras/arc ... ables.aspx

The blog said the it wouldn't make it into the final 1.2 build...not sure what current disposition is. You could try getting code off the trunk and see if it's supported there.

However, you could use a <subclass_join>. It looks like this and is under <class>
Code:
    <joined-subclass
      name="BlahBlah.Core.MyClass, BlahBlah.Core"
      table="MyClassTable">
      <key column="MyClassId"/>

      <property name="Prop1" column="Prop1" not-null="true" />
...
   </joined-subclass>


Your class structure would have <class> as your base and would be something like class AbstractTradeExternalMap. TradeExternalMap would derive from that and properties pertaining to the derived class would go into the joined-subclass section.

Problems with this?
1. "key" of joined-subclass is the foreign key to the parent table...this
doesn't look to fit into your domain model.
2. subclass and joined-subclass can't be used together in the same class
mapping.

Alternatively, you can have a TradeExternalMapResult class and set up a one-to-one relationship with TradeExternalMap. You'd declare the one-to-one so that it's sharing the primary key with TradeExternalMap.

Does that help?

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 3:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
The <join> element is implemented in the trunk, but it is not included in 1.2GA. It is slated to be included in 2.0.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 4:37 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Thanks Guys,

This was very helpful. jlockwood, thanks for youre suggestions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 17, 2007 9:29 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
NP, anytime.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 9:56 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Hi JLockwood,

Just a quick question. In the case of the one-to-one mapping with the shared primary key, how would I do this using the link table TradeExternalMapResult.

TradeExternalMap --> TradeExternalMapResult --> MarginResult.

I am not sure that this is possible using the link table is it !

thanks,
Richie.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:12 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
I think you would have to have a class that represents the association table, then it wouldn't be a problem. I'm not sure, off hand, if it's possible without the additional class. (If you can make it work drop a line and tell me how...I'll add it to my tool bag)

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:17 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
Hold that thought, I think chapter 19 may have what you are looking for:
http://www.hibernate.org/hib_docs/nhibe ... pings.html

Author class is associated to Work class through the author_work table. The example given is bi-directional. Just check out the page and search for 'author_work". Think it will do it for you.
Code:
    <class name="Author" table="authors">

        <id name="Id" column="id">
            <!-- The Author must have the same identifier as the Person -->
            <generator class="assigned"/>
        </id>

        <property name="Alias" column="alias" />
        <one-to-one name="Person" constrained="true"/>

        <set name="Works" table="author_work" inverse="true" lazy="true">
            <key column="author_id"/>
            <many-to-many class="Work" column="work_id"/>
        </set>

    </class>

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:18 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
Yeah, I was thining the same. I reckon I will see if I can integrate that patch first and when I do I will create a new post on it. If that fails then I may have to go with either a many to many solution of some kind. I dont want to expose the link table if possible. It would be a hack essentailly that I would have to change later on down the line me thinks.

thanks again,
Richie.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 18, 2007 10:21 am 
Beginner
Beginner

Joined: Fri May 25, 2007 5:55 am
Posts: 26
<replying to the many-to-many solution>

Again, exactly what I reckon I will have to do. Its probably the easiest way right now in order to get around this. I have another post up asking if anyone has integrated with the NH-466 patch and I will see how I get along with that first.

Ta.
Richie.


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