PersistenceService not found. No bindings to that type were found

21 views
Skip to first unread message

Kelly Davis

unread,
Dec 4, 2007, 11:16:23 AM12/4/07
to warp-core
I am trying to try to warp persist with jpa. I have the following:

public class InitializerJpa
{
private final Log log = LogFactory.getLog( getClass());

private final PersistenceService service;

@Inject
InitializerJpa(PersistenceService service)
{
this.service = service;
service.start();
log.info("JPA Persistence Service started...");
}
}

public class ServiceModule extends AbstractModule
{
@Override
protected void configure()
{
bindConstant().annotatedWith(JpaUnit.class).to("DLXPU");
bind(InitializerJpa.class).asEagerSingleton();
}
}

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

Main main = injector.getInstance(Main.class);
main.go();
}
}

When I run Main, I get the following exception:

Exception in thread "main" com.google.inject.CreationException: Guice
configuration errors:

1) Error at
edu.duke.fuqua.dlx.util.InitializerJpa.<init>(InitializerJpa.java:25):
Binding to com.wideplay.warp.persist.PersistenceService not found. No
bindings to that type were found.

1 error[s]
at com.google.inject.BinderImpl.createInjector(BinderImpl.java:
465)
at com.google.inject.Guice.createInjector(Guice.java:96)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at test.Main.main(Main.java:171)

I am trying to follow the sample code pretty closely, so I am having
trouble getting an understanding of why this is happening. It looks
like there isn't a binding for PersistenceService, but none of the
examples show the a binding needs to be set in the user defined
module, so I am assuming it happens in the module created by
PersistenceService when I create the Injector. The only thing that may
be different is that I am using a recent snapshot of guice.

Thanks,

Kelly

Dhanji R. Prasanna

unread,
Dec 4, 2007, 4:31:04 PM12/4/07
to warp...@googlegroups.com
Hi Kelly

No you certainly don't need to bind PersistenceService yourself, it
should be available to the injector once you pass in the module from
PersistenceService.usingJpa()..buildModule(). I'm not sure I can tell
what is happening from the code you have--can you post the entire Main
class including the go() method?

I tried this quick and dirty test and it worked for me:

injector = Guice.createInjector(
new AbstractModule() {

protected void configure() {
//tell Warp the name of the jpa persistence unit

bindConstant().annotatedWith(JpaUnit.class).to("testUnit");
}
},
PersistenceService.usingJpa()
.across(UnitOfWork.TRANSACTION)
.transactedWith(TransactionStrategy.LOCAL)
.buildModule());

//startup persistence
injector.getInstance(PersistenceService.class)
.start();

There isn't anything different here to your code, semantically. So I'm
not sure what it is. I even tried a version with the InitializerJpa
exactly as you have it. One thing you could try is looking at the
warp-persist unit tests and compare if you are doing anything
differently?

As you say it may be the newer snapshot of Guice, I will grab it and
re-test to make sure. To be on the safe side, can you try it with
Guice 1.0? The latest source versions appear to be unstable..

Dhanji.

Kelly Davis

unread,
Dec 4, 2007, 6:34:26 PM12/4/07
to warp-core
Hi Dhanji, Thanks for your reply. I switched back to Guice 1.0 and it
worked. Thanks for your help, Kelly
Reply all
Reply to author
Forward
0 new messages