-->
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: dynamcally avoiding update of a column
PostPosted: Mon Feb 19, 2007 9:21 pm 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
Hibernate version: 3.2

Name and version of the database you are using: Oracle

I've been asked to implement i18n of some data columns.

I'm looking at using interceptors, event listeners, etc, in Hibernate to do this.

Briefly, we've created a new Translation table, which has columns like EntityName, EntityId, PropertyName.

If a column being updated appears in the registry of translatable columns then our Hibernate EventListener inserts/updates a row in the Translation table.

This works fine. The Translation table seems to be maintained correctly.

My question is, if I want the original table to retain the native translation, which will be for the en_AU locale, how do I get Hibernate to exclude various properties from update statements?

I've been playing around with specifying a persister attribute in my mapping <class> definition, where the persister is a subclass of org.hibernate.persister.entity.SingleTableEntityPersister but feel like i'm banging my head against the wall a bit.

Specifically, I've tried to override the update method, and thought I could possibly modify the boolean[] includeProperty array but the SQL statement for the update has already been built at this time so its the wrong spot to override.

Any ideas?

Is there some nice excludePropertyFromUpdate() template method I can override somewhere?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 20, 2007 7:41 pm 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
ok, just to answer my own question, i've done the following...

In my custom entity persister, which extends SingleTableEntityPersister I call

Object[] databaseSnapshot = entityPersister.getDatabaseSnapshot(((Part) object).getId(), session);

to get the original object values.

To prevent a column being updated I can conditionally copy a value from the databaseSnapshot back over the top of the Object[] fields array, which still means that the database update will proceed, but it will just write the original value back into the table.

pseudo code for what I'm doing is.

if( saving changes in the application's native locale ) {

allowNormalUpdateToOccur();
// also don't update translation table

} else {

preventUpdateToTranslatableColumnsInTable();
saveOrUpdateRowToTranslationTable();
}


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.