-->
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.  [ 1 post ] 
Author Message
 Post subject: issue with inverse=true in my mapping
PostPosted: Tue Sep 08, 2009 5:37 am 
Beginner
Beginner

Joined: Thu Aug 14, 2008 5:31 pm
Posts: 20
Hi,
I'll post the relevant part of my mapping. I have two classes : Art
and Artist. An Artist owns a collection of Art and an Art belongs to
one and only one Artist.

The mapping for the Art class :

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="XXX.Art, XXX" table="Art">
    <id name="Id" column="BuzzUserArtID" type="guid">
      <generator class="guid.comb"/>
    </id>

    <many-to-one name="Owner" class="XXX.Artist, XXX"
column="BuzzUserID" not-null="true" />
    <many-to-one name="Category" class="XXX.XXXCategory, XXX"
column="XXXCategoryID" />

    <property name="Title" type="String" length="50" column="Title" />
    <property name="Description" type="String" length="4000"
column="Description" />
    <property name="Width" type="integer" column="Width" />
    <property name="Height" type="integer" column="Height" />
    <property name="ArtDate" type="Date" column="BuzzUserArtDate" />
    <property name="DateCreated" type="Date" column="DateCreated"
insert="false" update="false" />
    <property name="DateModified" type="Date" column="DateModified"
insert="false" />
    <property name="BuzzCount" type="integer" column="BuzzCount" />
    <property name="Rating" type="double" column="Rating" />
    <property name="Url" type="String" column="URL" />
    <property name="UrlResized" type="String" column="URLResized" />
    <property name="UrlThumbnail" type="String" column="URLThumbnail" /

    <property name="IsProcessed" type="Boolean" column="IsProcessed" /

    <property name="Scrapped" type="Boolean" column="Scrapped"
insert="false" />

    <bag  name="Comments" inverse="true" cascade="all-delete-orphan"
lazy="true">
      <key column="BuzzUserArtID" on-delete="cascade"/>
      <one-to-many class="XXX.BuzzUserArtComment, XXX" />
    </bag>

  </class>
</hibernate-mapping>


And for the Artist :

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="XXX.BuzzUser, XXX" table="BuzzUser" lazy="true">
    <id name="Id" column="BuzzUserID" type="guid">
      <generator class="guid.comb"/>
    </id>

    <property name="FirstName" type="String" length="50"
column="FirstName"  not-null="true" />
    <property name="LastName" type="String" length="100"
column="LastName" not-null="true" />
    <property name="FullName" type="String" length="150"
column="FullName" insert="false" update="false" />
    <property name="Email" type="String" length="50" column="Email"
not-null="true" />
    <property name="UserName" type="String" length="50"
column="UserName" not-null="true" />
    <property name="Password" type="String" length="256"
column="Password" not-null="true" />
    <property name="PasswordSalt" column="PasswordSalt" type="String"
not-null="false" length="64" />
    <property name="PasswordFormat" column="PasswordFormat"
type="Int32" not-null="true" />
    <property name="FailedPasswordAttemptCount"
column="FailedPasswordAttemptCount" type="Int32" not-null="true" /

    <property name="LastPasswordChangedDate"
column="LastPasswordChangedDate" type="DateTime" not-null="false"
insert="false" update="false" />
    <property name="LastActivityDate" column="LastActivityDate"
type="DateTime" not-null="true" insert="false" update="false" />
    <property name="IsApproved" column="isApproved" type="Boolean" not-
null="true" />
    <property name="IsLockedOut" column="isLockedOut" type="Boolean"
not-null="true" />
    <property name="LastLockOutDate" column="LastLockOutDate"
type="DateTime" not-null="false" insert="false" update="false" />
    <property name="LastLoginDate" column="LastLoginDate"
type="DateTime" not-null="false"  insert="false" update="false"/>
    <property name="DateCreated" type="Date" column="DateCreated"
insert="false" update="false" />
    <property name="DateModified" type="Date" column="DateModified"
insert="false" />
    <property name="Scrapped" type="Boolean" column="Scrapped"
insert="false" />
    <property name="UrlPhoto" type="String" column="URLPhoto" />
    <property name="PersonalWebSite" type="String"
column="PersonalWebSite" />

    <bag  name="Arts" inverse="true" cascade="all-delete-orphan"
lazy="true">
      <key column="BuzzUserID" on-delete="cascade"/>
      <one-to-many class="XXX.Art, XXX" />
    </bag>

  </class>
</hibernate-mapping>


Now when I save a new Art, Hibernate performs and INSERT and then an UPDATE
on Artist, which is wrong.

Here's my code for saving the Art entity :

Code:
  Art art = null;
      _UserArtDao.SessionManager.GetCurrentSession().BeginTransaction();

      art = new Art()
     {
       Category = _artCategoryDao.GetById(1),
       Artist = _UserDao.GetByUserName("jack"),
     };
      _ArtDao.SaveOrUpdate(art);
      _ArtDao.SessionManager.GetCurrentSession().Transaction.Commit();


Could you help me understanding what I'm doing wrong and why there is
an extra UPDATE on the Artist table ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.