-->
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.  [ 1 post ] 
Author Message
 Post subject: BusinessKey, a nice rule and Cascading
PostPosted: Thu Apr 12, 2007 3:47 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 3:26 am
Posts: 35
Location: Germany
Hi!

I'm using the newest Hibernate release in a standalone application.

All of my entities have a businessKey. Entities in the database are identical, if two businessKeys are identical. This means that if an entity with the businessKey "xyz" exists and an entity with the same businessKey should be persisted, the already persistent entity should be updated.

I wrote a method which implements this behaviour:
<pseudocode>
Code:
private void saveOrUpdate(Session session, BaseEntity baseEntity) {
        BaseEntity tmp = getEntityForBusinessId(baseEntity.getClass(),baseEntity.getBusinessId());

        if (tmp != null) {
            session.evict(tmp);
            //Adopt id and version which are set by hibernate
            //Other fields like (for example) username are not overwritten
            baseEntity.initDatabaseFieldsFrom(tmp);
        }
       
        session.saveOrUpdate(baseEntity);
    }

</pseudocode>

Every entity is persisted with the method above and it works fine. But unfortunately, due to this method, I can't use cascading, because cascading would bypass this method.

Is there an elegant way how I could implement the behaviour so that I will be able to use cascading?


Thanks for help
hoeft


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.