aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved " Watch "Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved " New topic
Author

Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved

Unnati Redkar
Greenhorn

Joined: May 14, 2007
Posts: 5
Hi,

I have a view (used to ONLY fetch and display data) and table (used for INSERTS and UPDATES)

Following is the mapping in hibernate mapping file , both table and view are mapped to same POJO but underlying table are different.
<class
name="com.common.to.AccountTO" entity-name="AccountTOView"
table="ACCOUNT"
lazy="true"
>
-------------------------
<class
name="com.common.to.AccountTO" entity-name="AccountTO"
table="CST_HDR"
lazy="true"
>

When i do a batch update (Object update -HibernateSession.update(AccountTO, obj); ) , few records get updated OK and then hibernate throws following exception :

cannot modify a column which maps to a non key-preserved table
2011-05-14 23:09:49,320 INFO [STDOUT] 14 May 2011 23:09:49,305 [DefaultQuartzScheduler_Worker-5] ERROR org.hibernate.event.def.AbstractFlushingEventListener []: Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: could not update: [AccountTOView#452283]


Am using Spring's HibernateTemplate to do the update.

Any directions to get rid off this exception will be a great help, looks like a weird behaviour, since few records are updated fine.
Is it hibernate session behaviour which is looking for AccountTOView even when update should be ideally done via AccountTO which is mapped to CST_HDR table ?

Thanks

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved