-->
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.  [ 8 posts ] 
Author Message
 Post subject: Auditable; can I save a copy from an Interceptor?
PostPosted: Thu Apr 22, 2004 12:19 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
I would like to implement Auditable so that each time a record is modified a new copy is saved.

I tried the following with interceptor and long sessions:

- from isUnsaved return true for all Auditables, then clear the id from onFlushDirty: isUnsaved() was not called for the entity i passed to the long session's saveOrUpdate(?!), several others were passed... also changing the id results in an exception

- saveOrUpdateCopy (was misled by the name, it's for something else)

- call evict(entity) and save(entity): this approach works, but it only works for root entities, it fails if the entity is saved due to some cascading because it's not implemented in an interceptor.

so my question is: can i achive from an interceptor that entities that implement Auditable and are (directly/indirectly) passed to saveOrUpdate() will automatically be saved into a new row?

thanks in advance,

- 101


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Use a database trigger.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 1:30 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
christian wrote:
Use a database trigger.


trying... but what if i would like to avoid triggers?

it's so close with hibernate, it only needs a little something. it's either me missing it or a few lines are missing from hibernate...

and if there's no other way, and if it's not too offtopic, could someone help me with the ?????? part?

thanks all,

- 101


CREATE OR REPLACE TRIGGER AUDITING
BEFORE UPDATE
ON SITE_QUESTION
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
Declare

rs SITE_QUESTION%rowtype;

Begin

select * into rs from SITE_QUESTION where id = :old.id;

select HIBERNATE_SEQUENCE.nextval into rs.id from dual;

insert into SITE_QUESTION ??????;

End;


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 22, 2004 1:32 pm 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
101 wrote:
insert into SITE_QUESTION ??????;


of course i'm trying to avoid enumerating all columns here...


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 5:06 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
i've decided to open a new session each time i need to save a new copy from the interceptor. this app is not performance critical, so it works fine this way.

but still it would be good to have support for this in hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 5:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
as long as you open the session on the same connection, this is the correct solution and should not harm performance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 8:21 am 
Beginner
Beginner

Joined: Mon Mar 22, 2004 10:01 am
Posts: 22
gavin wrote:
as long as you open the session on the same connection, this is the correct solution and should not harm performance.


hmm... currently i open a new session with a NEW connection. it's in a JCA environment, is there a way to get the calling session from the interceptor?

i have a threadlocale with the session, can i safely assume that Hibernate is single threaded so i can use this threadlocale to access the calling session (to ask for the current sql connection)?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 11:38 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
101 wrote:
gavin wrote:
i have a threadlocale with the session, can i safely assume that Hibernate is single threaded so i can use this threadlocale to access the calling session (to ask for the current sql connection)?

Yes. Actually it depend if your app is "single threaded".
threadSession.connection() and open a new one using a user provided conenction

_________________
Emmanuel


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