-->
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.  [ 7 posts ] 
Author Message
 Post subject: PersistentCollection - why no public getSession()?
PostPosted: Tue May 09, 2006 4:04 am 
Newbie

Joined: Fri May 05, 2006 11:15 am
Posts: 6
Hello!
I have got a flag indicating that permits lazy initialization or else throw an exception (no matter how, lets say FlagHolder.isLIAllowed(Session session)) and I would like a code like this work for me:
Code:
if (value instanceof HibernateProxy) {
    session = ((HibernateProxy) value).getHibernateLazyInitializer().getSession();
} else if (value instanceof PersistentCollection) {
    session = ???
}

However, it is impossible to extract session information from an instance of PersistentCollection in current version of Hibernate (or I did not found any way of doing this?). Searching the net i found that in version 2.1.4 there was public getSession() in PersistentCollection interface, now if it is gone is it illegal to extract such info from PersistentCollection?

Thanks in advance, Marcin

Hibernate version:3.1.3


Last edited by plas on Tue May 09, 2006 5:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 5:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Why would you ever want to access the internal session ?

That sounds like a baad dependency.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 5:38 am 
Newbie

Joined: Fri May 05, 2006 11:15 am
Posts: 6
Well, it sounded innocent to me when I was thinking about it, the only thing I do is checking if a certain flag (my own) is set with session that owns proxy object, like this:
Code:
SessionImplementor session;
// obtain SessionImplementor like in the code above
if (!FlagHolder.isLazyInitAllowed(session)) {
    throw new SorryLazyInitializationIsTurnedOffException();
}
// do rest of code

The availability of HibernateProxy.getHibernateLazyInitializer().getSession() made my hunger of same thing available at PersistentCollection side, so is it all invalid to do?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 6:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
why would lazy initialization ever be associated with the session ?

you mean you check session.isClosed() ?

if yes; why don't you know (from somewhere else) what the current session is ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 6:23 am 
Newbie

Joined: Fri May 05, 2006 11:15 am
Posts: 6
I don't want to check anything that has to do with internal state of session, the flag is just a boolean value held inside my FlagHolder, for example:
Code:
class FlagHolder {
   Set<SessionImplementor> allowedSessions;

   public static boolean isLazyInitAllowed(SessionImplementor session) {
       return allowedSessions.contains(session);
   }
}

Yes, I would like to associate this type of checking with particular sessions, not with my application context for example. And at this level I don't want to check if the session is connected, if not HibernateException will be thrown later.
I could, of course, hold my own session reference inside my objects, but why should I do this if Hibernate does this for me?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 09, 2006 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
your code should not assume any thing about a session being attached to the objects.

btw. how did you get the collection without having the root/parent object?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 2:35 am 
Newbie

Joined: Fri May 05, 2006 11:15 am
Posts: 6
max wrote:
btw. how did you get the collection without having the root/parent object?

I have parent object, as the mechanism I'm trying to develop is in fact nested inside the getter of some child, so access to parent is available. However, I cannot assume that my parent class is instanceof HibernateProxy (because session.list() for example returns such beings that are not proxied instances, but could have uninitialised persistent collections).


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