• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

updating records, for a table without primary key.

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am using websphere application server and when i give the session.update it does not update the records in database.

and I do not see the SQL statements also.

This particular table does not have the primary key, so my question is if you do not have the primary key for the table, does session.update or session.saveOrupdate will work?


I think the problem is table does not have the primary key.
This table is developed long back and more than 1 application is using this table and I cannot change this table.

And I am using middlegen to generate the mapping files and if you do not have the primary key, it makes all the columns as composite keys and i think we cannot update the keys by giving session.update.

Can somebody suggest others ways to handle this situation, where you do not have primary key and want to update records.
 
srikanth koppisetty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My mapping file is and we are using :- net.sf.hibernate.transaction.WebSphereTransactionManagerLookup

and sample code is


aUser.setLastUpdtById(sysUser);
aUserDAO.update(aUser, session);
session.flush();

---------------------------------------------------


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration SYSTEM
"hibernate-configuration-2.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">
jdbc/oracle/cmis
</property>
<!-- Database Settings -->
<property name="hibernate.dialect">
net.sf.hibernate.dialect.Oracle9Dialect
</property>
<property name="hibernate.jdbc.batch_versioned_data">false</property>
<property name="hibernate.jdbc.batch_size">0</property>
<property name="hibernate.default_schema">ADMN</property>
<property name="hibernate.show_sql">true</property>
<!-- Transaction Settings -->
<property name="hibernate.transaction.manager_lookup_class">
net.sf.hibernate.transaction.WebSphereTransactionManagerLookup
</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<!-- Session Factory Settings -->
<property name="hibernate.session_factory_name">
HibernateSessionFactory
</property>
<!-- Mapping Files - audt_admn schema -->
<mapping resource="xxx/xxx/xxx/audit/domain/AudtHdr.hbm.xml" />

</session-factory>
</hibernate-configuration>
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While the table may not define a primary key constraint, is there a column (or set of columns) that make up a logical primary key? If so, put this in your Hibernate mapping as the ID.

Can you provide the code and mappings so we can help? I don't see any reason why a table where every column makes up a composite ID wouldn't be able to be persisted. Is it an entity by itself, or a component in a collection of another entity?
 
srikanth koppisetty
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for responding back.

I thought you cannot update a primary key in update statement using hibernate, since my mapping tool generated all the column as keys.


Here is my mapping file for class.

--------------------------------------------------------

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM
"hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin

http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->

<class name="xxx.xxx.xxx.scrty.domain.ScrtyUser" table="SCRTY_USER" schema="SCRTY_ADMN">

<composite-id>
<key-property name="userId" column="USER_ID" type="java.lang.String" length="8" />
<key-property name="user1stName" column="USER_1ST_NAME" type="java.lang.String" length="30" />
<key-property name="userLastName" column="USER_LAST_NAME" type="java.lang.String" length="30" />
<key-property name="stusCd" column="STUS_CD" type="java.lang.String" length="1" />
<key-property name="stusDt" column="STUS_DT" type="java.sql.Timestamp" length="7" />
<key-property name="lastUpdtDt" column="LAST_UPDT_DT" type="java.sql.Timestamp" length="7" />
<key-property name="lastUpdtById" column="LAST_UPDT_BY_ID" type="java.lang.String" length="8" />
<key-property name="invldPwCnt" column="INVLD_PW_CNT" type="java.lang.Integer" length="2" />
<key-property name="lockNum" column="LOCK_NUM" type="java.lang.Long" length="16" />
<key-property name="id" column="ID" type="java.lang.Long" length="14" />
</composite-id>


<!-- associations -->

</class>
</hibernate-mapping>
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by srikanth koppisetty:
I thought you cannot update a primary key in update statement using hibernate, since my mapping tool generated all the column as keys.

Sorry, I didn't think that through entirely before posting. Do any of those properties uniquely identify a row in the table? Is userId unique to each row or a combination of fewer properties than the entire table?
 
You didn't tell me he was so big. Unlike this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic