Status of Guice and persistence support

95 views
Skip to first unread message

Michael Ballantyne

unread,
Oct 10, 2010, 9:30:05 PM10/10/10
to google-guice
Hello All,

I am considering porting part of a project to Guice and will be
needing to use JPA or hibernate. Currently we are using EJBs with
injected EntityManager and transactions, but we want to move away from
EJBs so we can move from an EAR on jboss to a tomcat WAR. Along the
way, we want to make fuller use of dependency injection and make
development nicer.

What can guice provide? I noticed that the development version
includes guice-persist, and also that warp-persist exists for some
current version (1 or 2?), but appears unmaintained. I am not sure
what I should select that will be usable now and maintained in the
future. Also, at current we are currently using some features of
Hibernate included only in JPA 1, not 2. Is JPA 2 supported by any of
the options?

Any suggestions / hints?

Thanks,
Michael Ballantyne

Dhanji R. Prasanna

unread,
Oct 11, 2010, 5:24:52 AM10/11/10
to google...@googlegroups.com
Hi,

Guice persist at trunk is more or less stable. Warp persist has been superceded by it. You can use a snapshot build, it should be fine for the foreseeable future.

We support @Transactional, injecting the EntityManager and many other features: 

We support JPA 1 and 2 but nothing special for 2.

Dhanji.


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


Josh Kamau

unread,
Oct 13, 2010, 4:34:45 AM10/13/10
to google...@googlegroups.com
Hi team;

1 .Does Guice-persist have support  for hibernate? it used to be there in warp-persist.

2. How can i get guice-persist with maven? do i have to compile it from the code? Can i use guice-persist with Guice 2.0?

Kind regards.

Josh

Dhanji R. Prasanna

unread,
Oct 13, 2010, 4:59:08 AM10/13/10
to google...@googlegroups.com
On Wed, Oct 13, 2010 at 7:34 PM, Josh Kamau <joshn...@gmail.com> wrote:
Hi team;

1 .Does Guice-persist have support  for hibernate? it used to be there in warp-persist.

Yes, it is supported via JPA.
 
2. How can i get guice-persist with maven? do i have to compile it from the code? Can i use guice-persist with Guice 2.0?

There are no poms yet, but Stuart might be able to point you in the right direction--the maven guys maintain a version of Guice called sisu-guice which has maven poms I believe.

Dhanji.

Josh Kamau

unread,
Oct 13, 2010, 5:27:44 AM10/13/10
to google...@googlegroups.com
Danji;

Does it mean the support for Hibernate api has been dropped? I didnt want to use the EntityManager api but native hibernate.

regards.

--

Dhanji R. Prasanna

unread,
Oct 13, 2010, 5:30:22 AM10/13/10
to google...@googlegroups.com
On Wed, Oct 13, 2010 at 8:27 PM, Josh Kamau <joshn...@gmail.com> wrote:
Danji;

Does it mean the support for Hibernate api has been dropped? I didnt want to use the EntityManager api but native hibernate.

Yes, that is correct. The hibernate team themselves are also moving in this direction, so I felt it was the logical choice.

Dhanji.

Stuart McCulloch

unread,
Oct 13, 2010, 6:19:52 AM10/13/10
to google...@googlegroups.com
you can find latest snapshots at:


you'll need to add https://repository.sonatype.org/content/groups/forge as a snapshot repository

if you want to use guice-persist with guice 2.0 then you'll probably also want to exclude the org.sonatype.sisu:sisu-guice dependency so you can replace it with the official guice 2.0 dependency in your pom (there are other dependencies you might want to exclude - I'm still tidying up the relevant versions and scopes)

HTH
 
Dhanji.

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



--
Cheers, Stuart

Josh Kamau

unread,
Oct 13, 2010, 6:34:16 AM10/13/10
to google...@googlegroups.com
Thanks Stuart;

Am adding the dependency right away.

regards.
Josh

jon stevens

unread,
Oct 17, 2010, 7:31:59 PM10/17/10
to google-guice
Hi all,

I'm new to guice and guice-persist. I just got guice-persist
integrated into a war based project sitting on top of Tomcat 6. Seems
to work brilliantly. On my laptop, Tomcat starts up in 2 seconds which
includes starting hibernate and connecting to the database.

