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.  [ 6 posts ] 
Author Message
 Post subject: How to use Orcale rowid as identifier?
PostPosted: Tue May 10, 2005 10:28 am 
Newbie

Joined: Tue May 10, 2005 10:17 am
Posts: 6
Hi,

I'm using hibernate 3.0.3 with Oracle10g and have the following problem:

I have mapped a legacy table which has no primary key defined. As I understood in this case one could use a composite key referring to all columns. Unfortunately this does not work since there might be duplicate rows.

I tried the configuration of the id as following:
Code:
        <id type="string">
            <column name="ROWID" not-null="true"/>
            <generator class="guid"/>
        </id>


However, this fails because on inserting hibernate tries to update the ROWID column. This fails with an exception (invalid column).

I would like to have something like this: The rowid is used as id when reading . On writing no id has to be written, since this is handled by oracle itself.
The question is: Is this possible with hibernate?

Any help would be appreciated.
Regards,
Andreas


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 12:20 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
you can try mapping rowid with no update option (insert="false",delete and update) and use it
fro select only.I don't try


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 1:37 pm 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
This is going to be really hard to use with Hibernate. If you can, I would just get someone to add a PK column to the table. It won't (shouldn't) affect legacy code, but it will allow you to do what you need to do.

I think the best you could manage would be to specify mutable="false" in the <class> element to avoid inserts and updates, period. You could then map a rowId property to the ROWID "column" which should be okay as long as you are not inserting or updating.

The problem is that Hibernate must have an <id>, and right now you don't have anything that is suitable. There is no way to specify that the ID column be omitted in an insert or update statement, unless you wrote your own Dialect implementation (which is another possibility).

You really need a primary key, especially if the combination of other columns is not necessarily unique.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 7:17 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
primary key is mandatory for relation database


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 9:26 pm 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
jesse_sweetland wrote:
This is going to be really hard to use with Hibernate. If you can, I would just get someone to add a PK column to the table. It won't (shouldn't) affect legacy code, but it will allow you to do what you need to do.

I think the best you could manage would be to specify mutable="false" in the <class> element to avoid inserts and updates, period. You could then map a rowId property to the ROWID "column" which should be okay as long as you are not inserting or updating.

The problem is that Hibernate must have an <id>, and right now you don't have anything that is suitable. There is no way to specify that the ID column be omitted in an insert or update statement, unless you wrote your own Dialect implementation (which is another possibility).

You really need a primary key, especially if the combination of other columns is not necessarily unique.

- Jesse


Sometimes its not that easy. In the company I work for, there is a culture of strong disapproval towards table modification like this. And the reason supplied is that there are 4GL programs which rely on these tables, and expect a certain column ordering & key/s to use. Modifying a table therefore means that heaps of 4GL programs have to be re-compiled, then redistributed to all customer deployment sites along with the table change. Thats a big task, even more so when the table in question is central to a lot of other business processes.

I myself am faced with the problem of mapping a header-detail-detail table where the only available key for the child and grandchild tables are a composite key created from the parent/grandparent PK, plus the index number of the child or grandchild. A composite key like this is very fragile, because as soon as you move children around in the parent's detail list, you essentially change the child's id. The only way to manage this effectively is to delete then re-insert the list of children upon any list modification.

Having rowid available as the id property would be much more effective, because I would not have to rely on a fragile key for updating child rows. Having said that though, surely one could create a custom IdentifierGenerator implementation that handled ROWIDs correctly? I imagine that it would be database specific, but for myself (using mostly Informix) that wouldn't be a problem.

regard,
Scott


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 2:30 am 
Newbie

Joined: Tue May 10, 2005 10:17 am
Posts: 6
Scott wrote:
Having rowid available as the id property would be much more effective, because I would not have to rely on a fragile key for updating child rows. Having said that though, surely one could create a custom IdentifierGenerator implementation that handled ROWIDs correctly? I imagine that it would be database specific, but for myself (using mostly Informix) that wouldn't be a problem.


Yes, such an option would be helpful for me also. As I gather it, currently no direct support of this case is available. Pure reading works in my case (also update and delete), but inserting fails because of the aforementioned problem of setting a value to ROWID.
Another IdentifierGenerator for this case would really be appreciated. I guess there are a lot more problematic legacy tables around :-(

As of the primary key: I would like to add one, but that is not an option, unfortunately.

Regards,
Andreas


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