Hi Alan,

That indeed seems like a tricky problem. You cannot use the primitive
service model (which would have solved the problem because there would
be no wrapping proxy) as Hibernate sessions are not thread safe, nor
can you declare the implementation class SessionImpl as the HiveMind
service's interface as that class is final.

I think you should either declare the Hibernate SessionFactory as a
HiveMind service and inject that, or you could also define an
interface in your application which inherits from Session and
SessionImplementation and then use that to define your HiveMind
service. James, what do you think?

HTH,

--knut

On 4/4/07, Alan Chaney <[EMAIL PROTECTED]> wrote:
Hi

I've based my Hivemind/Hibernate code on James Carman's excellent
example. I am using this in a new project in preference to the Spring
Hibernate framework because its simpler and easier to understand IMHO.
However, I've hit one slight snag. In part of my code I use a Hibernate
DetachedCriteria object which gets associated with a session by a
Hibernate call such as
DetachedCriteria dc = DetachedCriteria.forClass(MyClass.class);

(and then, much later inside the DAO)

Criteria cc = dc.getExecutableCriteria(Session session);

where session has been injected by Hivemind. However, it seems that
Hivemind injects a proxy and getExecutableCriteria casts to a
SessionImplementor and cannot cast the Hivemind created proxy giving me:

java.lang.ClassCastException: $Session_111be7b3773
    at
org.hibernate.criterion.DetachedCriteria.getExecutableCriteria(DetachedCriteria.java:51)
    ...

Is there any way to obtain the 'real' Session object from the proxy? Or
can anyone suggest another way to solve this problem. I looked at the
Spring equivalent which uses a special method within the Spring
HibernateTemplate class but I got lost trying to understand how the
HibernateCallback overcame this problem.

Thanks

Alan Chaney


Reply via email to