-->
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: Configuring CompositeUserType with external info
PostPosted: Thu Jul 21, 2005 11:14 am 
Newbie

Joined: Thu Jul 21, 2005 10:48 am
Posts: 7
Hi,

I have a question about the CompositeUserType.
Cosider the following situation:
In the tables in my DB I have a field that stores the ID of the user, that created the record. The information for that ID is in separate class.
If I create a CompositeUserType for that field, how can I pass the object, that holds the ID info to that CompositeUserType. Maybe somehow using the SessionImplementor parameter, passed to nullSafeGet/Set.


Regards,
Sith


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:29 am 
Newbie

Joined: Thu Jul 21, 2005 10:48 am
Posts: 7
The idea behind this is that I want to have a common type for fields with the same semantics. And most of these fields are system field.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 7:35 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
the CompositeUserType creates that Object which contains the ID and returns it.
There's a good example in HiA.

For example in the "nullsafeget"-Method you won't return an "int" or "long" but a Object called "CreatorID" ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2005 9:20 am 
Newbie

Joined: Thu Jul 21, 2005 10:48 am
Posts: 7
OK, obviously I was not completely clear.
The idea in this case is mainly when I want to set a value to that field, but I have to get the value from external oblect. In this case the ID of the user. How can I pass this external object to the UserType ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 2:32 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
okay ... now i understand ...

I need something similar for Audit-Logs and i'm using a ThreadLocal to provide access to such information, but i'm setting the UserID before calling "session.save" ... but you can (of course) access it from your UserType, too.

HiH
curio


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 10:59 am 
Newbie

Joined: Thu Jul 21, 2005 10:48 am
Posts: 7
This can be possible, but I'm not sure if it will work.
I have to check how Tomcat and Hibernate handle threads. Not to mention that I have Spring in between.
I can set the ThreadLocal variable in the user initial thread, when the user logs-in. I'm not sure in which thread Hibernate will execute. Is it the same, or it even can execute in the thread of another user ?
This can lead to very nasty problems.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 2:43 pm 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
it should be no problem ...
as far as i know Tomcat has a seperate Thread for each request ... therefore it's necessary to provide the information to each thread (request) ...
It works perfectly in combination with the HibernateSession ... so i think it should be no problem with a UserType ...

It's a long time ago i've used Spring, but i couldn't imagine that they're opening new threads ...

gtx
curio


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:12 am 
Newbie

Joined: Thu Jul 21, 2005 10:48 am
Posts: 7
I'll try it anyway. Hope it works.
Thanks


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.