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.  [ 7 posts ] 
Author Message
 Post subject: [2.2] exception raised on BuildSessionFactory
PostPosted: Wed Sep 17, 2008 2:40 pm 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Hello,

I've got the following exception when I do :

Code:
ISessionFactory sessionFactory = (new Configuration()).Configure().BuildSessionFactory();



DataTransfer.Mappings.RssFeedCountries.hbm.xml(4,6): XML validation error: The element 'class' in namespace 'urn:nhibernate-mapping-2.2' has invalid child element 'property' in namespace 'urn:nhibernate-mapping-2.2'. List of possible elements expected: 'urn:nhibernate-mapping-2.2:meta urn:nhibernate-mapping-2.2:jcs-cache urn:nhibernate-mapping-2.2:cache urn:nhibernate-mapping-2.2:id urn:nhibernate-mapping-2.2:composite-id'.

I don't understand what the problem is. My mapping file for this table looks like this :

<?xml version="1.0" encoding="utf-8"?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">

<class name="DataTransfer.RssFeedCountries,DataTransfer" table="RSSFeedCountries" lazy="true">

<property type="int" not-null="true" name="RssFeedCountryid" column="[RSSFeedCountryID]" />

<property type="string" not-null="true" length="50" name="RssFeedCountry" column="[RSSFeedCountry]" />

</class>

</hibernate-mapping>


Does someone know what I'm doing wrong ?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 3:49 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
First part of a class mapping is the identity specification.
Code:
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Eg"
    namespace="Eg">

        <class name="Cat" table="CATS" discriminator-value="C">
****             
                <id name="Id" column="uid" type="Int64">
                        <generator class="hilo"/>
                </id>
****
                <discriminator column="subclass" type="Char"/>
                <property name="BirthDate" type="Date"/>
                <property name="Color" not-null="true"/>
                <property name="Sex" not-null="true" update="false"/>
                <property name="Weight"/>
                <many-to-one name="Mate" column="mate_id"/>
                <set name="Kittens">
                        <key column="mother_id"/>
                        <one-to-many class="Cat"/>
                </set>
                <subclass name="DomesticCat" discriminator-value="D">
                        <property name="Name" type="String"/>
                </subclass>
        </class>

        <class name="Dog">
                <!-- mapping for Dog could go here -->
        </class>

</hibernate-mapping>

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:01 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Thanks for the tip !

What if my database table does not define a primary key ( I know it shouldn't be) then can I not by-pass that in the xml file ?

Also, what if they are multiple primary keys ? How would that be defined in the xml file ? Can you give me a quick example ?

Thanks a lot for helping !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:15 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
If your primary key consists of multiple columns you use <composite-id> instead of <id>.
I don't think tables without a primary key can be mapped to an entity. I think you can only use the table as a component of another entity then. But I never tried this, so I might be wrong.

Look here for further information:
http://www.hibernate.org/hib_docs/nhibe ... aration-id


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:16 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hibernate needs a primary key. If you don't have one, you can use a surrogate primary key. If you can't change your database then you have a problem.

What do you mean with "multiple" primary keys. If you mean a composite primary key, then check out this chapter of the docs:

http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/mapping.html#mapping-declaration-compositeid

And I strongly recommend that you read some docs/books about hibernate before continuing. It will save you a lot of time.

Check out:

http://www.nhforge.org
http://www.manning.com/kuate/

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:53 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Thank you both for your help.

I meant a composite primary key indeed.

I agree with the fact I should read a book.... but I wish I could find one ! There's plenty about hibernate, but nothing about NHibernate. There is some online documentation, but I'm more of a 'book guy' :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:58 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have a look at

http://www.manning.com/kuate/

That's the NHibernate version of "Hibernate in action". You can get the "early access edition". And since NHIberanate is a port you can take any hibernate book. You have to translate java to C# or VB but the principles are the same.

And you can try the reference doc for a start. It's not an easy start but there's a lot of valuable information in it. And browse through nhforge.

Here you can find a pdf version for 1.2:

http://www.hibernate.org/5.html#A27

I haven't found one for 2.0, yet.

_________________
--Wolfgang


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