A couple notes so far:

http://code.google.com/p/google-guice/wiki/JPA
JpaModule should be JpaPersistModule

I'd really like to be able to instantiate my own EntityManager
implementation (I add a few handy methods to mine). Haven't figured
how to do that quite yet. What I do right now is @Singleton a bean
that wraps a @Inject EntityManager. Works well enough, but it would be
nice to be able to do this more cleanly.

I really wish there was more lifecycle support in guice (specifically
@PostConstruct/@PreDestroy) for my beans. I know James S did some work
with guiceyfruit, but it seems like it is a dead project. I'm looking
next into seeing how hard it will be to just put weld into the mix.

cheers,

jon


On Oct 10, 6:30 pm, Michael Ballantyne <michael.ballant...@gmail.com>
wrote:

Dhanji R. Prasanna

unread,
Oct 17, 2010, 10:25:52 PM10/17/10
to google...@googlegroups.com
On Mon, Oct 18, 2010 at 10:31 AM, jon stevens <latc...@gmail.com> wrote:
Hi all,

I'm new to guice and guice-persist. I just got guice-persist
integrated into a war based project sitting on top of Tomcat 6. Seems
to work brilliantly. On my laptop, Tomcat starts up in 2 seconds which
includes starting hibernate and connecting to the database.

Thanks for the kind words! Glad it's working nicely for you.
 

A couple notes so far:

http://code.google.com/p/google-guice/wiki/JPA
JpaModule should be JpaPersistModule

Fixed, thanks!
 

I'd really like to be able to instantiate my own EntityManager
implementation (I add a few handy methods to mine). Haven't figured
how to do that quite yet. What I do right now is @Singleton a bean
that wraps a @Inject EntityManager. Works well enough, but it would be
nice to be able to do this more cleanly.

Hmm, we deliberately don't proxy (or allow proxying) EntityManager coz it may create problems with spec compatibility. But you could presumably create your own version of JpaPersistModule where you bind a proxy instead.
 
I really wish there was more lifecycle support in guice (specifically
@PostConstruct/@PreDestroy) for my beans. I know James S did some work
with guiceyfruit, but it seems like it is a dead project. I'm looking
next into seeing how hard it will be to just put weld into the mix.

Yea, one issue here is the Guice team has not been able to agree on the ideal solution for lifecycle (this debate has been ongoing since 2007). So as an alternative, Bob created the TypeListener system that enables things like guiceyfruit without directly implementing them.

Dhanji.

jon stevens

unread,
Oct 18, 2010, 5:08:00 PM10/18/10
to google-guice
> Yea, one issue here is the Guice team has not been able to agree on the
> ideal solution for lifecycle (this debate has been ongoing since 2007). So
> as an alternative, Bob created the TypeListener system that enables things
> like guiceyfruit without directly implementing them.

Yea, unfortunately guiceyfruit is no longer really developed and it
isn't compatible with latest guice (the @PreDestroy stuff throws an
illegalstateexception when gf tries to use some internal guice api's).

Sadly, I've come to the conclusion that while I love guice/guice-
persist, in order to be all enterprisey, I'm also going to want what
amounts to container managed transactions and solid lifecycle support
like what JBoss (and Spring) provides. Your @Transactional is very
nice, but just not enough.

I used to be a big fan of JBoss, but have long since tired of waiting
24seconds+ just for the default container to start up without anything
even installed (yes, that is the latest release of jboss6). I'm now
experimenting with a bare spring+tomcat solution, but I feel like
spring is kind of a dead end and only just recently starting to 'get'
annotations.

In summary, what I'd love is a single product that has:

Tomcat/War based deployment
guice-servlet style configuration
Hibernate/JPA/Entities
@Stateless/@Statefull bean support
Expose my bean methods via JMX with simple annotations
Transactions that support RequiresNew and timeouts
@Inject/@Provides (guice/cdi/jsr299)
@PostContruct/@PreDestroy
jax-rs support (ala: resteasy)
A startup time of under 5 seconds on my laptop for a relatively simple
application.

