-->
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.  [ 2 posts ] 
Author Message
 Post subject: How to update a record in a table with no primary key
PostPosted: Fri Feb 10, 2006 7:47 am 
Newbie

Joined: Fri Feb 10, 2006 2:29 am
Posts: 1
Hello Everyone,

I have a table with no primary key. I don't have control over the database. All the fileds in the table can only act as primary key.
When i generate .hbm.xml file by using reverse engineering mechanism provided in eclipse, here is the generated .hbm.xml file.
In this case when i try to update a record in the table, i am not able to update using hibernate.

[u][b]Emp1.hbm.xml[/b][/u]

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Feb 10, 2006 12:26:48 PM by Hibernate Tools 3.1.0 beta1JBIDERC2 -->
<hibernate-mapping>
<class name="com.adp.es.fsa.test.Emp1" table="EMP1" schema="SCOTT">
<composite-id name="id" class="com.adp.es.fsa.test.Emp1Id">
<key-property name="empno" type="short">
<column name="EMPNO" precision="4" scale="0" />
</key-property>
<key-property name="ename" type="string">
<column name="ENAME" length="10" />
</key-property>
<key-property name="job" type="string">
<column name="JOB" length="9" />
</key-property>
<key-property name="mgr" type="short">
<column name="MGR" precision="4" scale="0" />
</key-property>
<key-property name="hiredate" type="date">
<column name="HIREDATE" length="7" />
</key-property>
<key-property name="sal" type="big_decimal">
<column name="SAL" precision="7" />
</key-property>
<key-property name="comm" type="big_decimal">
<column name="COMM" precision="7" />
</key-property>
<key-property name="deptno" type="byte">
<column name="DEPTNO" precision="2" scale="0" />
</key-property>
</composite-id>
<many-to-one name="dept1" class="com.adp.es.fsa.test.Dept1" update="false" insert="false" fetch="select">
<column name="DEPTNO" precision="2" scale="0" />
</many-to-one>
</class>
</hibernate-mapping>


Please tell me some solution to update a record in this scenario.

Thanks
Ravi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 8:00 am 
Newbie

Joined: Tue Oct 25, 2005 12:28 pm
Posts: 18
Location: London
Ravi,
the table is broken if there is no PK.

Suggest you use JDBC and not Hibernate, since Hibernate is not designed to accomodate broken databases.

Another approach is to set each field as part of a composite-id - I see this is done already - presumably middelgen generated this for you? Note there will be scalability issues if you use this approach.

Please paste a stacktrace or error message so I can see what is happening when you try to update. Also give me the code you are trying to update with.

Can JDBC be used for this?

_________________
Cheers,
MikeR


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