-->
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.  [ 12 posts ] 
Author Message
 Post subject: Mapping View or table without a Primary Key
PostPosted: Wed Oct 22, 2003 1:32 pm 
Newbie

Joined: Wed Oct 22, 2003 1:07 pm
Posts: 10
Hi,

When I looked at the documentation for the mapping file, it says "Mapped classes must declare the primary key column of the database table ".

So my question is can I map a View with no primary key?

The view in question will only be passed to the presentation layer. No update, insert, or delete will be done on the view.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 22, 2003 9:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Map all columns as a compound key thus the complete tuple is the key.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 10:01 am 
Newbie

Joined: Wed Oct 22, 2003 1:07 pm
Posts: 10
I might have duplicate tuples in the View ?
The view is only for presentation layer. I want to display all the records including the duplicates.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 23, 2003 1:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As Christian really got through to me one day, duplicate tuples are -fundamentally- broken. Like, completely. It can not possibly have any meaningful semantics to the user (what does two identical rows mean??) and breaks the relational model (a table or view = a relation = a set of tuples in mathematics). Databases should not allow this, and you should not display such meaningless data to your user.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 12:45 pm 
Newbie

Joined: Wed Oct 22, 2003 1:07 pm
Posts: 10
Hi,

First of all I was talking about views. Views can have duplicate tuples. I can give you an example of that if you like. And we are not trying to persist that data. We are just trying to load all the data.
As far as tables are concerned, you are taling about ideal conditions, ideally you should have a primary key. But there are legacy data or clients have tables with no primary key. We have clients who have one big table with 100 columns in it and no primary key One client has a table with 12 columns in it, all of them can be null and there is no primary key. We have to deal with that kind of data. I was trying to migrate that kind of data into normalized ideal tables designed by us when I asked you this question.
As far as your quote" duplicate tuples are -fundamentally- broken. Like, completely. Databases should not allow this, and you should not display such meaningless data to your user". All RDBMS allow tables without primary key, It is not a requirement. and I think Oracle, SQL Server guys know fundamental concept of Relatinal Database.

I was quite disappointed to see this reply.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 1:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you want to actually go look up the definition of "relation", you will find it means "a set of tuples". Sets do not permit duplicate elements.

A view is supposed to be a relation, just like a normal table.

It is, of course, quite trivial to add a surrogate key to a view, or remove duplicates using distinct.

While I am quite certain that Oracle et al know quite a lot about the relational model, I am equally certain that they do not strictly implement it. (Well, at a physical level, actually they do - by under the covers using a hidden row id.)

And you havn't explained to me exactly what sense the user is supposed to make of a duplicate tuple displayed on the screen. Or what semantics duplicate table rows could possibly have.

I am sorry to disappoint you.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 1:29 pm 
Newbie

Joined: Wed Oct 22, 2003 1:07 pm
Posts: 10
May I can clarify, I am building a web frontend on top of a legacy data store. This data is studied by geologist that would like to see the raw data in the presentation layer. They see value in seeing duplicates records(I am a DBA and have know idea what they see but I am here to please). All I know is the tables I need to bring up to the presentation screen contains no PK and not unique values. I know I can get around this problem by using staight JDBC but I was curious why Hibernate does not have a feature for READ-ONLY data. This would allow me to retrieve the raw records without PK. I know there are many work arounds but I was just curious.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 9:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Convert your view into a HQL find query and use the new class semantics so that you read the data into a newly allocated class for each row of you data. This class is nothing more than holding the data returned from the query.
For example,

Code:
s.find("select new net.sf.hibernate.test.S(s.count, s.address) from s in class Simple")


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 12:09 pm 
Newbie

Joined: Wed Oct 22, 2003 1:07 pm
Posts: 10
What is 's' here ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 6:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
THis was a simple example of the syntax aimed at the use of new to create a read only data object. So 's' is, depending on which one, the session, eg, s.find or the Simple class alias, eg, s in class Simple.


Top
 Profile  
 
 Post subject: How do you map the Simple class ?
PostPosted: Thu Nov 13, 2003 12:47 pm 
Newbie

Joined: Thu Nov 13, 2003 12:03 pm
Posts: 18
Location: France
In your example, how do you map the Simple class ?eg, how do you describe to which table the Simple class is associated ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 13, 2003 6:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
In this case the simple class is a mapping to a simple table with no associations. This was taken from one of the tests I wrote to support some modifications in the Select clause parser. Check out the source in the hibernate code under the tests directory.


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