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