-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Using Views
PostPosted: Thu May 06, 2004 3:17 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
Can we use database views instead of tables in hiberante. If yes then what is the way to do that??. I am using an Oracle database and we already have many view and we want to use that views in the new application too. We dont want to insert or update, delete using View as they are not insertable we just want to use them in searching cases so only for retrieval.Please reply me asap.

Regards,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 3:18 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
just use view name instead of table on the mapping file


Top
 Profile  
 
 Post subject: Using View without Primary Key
PostPosted: Tue May 18, 2004 5:45 am 
Regular
Regular

Joined: Tue Mar 23, 2004 2:10 am
Posts: 51
Hello,
Now i know that i can use View for mapping too. But what is irriating me is the fact that hbm2java requires primary key but my view has no primary key and no column is unique either and hbm2java does not generate mapping file and complains that there should be primary key or id defined. Please help me asap

Regards,
Shoaib Akhtar


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 5:46 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
How do you prevent duplicates without a primary key?

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 18, 2004 9:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Create the entry with all fields as members of the composite key. Now this assumes that it will be unique in this case. If not then you may have to use the ROWID as/in the key (if you can get access to it).


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 4:47 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:08 pm
Posts: 38
Location: Davis,CA,USA
I think its not importent if values are unique in a view, a view is only a stored query in the database with a table mapping.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:32 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
No, a View is a virtual table with all the implications. A "stored query" can be materialized in a Temporary table, some people confuse the two.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:34 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:08 pm
Posts: 38
Location: Davis,CA,USA
thats not so right a view is a virtual table based on a sql query whitch is stored in the database!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Of course. But it's still a real table, just virtual. It needs a primary key.

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:39 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:08 pm
Posts: 38
Location: Davis,CA,USA
sorry thats not right, a view only need a primary key when it is update and insertable!


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:52 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Every view should be update and insertable, thats why it is a table! Come on, don't learn the relational model from Oracle books ;)

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 6:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The fact is we just won't support constructs like tables/views without an identifying set of atributes. This is pretty impossible for ORMs, because you can no longer identify which row an object represents.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 7:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Keep in mind that you can in extreme cases map all properties of a class, that is, all columns of a view/table as a composite key. This correctly reflects the primary key in a table/view without an explicit primary key declaration: All attributes together are the primary key.

(This doesn't mean a database will work correctly: Most allow duplicate rows, that is, they allow bags of tuples instead of sets. There goes data integrity again. In practice, it works "most of the time".)

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 7:03 am 
Beginner
Beginner

Joined: Tue May 11, 2004 12:08 pm
Posts: 38
Location: Davis,CA,USA
:)

sorry dont learning by oracle, it's written in the 1999 and 2003 sql refrence and this says a view is only insert and updateable if it based on one table. Then your right it needs an primary key. The other way is to make a view over several tables to display a report for an user or things like this... And then is it not updateable! (ok if you use oracle it is updateable, but we want to use the standard...)

But thats not the fact, the importent thing is thats hibernate works fine


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 19, 2004 7:07 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Keep in mind that SQL is not a relational language and the SQL standard has not much to do with relational databases. There is a huge difference between "should be", "is standardized" and "is available" in the database world. Always try to see what it really is. A view is a relation, with all implications, completely transparent to the application (that is, its the same as a base table). Just because the SQL guys couldn't figure out how to make it a relation doesn't mean it shouldn't be nor that it is not available.

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

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.