Newbie : help in getting warp to work with JPA

0 views
Skip to first unread message

Prashant

unread,
Jul 27, 2007, 9:45:22 AM7/27/07
to warp-core
Hello:

I think dynamic finders is a smashing idea.

I am having couple of problems with getting this to work.

1. SVN check out of warp does not checkout the code completely.
This is the error i get.
A warp-persist/warp-persist/lib/hsqldb.jar
svn: REPORT request failed on '/svn/!svn/vcc/default'
svn: REPORT of '/svn/!svn/vcc/default': 200 OK (http://warp-
persist.googlecode.com)

Fortunately warp/dist is checked out by this time and this directory
has the warp-persist.jar, so I can still hack on...

2. (This problem may be Guice related and not Warp related. I am new
to Guice also, so please bear with me.)

I code up a simple Entity, setup persistence.xml in META-INF in the
classpath.
Next I create a module to bootstrap the persistence unit and start
JPA

public class Startup extends AbstractModule
{

public static void main(String[] args)
{
Injector injector = Guice.createInjector(new Startup());

EntityA person = new EntityFinder().createNewPerson();
System.out.println("person = " + person);
}
protected void configure()
{
bindConstant().annotatedWith(JpaUnit.class).to("warp-
persistence-unit");
Injector injector = Guice.createInjector(
PersistenceService.usingJpa()
.buildModule());

}

@Singleton
public class MyInitializer {

@Inject MyInitializer(PersistenceService service) {
System.out.println("Startup$MyInitializer.MyInitializer About
to start JPA");
service.start();
//at this point JPA is started and ready

}

}
}

But when i run this I get a run time error :

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

1) Error at com.wideplay.warp.jpa.JpaPersistenceService.<init>(Unknown
Source):
Binding to java.lang.String annotated with
@com.wideplay.warp.jpa.JpaUnit() not found. No bindings to that type
were found.

1 error[s]
at com.google.inject.BinderImpl.createInjector(BinderImpl.java:277)
at com.google.inject.Guice.createInjector(Guice.java:79)
at com.google.inject.Guice.createInjector(Guice.java:53)
at com.google.inject.Guice.createInjector(Guice.java:43)
at warp.Startup.configure(Startup.java:36)

What am i doing wrong ?
bindConstant().annotatedWith(JpaUnit.class).to("warp-
persistence-unit");

does happen before

Injector injector = Guice.createInjector(
PersistenceService.usingJpa()
.buildModule());

Why is Guice not able to pick this binding up ?

Thank you.
-Prashant

Dhanji R. Prasanna

unread,
Jul 27, 2007, 10:05:11 AM7/27/07
to warp...@googlegroups.com
Hi,

The problem is that you are creating 2 injectors and binding the configuration in one and the warp persistence support in the other.
You need to create just one injector:


public static void main(String[] args)
   {
       Injector injector = Guice.createInjector(new Startup(), PersistenceService.usingJpa().buildModule());
   }


And also you cannot use the "new" operator to obtain instances of dynamic finders, instead use injector.getInstance() or simply @Inject them as services into your managed objects.

Dhanji.

@com.wideplay.warp.jpa.JpaUnit () not found. No bindings to that type
Reply all
Reply to author
Forward
0 new messages