Doesn't not-null="true" indicate that it can't be null?

From: Fabio Maulo 
Sent: Tuesday, September 08, 2009 9:09 PM
To: [email protected] 
Subject: [nhusers] Re: issue with inverse=true


This is how should look that mapping
<property name="PasswordFormat"  />


Note: not-null="true" ; how an enum can be null ?


2009/9/8 Lothan <[email protected]>


  I've run into that situation as well and it seems to boil down to the fact
  that mapped the column as an Int32, but the actual value is an enum so the
  final value looks different to NHibernate. The solution I found is to map it
  to the actual enum type using the fully-qualified type name, e.g.:


  <property name="PasswordFormat" column="PasswordFormat"

  type=MyDomain.Namespace.PasswordFormatType, MyDomain" not-null="true" />

  Anyone feel free to correct anything I may have gotten wrong.

  --------------------------------------------------
  From: "graphicsxp" <[email protected]>
  Sent: Tuesday, September 08, 2009 11:57 AM
  To: "nhusers" <[email protected]>
  Subject: [nhusers] Re: issue with inverse=true


  >
  > Ok, I've narrowed down the problem. It's actually not to do with
  > inverse=true but with this line in the mapping of Artist :
  >
  > <property name="PasswordFormat" column="PasswordFormat" type="Int32"
  > not-null="true" />
  >
  >
  > The value set in my code is of type MembershipPasswordFormat which is
  > an Enum in System.Web.Security. So the value I'm trying to persist is
  > MembershipPasswordFormat.Clear, which is equal to 0. For some reason,
  > NH does an update even when the value is not changed.
  >
  > Anyone ?
  >
  >
  > On 24 Aug, 16:13, graphicsxp <[email protected]> wrote:
  >> Hi,
  >> Thanks for helping.
  >>
  >> The mapping for the Art class :
  >>
  >> <?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
  >>
  >> <?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>
  >>
  >> Can you see something wrong ?
  >>
  >> On 23 août, 16:42, zihotki <[email protected]> wrote:
  >>
  >> > Hi,
  >>
  >> > Could you please post complete mapping? It's very hard to understand
  >> > the problem with the parts of mappings you wrote before.
  >> > And also please check generated SQL queries, probably you'll find the
  >> > answer yourself.
  >>
  >> > On Aug 22, 10:08 pm, graphicsxp <[email protected]> wrote:
  >>
  >> > > 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.
  >>
  >> > > Art mapping :
  >> > > <class name="xxx" table="xxx">
  >> > >     <id name="Id" column="xxx" type="guid">
  >> > >       <generator class="guid.comb"/>
  >> > >     </id>
  >>
  >> > >     <many-to-one name="Artist" class="xxx.xxx, xxx" column="UserID"
  >> > > not-null="true" />
  >> > > .
  >> > > .
  >> > > .
  >>
  >> > > Artist mapping :
  >>
  >> > > <bag  name="Arts" inverse="true" cascade="all-delete-orphan"
  >> > > lazy="true">
  >> > >       <key column="UserID" on-delete="cascade"/>
  >> > >       <one-to-many class="xxx.xxx, xxx" />
  >> > > </bag>
  >>
  >> > > Now when I save a new Art, NH performs and INSERT and then an UPDATE
  >> > > on Artist, which is wrong.
  >>
  >> > > Here's my code for saving the Art entity :
  >>
  >> > >        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 ?
  >>
  >> > > Thanks
  > >
  >






-- 
Fabio Maulo



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to