wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate batch update via a table, throws cannot modify a column which maps to a non key-preserved
 
Similar Threads
Hibernate- one-to-many association on a foreign key
Eager Fetching a Polymorphic SET
1-to-M mapping confusion
Need many-to-one mapping help
Hibernate supports for PK