[Persistence, JBoss/CMP, Hibernate, Database] - Re: Hibernate - Unable to locate current JTA transaction
by bmcgovern
I seemed to get around it with the following code.
But does anyone know if im on the right track here? Is openSession() worse than getCurrentSession()?
Session hsession = null;
| try {
|
| InitialContext ctx = new InitialContext();
|
| //UserTransaction tx = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
| //tx.begin();
| SessionFactory factory = (SessionFactory) ctx.lookup("java:/teenfit/TeenFitDataSessionFactory");
| hsession = factory.openSession();
|
| // Session hsession =
| // TeenFitHibernateUtil.getSessionFactory().getCurrentSession();
| // zTransaction = (Transaction)new
| // InitialContext().lookup("java:comp/UserTransaction");
|
| //Transaction t = hsession.getTransaction();
| // System.out.println("**TRANSACTION FOUND**:: tx = " + tx.toString());
| System.out.println("**TRANSACTION FOUND**:: session = " + hsession.getTransaction().toString());
| hsession.getTransaction().begin();
|
| hsession.saveOrUpdate(HibernateTFUser);
| hsession.saveOrUpdate(HibernateTFUser2);
|
| hsession.getTransaction().commit();
|
|
| //tx.commit();
|
| }catch (Exception zEX){
| System.out.println("Eception:" + zEX.toString());
| hsession.getTransaction().rollback();
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3980824#3980824
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3980824
19 years, 6 months
[JBoss Seam] - All injections are disinjected when used in a component with
by zzjb
When I use @In and @Unwrap in the same seam component, all the injections are null (at least in the @unwrap method).
Seems in BijectionInterceptor class, all be disinjected just after inject to the component.
@AroundInvoke
public Object bijectTargetComponent(InvocationContext invocation) throws Exception
{
if ( getComponent().needsInjection() ) //only needed to hush the log message
{
if ( log.isTraceEnabled() )
{
log.trace("injecting dependencies of: " + getComponent().getName());
}
getComponent().inject( invocation.getTarget(), !isLifecycleMethod( invocation.getMethod() ) );
}
Object result = invocation.proceed();
if ( getComponent().needsOutjection() ) //only needed to hush the log message
{
if ( log.isTraceEnabled() )
{
log.trace("outjecting dependencies of: " + getComponent().getName());
}
getComponent().outject( invocation.getTarget(), !isLifecycleMethod( invocation.getMethod() ) );
}
if ( getComponent().needsInjection() ) //only needed to hush the log message
{
if ( log.isTraceEnabled() )
{
log.trace("disinjecting dependencies of: " + getComponent().getName());
}
getComponent().disinject( invocation.getTarget() );
}
return result;
}
It works fine with components which do not have @Unwrap. Does anyone have idea about this? Thanks a lot.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3980816#3980816
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3980816
19 years, 6 months