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.  [ 3 posts ] 
Author Message
 Post subject: Is this problem with lazy loading?
PostPosted: Mon Aug 30, 2010 11:02 am 
Newbie

Joined: Mon Aug 30, 2010 10:50 am
Posts: 4
Hi all.

My mapping files:

Contact (one contact belong to one group)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  auto-import="true" namespace="ContactBook.Dao.Domain" assembly="ContactBook">
  <class name="ContactBook.Dao.Domain.Contact, ContactBook" lazy="false">
    <id name="Id" access="property" column="contact_id">
      <generator class="native" />
    </id>
    <property name="FullName" access="property" column="full_name"/>
    <property name="Email" access="property" column="email"/>
    <property name="Address" access="property" column="address"/>
    <property name="Phone" access="property" column="phone"/>
    <property name="Fax" access="property" column="fax"/>
    <property name="Mobile" access="property" column="mobile"/>
    <property name="Note" access="property" column="note"/>
    <property name="BirthDay" access="property" column="birthday"/>

    <many-to-one access="property" name="Group" column="contact_group_id" cascade="all" lazy="false"/>
  </class>
</hibernate-mapping>


ContactGroup (has many contacts)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
  auto-import="true" namespace="ContactBook.Dao.Domain" assembly="ContactBook">
  <class name="ContactBook.Dao.Domain.ContactGroup, ContactBook" lazy="false" table="contact_group">
    <id name="Id" access="property" column="contact_group_id">
      <generator class="native" />
    </id>
    <property name="Name" access="property" column="name"/>
    <property name="Note" access="property" column="note"/>

    <set name="Contacts" lazy="true" table="contact" inverse="false">
      <key column="contact_group_id"/>
      <one-to-many class="ContactBook.Dao.Domain.ContactGroup, Dao"/>
    </set>
  </class>
</hibernate-mapping>



But I cannot retrieve the group that a contact belongs to. [contact.Group == null]
So, how can i fix it?

Thanks.


Top
 Profile  
 
 Post subject: Re: Is this problem with lazy loading?
PostPosted: Mon Aug 30, 2010 11:08 am 
Newbie

Joined: Mon Aug 30, 2010 10:50 am
Posts: 4
Oh my god. I also cannot get a set of contacts that belong to one group.


Top
 Profile  
 
 Post subject: Re: Is this problem with lazy loading?
PostPosted: Wed Sep 01, 2010 2:04 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Your set seems to be wrong:

<set name="Contacts" lazy="true" table="contact" inverse="true">
<key column="contact_group_id"/>
<one-to-many class="ContactBook.Dao.Domain.Contact, Dao"/>
</set>

_________________
--Wolfgang


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