-->
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: No identifier/Primary key in table
PostPosted: Tue May 02, 2006 5:56 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
Hibernate version:1.0.2

Hi there,

i'd like to map a table, but the table hasn't a identifier/primary key field. Now NHibernate throws an error that it must have an identifier. How can I resolve this?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 02, 2006 9:33 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
If you can, add a primary key to the table. Can you infer a natural (composite) key? How do you identify one unique record?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 7:34 am 
Newbie

Joined: Wed Apr 26, 2006 5:28 am
Posts: 18
k-dub wrote:
If you can, add a primary key to the table. Can you infer a natural (composite) key? How do you identify one unique record?


Hi,

thank you for your respone and sorry for the delay. One column has an index but the column isn't unique. Currently I open the database with the OleDbConnection and add a column with the alter statement and use that column as primary key. Then I use NHibernate. When I have finished working with the DB I drop the column.

The problem is that I didn't create the DB. It's from a third party.

Maybe for one of the next releases of NHibernate it's possible to allow tables without index. I know it's against the normal form but tell that the people who build the database I have to use.


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 05, 2006 8:12 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
There's no way that I know of for NHibernate to work with a table where rows are not guaranteed to be unique be either a surrogate key (primary key) or a natural key (joined primary keys). If you can't find a way to identify one row from another, you'll likely have trouble with any ORM solution.

If I have a table like:
Code:
==name== ==email=== ==age===
john            jkl@hp.com     32
sue            sue@hp.com    27
mike           mj@nike.us     41


... and there's no definitive way to know that row2 != row1, I would have to scan all the fields in all the rows looking for duplicates, or put the rows in different sets of Hashtables to find duplicates. That would be horrendously slow! It just won't work. And how would you look up mike's row, by name? If there's a primary key column, indexed and unique,
Code:
select * from faketable where id = 3
is much faster than
Code:
select * from faketable where name='mike' and email='mj@nike.us' and age=41
Now you've given the select statement all the info you needed to retrieve, making the query pointless. Also, the DB has to scan the value of all those fields to find the value you've given, rather that getting a match from an index.

Tables without primary or composite keys just won't work - that's why NHibernate requires it.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.