Shards and JTA

19 views
Skip to first unread message

davidp4web

unread,
Jan 6, 2009, 6:41:39 PM1/6/09
to Hibernate Shards Dev
Has anyone used Hibernate Shards in conjunction with JTA?

The JTA examples I've seen use SessionFactory.getCurrentSession, which
is not supported in ShardedSessionFactory. :-(

My intention is to hide as much of the persistence plumbing as
possible from the view of the application developer (using a DAO
layer). Toward that end, I'm considering JTA (with JBoss), but before
I sink a bunch of time into this, I'd like some assurance that I'm not
running headlong into the abyss.

Examples would be wonderful, though tips and/or words of encouragement
are helpful too. :-)

Thanks!

David

Emmanuel Bernard

unread,
Jan 6, 2009, 7:15:09 PM1/6/09
to hibernate-...@googlegroups.com
you don't need getCurrentSession() it all depends on how you store the
session. which environment are you running on? An EE 5-ish environment?
Anyway, Shards can probably implement getcurrentSession easily.

David Pellegrini

unread,
Jan 6, 2009, 8:02:59 PM1/6/09
to hibernate-...@googlegroups.com
Environment is:
* Java 6
* JBoss AS 5
* Hibernate 3.3

I'm a newcomer to Hibernate and JBoss -- it's the "new technology
direction" for our group, so I'm trying to run up the learning curve as
quickly as possible. I'm basing my architectural choices on what I see
as "best practices" in my reading combined with my own experience.

One source is http://www.hibernate.org/42.html, particularly the
sections "Transaction demarcation with JTA" and "Implementing data
access objects (DAOs)". In addition, "Java Persistence with Hibernate"
also advocates using JTA whenever possible.

Overall, I want to keep the application/business logic as free as
possible from persistence dependencies. So I'm willing to put some extra
effort in at the outset to use available abstractions/frameworks or
build my own. Obviously I'd rather use existing ...

DAOs seemed like a great abstraction, but either need to have a Session
injected, or rely on a
HibernateUtil.getSessionFactory().getCurrentSession() pattern that
doesn't work in Shards. If I'm injecting Sessions into DAOs, I haven't
really bought much isolation from persistence dependencies.

JTA seemed to hold promise in this regard, but I don't know enough about
it yet, hence my question to this esteemed group of experienced
Shard-ers. :-) Is this the right way to go? Or am I chasing after
phantoms? What would constitute best practice at this juncture?

Thanks!

David

Max Ross

unread,
Jan 18, 2009, 4:55:18 PM1/18/09
to hibernate-...@googlegroups.com
As Emmanuel said, you should be able to get ahold of a Session without difficulty even though getCurrentSession() is currently unimplemented.  Somewhere in your app you're going to need to establish a new session, and that code will have a hibernate dependency.  At that point you can inject the Session into your DAO or store it in a ThreadLocal and have your DAO reach out and ask for it when it needs a Session.  Either way, the number and extent of your Hibernate dependencies should be no greater than if getCurrentSession() worked.

Hope this helps,
Max

davidp4web

unread,
Feb 20, 2009, 7:20:22 PM2/20/09
to Hibernate Shards Dev
I had to drop this for a few weeks to concentrate on getting code
out. I still want to use JTA, though, and started this thread with
that focus, but the discussion thus far has not addressed my core
question:
Is anyone using Shards with JTA?
If so, can you share your experience with us?

Thanks!

David
Reply all
Reply to author
Forward
0 new messages