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.  [ 4 posts ] 
Author Message
 Post subject: EmptyInterceptor
PostPosted: Wed Sep 24, 2008 4:02 am 
Newbie

Joined: Fri Feb 29, 2008 7:05 am
Posts: 13
Location: New Delhi, India
Hi All,

I am stuck at a design issue and I seek the help of the Hibernate experts to guide me in this.

I have got 2 entities A & B. A has got one-to-many with B while B has got many-to-one relationship with A. Entity B's crud operations can only be fired when entity A's crud is fired i.e. user cannot directly affect entity B.

I am thinking of using an EmptyInterceptor to do crud operations when there is a crud operation on the entity A. I am doing this to make sure that B's crud operations are not always fired and they occur only when Hibernate does any crud operation on entity A.

Please let me know if this is the right approach. If not what else can I use, keeping in consideration:

- There can be many operations on B (multiple create, update, delete) when user makes a change to A.
- Changes in B should only happen when there is a change in its parent A.

Regards,
Nitin


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 3:19 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
If B is truly dependent on A (bound by A's life cycle) then you should consider mapping a collection of components. If that's not your cup of tea, then implement cascading life cycle for your association. Perhaps I've missed what you're trying to do; if so please provide an example use case. I don't believe you need any sort of Interceptor here.

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 24, 2008 6:20 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2008 5:44 pm
Posts: 34
My understanding of this is you have some entityA who has a collection of entityB. Users only interact with entityA. When entityA is changed, some changes should be made to entityB.

I think this is more of a general application issue than a hibernate issue. If you design your application in such a way that the object that is wrapping entityA has all the logic needed to update itself (and since it contains a collection of entityB it also knows how to update entityB) then the issue resolves itself before it reaches the hibernate level.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 26, 2008 2:40 am 
Newbie

Joined: Fri Feb 29, 2008 7:05 am
Posts: 13
Location: New Delhi, India
Hi cbredesen, phen0m.

I think I was not able to clearly state my problem. Let me explain you this with an example:

In my application, user can set some schedule preferences. Each schedule preference would mean some notifications to the user. So we have got three entities here: User, Schedule & Notification. When ever user makes a change to his preference, we save the user entity. USER has got cascaded association with the SCHEDULE, so with user update, schedules are also persisted.
When there is a change in the schedule, app is required to calculate all the notifications which are going to result from the respective schedule.

As you see, I need to determine if there is any change in the associated schedules of the user. If there is a change then app can initiate the expensive process of calculating the notifications. I was thinking of implementing this with the help of a interceptor on the Schedule entity. But I had no luck in modifying the collection (of notifications) in the case of onFlushDirty while it is working in onSave

Any help in this would be highly appreciated. Can I use JPA with entity listeners or I can do it with some thing not very fancy?

Regards
Nitin


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.