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.  [ 5 posts ] 
Author Message
 Post subject: How can I map with No Primary Key?
PostPosted: Tue Sep 12, 2006 10:15 am 
Newbie

Joined: Mon Jun 26, 2006 12:27 pm
Posts: 16
I need to create a mapping file for a table that has no real primary key. I realize that keeps NHibernate from being able to update the data, but the data is read only from NHibernates point of view.

As an example, I have a job table the represents a finished job. Another table is job_output and contains output messages from the job. This table has no primary key, just a row for each message and a foreign-key reference back to the job. Is there a way to map this in NHibernate without making some primary key on the job_output table that is pretty much worthless from a database point of view (i.e. the data is read only)?


Top
 Profile  
 
 Post subject: Re: How can I map with No Primary Key?
PostPosted: Tue Sep 12, 2006 1:02 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
I'm afraid NHibernate will not help you here. It seems to me that it is against the principle of NHibernate (and OR mapping in general, for that matter) to reconstruct objects from a persistent store without any means to identify them back to where they are persisted. If redesigning your database is not possible, the only thing you can do (as I see it) is have a SQL query collect the appropriate data from the database and do some reconstruction yourself.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 1:34 pm 
Newbie

Joined: Mon Jun 26, 2006 12:27 pm
Posts: 16
I kinda figured that from the documentation and it makes sense. I didn't know if there was some way to make it read only and let NHibernate assign some sort of key of it's own in the background to allow it to track the object. I ended up adding an identity column and setting an id that NHibernate can access with field, but these will be pretty large tables and I hate to have an extra column of storage in the database that is necessary only for NHibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 3:52 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You cannot map the job message as a separate entity but you can make job have a collection of its messages, mapped using <set>. You don't need a primary key then.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 7:07 am 
Newbie

Joined: Mon Jun 26, 2006 12:27 pm
Posts: 16
I'll look into set then. I always assumed that you had to have a mapped entity to be the basis of your relationship.


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