-->
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.  [ 4 posts ] 
Author Message
 Post subject: one-to-one mapping using unique foreign key constraint
PostPosted: Thu Jun 09, 2005 11:34 pm 
Hi.

Despite having the below in my hbm.xml file :

<many-to-one name="Doc" column="DocID"
class="Doc"
cascade="all"
unique="true" />

NHibernate happily keeps inserting multiple rows with the same DocID value; I might be missing something...
Does NHibernate itself implement the logic that the docs say the configuration performs, e.g the purpose
of the attributes and the elements in the hbm.xml
file; or am I supposed to have my (existing) schema set up so as to match what the xml attributes tell NHibernate?
Meaning that some attributes are meant mainly for schema generation?
e.g, 'unique="true" ' and 'not-null="true" '

Rico.


Top
  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 12:36 pm 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
I'm pretty sure NHibernate doesn't look at the unique and not-null attributes. Those are only for the hbm2dll schema creation.

You will probably have to query to see if the DOC-ID exists yet prior to creating a new object.

[Then again, I could be wrong.]

BOb


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 12:47 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Pilotbob wrote:
I'm pretty sure NHibernate doesn't look at the unique and not-null attributes. Those are only for the hbm2dll schema creation.

You will probably have to query to see if the DOC-ID exists yet prior to creating a new object.

[Then again, I could be wrong.]


You are right. NHibernate doesn't check uniqueness, since this would require an additional query in general. I think that H2.1 does check uniqueness among the objects known to the session, but I am really not sure about this either. In general, it's the job of the database to check these constraints.


Top
 Profile  
 
 Post subject: one-to-one mapping using unique foreign key constraint
PostPosted: Fri Jun 10, 2005 2:58 pm 
Newbie

Joined: Sat Jan 15, 2005 9:17 am
Posts: 10
sergey wrote:
Pilotbob wrote:
I'm pretty sure NHibernate doesn't look at the unique and not-null attributes. Those are only for the hbm2dll schema creation.

You will probably have to query to see if the DOC-ID exists yet prior to creating a new object.

[Then again, I could be wrong.]


You are right. NHibernate doesn't check uniqueness, since this would require an additional query in general. I think that H2.1 does check uniqueness among the objects known to the session, but I am really not sure about this either. In general, it's the job of the database to check these constraints.


Thanks Guys. Pilotbob and sergey.
What I've done was to go ahead and get my hands dirty: simple as it might be, the overwelling number of parameters and miscellaneous stuffs to consider with NHibernate had me stuck at how to formulate the uniqueness constraint on MS SQL for that particular column.
So, I got the SchemaExport class up and running in my project and let it re-create the schema based on what I had understood the attributes helped to configure it to do. Now it's got clearer, from the demarcation between what NHibernate does and what it counts on the DBMS to do, to NHibernate's responsibility for object persistence being within the context of a session..

Actually, I spent a lot of time trying to get the picture of what the praiseworthy documentation for Hibernate was trying to say, but from inheritance mapping using discriminator, joined-subclass, composite-id, outer-join="true", property-ref,
"isn't the collection on the 'one' end of the one-to-many relationship so why do they say it's the 'many' end?" ... it all just flew way over my head before I dozed off... and then, there was NHibernate's unit tests and examples. Light. I guess I know what to do on Hibernate's side as well :)
Thank You Guys.

Rico.


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