-->
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.  [ 10 posts ] 
Author Message
 Post subject: not-null="true|false" and not-found="ignore
PostPosted: Sat May 28, 2005 10:36 am 
not-null="true|false"
not-found="ignore|exception"

NHibernate doesn't support it ?


Top
  
 
 Post subject:
PostPosted: Sat May 28, 2005 12:48 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It supports not-null only.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 2:37 am 
Newbie

Joined: Sat May 28, 2005 10:25 am
Posts: 1
sergey wrote:
It supports not-null only.



-------------------------------------------------------------------------------

hi , sergey
a relation of many-to-one,have a bill class which a person class.In the bill mapping file
we add :

<many-to-one name="Person" column="PersonID" class="abc.Person,abc" not-null="false" />

When use session.Load Bill Class,if the person not exists,the method of Load will create exception.
now this person column can be null。
not-null="false" has no effect。

sorry , I am bad at English. thanks.


Top
 Profile  
 
 Post subject: not-found="ignore|exception"
PostPosted: Sun May 29, 2005 2:41 am 
Newbie

Joined: Sun May 29, 2005 2:17 am
Posts: 2
Location: Novosibirsk, Russia
It would be nice if NH supports such configuraion global and/or per class/relation.
In my current project i'm faced with problem how to work arround of broken entity references. I should work with legacy database and also share it with another legacy application. Since I could not enforce reference entegrity in db I'm looking for some kind workarround to avoid "row not found" exception when loading class contains broken reference. Sergey could you recomend the Extesion Point where I could implement such behavior?

Many thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 3:38 am 
Newbie

Joined: Sun May 29, 2005 2:17 am
Posts: 2
Location: Novosibirsk, Russia
ouYeah wrote:
a relation of many-to-one, have a bill class which a person class.In the bill mapping file

<many-to-one name="Person" column="PersonID" class="abc.Person,abc" not-null="false" />

When use session.Load Bill Class,if the person not exists,the method of Load will create exception.
not-null="false" has no effect。


Hi ouYeah,
As I understand from NH docs not-null="true/false" used to determinate the order in which save/update of related entities happens and have no affect on load. NH will always throw "Object not found" exception when loading not existent persistent class; the only workarround is to use ISession.Get() - this method returns null reference if persistent class not found. ISession.Get(typeof(Bill), id) will also works just fine returning null in place of nonexistent Person. But when you will try to execute NH query, for example "from Bill ..." and resultset will contains bill with reference to nonexistent person, you'll get the same "Object not found" Exception.

It's main problem i'm facing also in my project now.
Regards,
/Wir


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 7:21 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
not-null actually has almost no effect in NHibernate. It's used in the schema export tool, and during updates, to check whether a field value is null. It has no effect on update ordering.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 4:21 am 
ouYeah wrote:
sergey wrote:
It supports not-null only.



-------------------------------------------------------------------------------

hi , sergey
a relation of many-to-one,have a bill class which a person class.In the bill mapping file
we add :

<many-to-one name="Person" column="PersonID" class="abc.Person,abc" not-null="false" />

When use session.Load Bill Class,if the person not exists,the method of Load will create exception.
now this person column can be null。
not-null="false" has no effect。

sorry , I am bad at English. thanks.






Top
  
 
 Post subject: not-found="ignore"
PostPosted: Thu Jan 26, 2006 11:11 am 
Newbie

Joined: Wed Nov 23, 2005 5:44 am
Posts: 7
I am also having this problem, I have a one-to-one relationship using the 'unique foreign key associations' example in the documentation.

The problem is if one of the records do not exist, it causes an exception

Code:
No row with the given identifier exists: fffdc40c-2233-4064-8ad2-c9d831071f94, of class: FusionRecruit.AspNetProviders.Pocos.AspNetProfile



My mapping (stripping out columns not needed):

Code:
  <class name="FusionRecruit.AspNetProviders.Pocos.AspNetUser, FusionRecruit.AspNetProviders" table="aspnet_Users">
    <id name="UserId" column="UserId">
      <generator class="guid" />
    </id>
    <many-to-one name="Profile" class="FusionRecruit.AspNetProviders.Pocos.AspNetProfile, FusionRecruit.AspNetProviders" column="UserId"
                unique="true" insert="false" update="false"
                cascade="all" not-null="false" />

  </class>
  <class name="FusionRecruit.AspNetProviders.Pocos.AspNetProfile, FusionRecruit.AspNetProviders" table="aspnet_Profile">
    <id name="UserId" column="UserId">
      <generator class="foreign">
        <param name="property">User</param>
      </generator>
    </id>
    <one-to-one name="User" class="FusionRecruit.AspNetProviders.Pocos.AspNetUser, FusionRecruit.AspNetProviders" constrained="true" />
  </class>



Ideally I want it so the AspNetUser either has a profile or doesn't have one, a one-to-zero-or-one relationship.

Anyone know how to get around this issue?

best regards

Fluxtah


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 1:06 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
ouYeah wrote:
sergey wrote:
It supports not-null only.



-------------------------------------------------------------------------------

hi , sergey
a relation of many-to-one,have a bill class which a person class.In the bill mapping file
we add :

<many-to-one name="Person" column="PersonID" class="abc.Person,abc" not-null="false" />

When use session.Load Bill Class,if the person not exists,the method of Load will create exception.
now this person column can be null。
not-null="false" has no effect。

sorry , I am bad at English. thanks.


If PersonID is null, the Person property should load as a null reference. If this isn't the case, then there is a problem and we'll need more details.

I'm assuming this problem only occurs if PersonID is not null. Since NH doesn't support that scenario (as far as I know) your only option is to make sure that a Person is never deleted from the DB without dereferencing or deleting the associated bills. If the association ID is still required because you have to relate the bills to each other, you could create a "placeholder" Person that they could at least point to.

Hope this helps.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 1:15 pm 
Newbie

Joined: Wed Nov 23, 2005 5:44 am
Posts: 7
well I managed to sort out my problem by using a one-to-one on the other end and now it does'nt complain thanks to extensive searching on the forum.

Code:
  <class name="FusionRecruit.AspNetProviders.Pocos.AspNetUser, FusionRecruit.AspNetProviders" table="aspnet_Users">
    <id name="UserId" column="UserId">
      <generator class="guid" />
    </id>
    <one-to-one name="Profile" class="FusionRecruit.AspNetProviders.Pocos.AspNetProfile, FusionRecruit.AspNetProviders" />

  </class>
  <class name="FusionRecruit.AspNetProviders.Pocos.AspNetProfile, FusionRecruit.AspNetProviders" table="aspnet_Profile">
    <id name="UserId" column="UserId">
      <generator class="foreign">
        <param name="property">User</param>
      </generator>
    </id>
    <one-to-one name="User" class="FusionRecruit.AspNetProviders.Pocos.AspNetUser, FusionRecruit.AspNetProviders" constrained="true" />
  </class>


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