Error w/Finders createQuery and active transactions...Please help

242 views
Skip to first unread message

Same dude

unread,
Jan 3, 2010, 10:37:22 PM1/3/10
to warp-core
Hello, Im having a dilly of a pickle here trying to get my 1st
transactional warp-persist demonstration running using Finders.

I have a gwt project that already uses Hibernate successfully. The
project is basically just retrieving info from one table for
authentication. Im not eving trying the web aspect of this out right
now. Im trying transactional method first, since this seems the
easiest way to use warp persist.
When I try to run the program I get this error

Exception in thread "main" org.hibernate.HibernateException:
createQuery is not valid without active transaction
at org.hibernate.context.ThreadLocalSessionContext
$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:
338)
at $Proxy7.createQuery(Unknown Source)
at com.wideplay.warp.hibernate.HibernateFinderInterceptor
$FinderDescriptor.createQuery(HibernateFinderInterceptor.java:256)
at com.wideplay.warp.hibernate.HibernateFinderInterceptor.invoke
(HibernateFinderInterceptor.java:68)
at com.google.inject.InterceptorStackCallback
$InterceptedMethodInvocation.proceed(InterceptorStackCallback.java:64)
at com.google.inject.InterceptorStackCallback.intercept
(InterceptorStackCallback.java:44)
at org.webhop.ywdc.login.client.LoginRepository$$EnhancerByGuice$
$76a2c7f1.listall(<generated>)
at org.webhop.ywdc.login.client.Main.main(Main.java:46)

Heres my main method that I use to enstantiate the Injector and do all
my business:

public static void main(String[] args)
{
Injector injector = Guice.createInjector(new LoginModule(),
PersistenceService
.usingHibernate()
.across(UnitOfWork.TRANSACTION)
.buildModule());

LoginRepository lRepository = injector.getInstance
(LoginRepository.class);
Vector<Members> repositoryList = lRepository.listall();

for (Members c : repositoryList)
{
System.out.println(c.getUsername());
}
}

Here is my Repository

@Transactional
public class LoginRepository {


public void LoginRespository(){}

@Inject
Provider<Session> session;

@Finder(query="from Members")
public Vector<Members> listall()
{
return null;
}

Here is my Guice module:

public class LoginModule extends AbstractModule {

@Override
protected void configure()
{
bind(Configuration.class).toInstance(new AnnotationConfiguration
().addResource("hibernate.cfg.xml"));
bind(MyInitializer.class).asEagerSingleton();
//bind(Session.class).asEagerSingleton();
bind(LoginRepository.class).asEagerSingleton();
}

}

Now I dont know why the error report says that createQuery is not
valid without active transaction, because I bound my Initializer class
"MyInitializer" in as an eager singleton just like the warppersist
site said to do, which would make it available when guice started.

heres is that initializer class:

public class MyInitializer {
@Inject
MyInitializer(PersistenceService service)
{

service.start();
}
}

I really really would appreciate a bit of help with this one.

Sincerely,

Coder420

Dhanji R. Prasanna

unread,
Jan 3, 2010, 10:51:06 PM1/3/10
to warp...@googlegroups.com
Hmm That is very strange. It looks like there may be some odd interaction between the DFs and your eager singleton. Try putting @Transactional on the method itself. Or better yet use the interface based Dynamic finders (use addAccessor() in your module instead of bind()). Inject this into your login repository and and just call the interface method in a delegate.

The class-based @Finder is not well supported and not particularly enouraged =(

Also I would recommend not binding anything but your MyInitializer as eager singleton (just bind them as regular Singletons):

bind(LoginRepo.class).in(Singleton.class);

Dhanji.


--

You received this message because you are subscribed to the Google Groups "warp-core" group.
To post to this group, send email to warp...@googlegroups.com.
To unsubscribe from this group, send email to warp-core+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/warp-core?hl=en.



Robbie Vanbrabant

unread,
Jan 4, 2010, 11:41:45 AM1/4/10
to warp...@googlegroups.com
Class-level @Transactional also requires this type of configuration, using forAll (from wideplay.com)

  Injector injector = Guice.createInjector(PersistenceService.usingHibernate()
        .across(UnitOfWork.TRANSACTION)
        .forAll(Matchers.annotatedWith(Transactional.class), Matchers.any())
        .buildModule();

Without this, class-level @Transactional is only used by method-level @Transactional's to get some defaults, so you would still need @Transactional on the method.

Next to that it also seems evil to return Vector. I don't think we have tests that cover that.

Hope this helps,
Robbie
Reply all
Reply to author
Forward
0 new messages