On 27/08/2010 5:30 PM, glassfish_at_javadesktop.org wrote:
> Hi there.
> I've been using Hibernate + JPA for a few months. I use application managed transactions, which means that I manually start and commit(or rollback) transactions.
>
> Now, I want to use Glassfish EntityManager instead of Hibernate
Glassfish's JPA implementation is EclipseLink, another persistence
provider like Hibernate. It's not part of glassfish as such, just
bundled, and like Hibernate it can be used elsewhere.
You can have Hibernate, EclipseLink, or any other JPA provider you
choose running within Glassfish, doing container-managed transactions.
So you don't actually have to drop Hibernate if you don't want to.
Glassfish's update tool can install Hibernate in Glassfish for you, so
you don't even need to bundle it in your app's jar/war/ear.
Ideally you can use whatever JPA2 provider the container has
pre-installed, so your app would work with Hibernate on JBoss and
EclipseLink on Glassfish, for example. Amazingly, it actually seems to
work - I switched my code from Hibernate to EclipseLink without changing
anything except my persistence.xml the other day.
> and thus I want it to automatically manage transactions; to achieve this I understand that I have to change a setting in the persistence unit to JPA.
Are you currently using Hibernate via the javax.persistence
(EntityManager, etc) APIs? Configured by persistence.xml?
Or are you using Hibernate's Session, etc directly in your code, and
configuring Hibernate with its own provider-specific config files?
> But what I really need to understand is how Glassfish+JTA manages transactions: how does it know when to begin them? How does it know where to end them?
I've found it hard to understand that myself, at times. When using JSF2
it's linked to the phases of processing in the request lifecycle, but
with things like JAX-RS calls or remote EJB access I have no idea.
How will you be using your persistence code? Is it driving a web
interface - and if so, using what technologies?
> This is not clear to me; I would be very grateful if you could point to any good documentation on this topic.
Me too. The Java EE 6 tutorial helps a bit, though.
(Admittedly I haven't read the EJB3.1 spec properly yet...)
--
Craig Ringer
Tech-related writing at http://soapyfrogs.blogspot.com/