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: Query View (no unique key)
PostPosted: Mon Feb 18, 2008 10:51 am 
Newbie

Joined: Mon Dec 10, 2007 3:27 pm
Posts: 8
Hibernate version: 3.2.2

Name and version of the database you are using: Oracle 10g

I've an Oracle view with 6 columns: name, id, company, department, reference, creationdate. I used all the columns (some columns are nullable) as the composite-id.

Is it ok to have nullable fields in composite-id or all fields in composite-id must be not-null?

In the view, there's a row with name & id, and when I try to query by criteria using these 2 fields, a list of 1 null object was returned. My mapping is as below:

Code:
<composite-id>
  <key-property name="name" column="NAME" />
  <key-property name="id" column="ID_NO" />
  <key-property name="company" column="COMPANY" />
  <key-property name="department" column="DEPARTMENT" />
  <key-property name="reference" column="REFERENCE" />
  <key-property name="creationDate" column="CREATION_DATE" />
</composite-id>


It is right that 1 object should be found, but it was null, does it means that Hibernate is unable to instantiate the object? I've the default constructor, a private attribute for the composite-id object (with getters/setters) and getters/setters and private attributes for all fields in the class as well.

Or this there a better way to do this in Hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 19, 2008 5:58 am 
Newbie

Joined: Mon Dec 10, 2007 3:27 pm
Posts: 8
Answering my own question.

What we did was to create a view on this view, and use the Oracle ROWNUM column as the primary key and it works!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 8:48 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
If you use this mapping document for onlt reading purpose then its fine. Becuase if we use rownum as id in hibernate mapping then we can't insert or update a unique record.

In select also you can't load the entity based on your id that is rownum. Hope you dont required this type reuiremnt.

Its not good design to create a table withouy keys..


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 20, 2008 12:43 pm 
Newbie

Joined: Mon Dec 10, 2007 3:27 pm
Posts: 8
somu_ngm1 wrote:
If you use this mapping document for onlt reading purpose then its fine. Becuase if we use rownum as id in hibernate mapping then we can't insert or update a unique record.

In select also you can't load the entity based on your id that is rownum. Hope you dont required this type reuiremnt.

Its not good design to create a table withouy keys..


As I said, this is a view, so its read only, hence no issue with using the ROWNUM. For legacy systems, it is sometimes unavoidable to have such cases (designs).


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