Is that too much to ask for? ;-)

jon

Hani Suleiman

unread,
Oct 18, 2010, 5:19:28 PM10/18/10
to google...@googlegroups.com

On Oct 18, 2010, at 10:08 PM, jon stevens wrote:

>> Yea, one issue here is the Guice team has not been able to agree on the
>> ideal solution for lifecycle (this debate has been ongoing since 2007). So
>> as an alternative, Bob created the TypeListener system that enables things
>> like guiceyfruit without directly implementing them.
>
> Yea, unfortunately guiceyfruit is no longer really developed and it
> isn't compatible with latest guice (the @PreDestroy stuff throws an
> illegalstateexception when gf tries to use some internal guice api's).

I apologise in advance for what I'm about to say, as clearly advocating one project in another's mailing list is bad form but....

Spring does pretty much what you need. Just use annotation scanning, and you're all set. Resteasy and co all hook into Spring and aren't invasive at all, and you also don't have to use custom frameworks maintained by a random guice enthusiasm who might or might not get bored with trying to make it play nice without polluting the pristine NIH 'core'. Additionally, Spring doesn't suffer from the elitism/purity mindset that guice does.

Guice is ideal for projects where you need DI and just DI (I use it for a lot of enterprise projects that don't require exposing as web services, have no web views, and have few third party dependencies). If you want to play nice with any other Java framework, it's a bad bet due to the mentality of 'google shall not pollute its code with open source/standards based filth'.

Sorry Bob, don't be mad at me!


Ales Justin

unread,
Oct 18, 2010, 5:20:25 PM10/18/10
to google...@googlegroups.com
> I used to be a big fan of JBoss, but have long since tired of waiting
> 24seconds+ just for the default container to start up without anything
> even installed (yes, that is the latest release of jboss6).

Dunno what kind of machine you have,
but on my simple laptop (almost 1y old plain MacBP) the last JBoss6_m5 takes ~15sec to boot.

Considering you have all of JavaEE6 stuff up & ready (Weld, JPA2, JSF2, Rest, ...)
I would say that's not too bad.

I do admit we did not do our best for early JBoss5, but we did fix a bunch of stuff for JBoss6.
And hopefully we'll get that running even faster for GA release.

-Ales

p.s.: I lead the JBoss Microcontainer project ;-)


jon stevens

unread,
Oct 18, 2010, 6:58:04 PM10/18/10
to google-guice
./bin/run.sh
15:47:33,190 INFO
[org.jboss.bootstrap.impl.base.server.AbstractServer] JBossAS
[6.0.0.20100911-M5 "Neo"] Started in 22s:430ms
macbook pro. 10.6.4, i7 @ 2.66ghz , 8gigs ram (ie: a pretty beefy
laptop)

That is just a straight download of m5 with nothing else installed.

I've almost got spring all integrated with my little setup on top of
tomcat based on my previously stated desires. Tomcat says: INFO:
Server startup in 2242 ms (and that includes also starting up guice
too!)

I'm glad you are working on improving the speed. Thank you! Please
don't take my statements as a slight. I spent 4 years building a
massive traffic porn site entirely on top of jboss 4 and was very
happy with the overall performance. But, I've seen the light with fast
startup times and I'm just not going to accept anything slower than
5s. Even Resin 4 starts up in a couple seconds and it supports
javaee6. There really is more work to be done.

jon

Ales Justin

unread,
Nov 24, 2010, 10:32:18 AM11/24/10
to latc...@gmail.com, google...@googlegroups.com
Jon, I guess this info will make you use JBoss again. :-)
* http://in.relation.to/Bloggers/Podcast15JBossApplicationServer7IsLookingShockinglyGood

Jon Stevens

unread,
Nov 24, 2010, 12:00:14 PM11/24/10
to Ales Justin, google...@googlegroups.com
08:58:31,927 INFO  [org.jboss.as.server] (pool-1-thread-2) JBoss AS 7.0.0.Alpha1 "Halloween" started in 9352ms. - Services [Total: 150, On-demand: 7. Started: 143]

Not bad! Thanks!

jon
Reply all
Reply to author
Forward
0 new messages