Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Unnati Redkar
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic