-->
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.  [ 9 posts ] 
Author Message
 Post subject: Identifier Property
PostPosted: Thu May 20, 2004 9:13 am 
Newbie

Joined: Thu May 20, 2004 9:07 am
Posts: 2
Hello,

I have a problem with identifier property. I have a table which does not have (does not need to have) a primary key. In Hibernate reference document for version 2.1.2 is says that identifier property is optional, but when I try not to put the corresponding XML tag, and run the application it doesn't work (throws an exception who says that id tag must pe present).

How can I map a class on a table which does not have a primary key?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 9:33 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
maybe mapping all his properties as part of a composite id

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 10:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No, what the documentation says is that having the id attribute defined on the java bean itself is optional. Of course you have to define some type of id in the mapping. How else is Hibernate supposed to locate specific rows?


Top
 Profile  
 
 Post subject: No identifier; no primary key
PostPosted: Thu May 20, 2004 5:19 pm 
Newbie

Joined: Thu May 20, 2004 4:59 pm
Posts: 3
Perhaps, I have misinterpreted the following incorrectly:

http://www.hibernate.org/hib_docs/refer ... a-examples
5.1.4 ID
...
"If the name attribute is missing, it is assumed that the class has no identifier property. "


Given the above quote and the DTD's requirements,
http://hibernate.sourceforge.net/hibern ... on-2.0.dtd,
it suggests to me that a table with no primary key constraints would be mapped with something like:

<id type="long"><generator class="identity"/></id>


However, both session.iterate() and session.find() are returning containers with all null objects. Albiet, the containers have the correct number of items, the items are null.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 5:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can not map a table without primary keys. What you can do is map classes without primary key properties, the table however must still have a primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 5:38 pm 
Newbie

Joined: Thu May 20, 2004 4:59 pm
Posts: 3
This would be a major limitation for adopting Hibernate for my current project. It is not my database to redesign.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
If you don't have primary keys, your database is doomed anyway and you are working with questionable results all the time.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 6:32 pm 
Newbie

Joined: Thu May 20, 2004 4:59 pm
Posts: 3
Once again, this database is not mine.

However, I might consider omitting a primary key on the following table(s):
1) AuditLog(
TimeStamp timestamp,
UserName varchar(32),
AttemptedAccess varchar(8)
ResourceName varchar(256),
WasDenied boolean,
Message varchar(512)
)


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 20, 2004 7:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Why don't you just declare for example the timestamp (or timestamp and username) as primary key, that should be good enough in that case. You have to use "assigned" in that case however. Anyways I'd strongly recommend not using such constructs and really go for reworking the database if anyhow possible.


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