-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to use Tomcat + Hibernate + JPA?
PostPosted: Fri Feb 12, 2010 4:15 am 
Newbie

Joined: Fri Jun 19, 2009 9:31 am
Posts: 12
Maybe a very basic question: How to use Tomcat + Hibernate + JPA?

Currently, I'm using Tomcat with plain hibernate with a ServletContextListener that initializes the hibernate configuration programmatically and a one-session-per-request approach as described here https://www.hibernate.org/43.html.

Is there an easy way to enable to use tomcat and hibernate inside of JPA or do I need a full J2EE server to do so?


Top
 Profile  
 
 Post subject: Re: How to use Tomcat + Hibernate + JPA?
PostPosted: Mon Feb 15, 2010 7:10 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Is there an easy way to enable to use tomcat and hibernate inside of JPA or do I need a full J2EE server to do so?


You absolutely don't need a J2EE server to use hibernate with JPA approach within tomcat.
Just deploy your hibernate application as servlet within tomcat.

N.B.: Maybe you are confusing JPA with JTA ? (JTA is usually used on J2EE servers)


Top
 Profile  
 
 Post subject: Re: How to use Tomcat + Hibernate + JPA?
PostPosted: Mon Feb 15, 2010 5:52 pm 
Newbie

Joined: Fri Jun 19, 2009 9:31 am
Posts: 12
Thanks for your answer and yes, maybe I'm confused :)

In this post (https://forum.hibernate.org/viewtopic.php?f=1&t=1000680) I asked why the callbacks are not supported and mmerder answered:
"Are you using JPA or plain hibernate?" and "Well, It's been a long time since I used plain hibernate and not JPA in a container. But as far as I remember, the entity listeners only work in a JPA environment."

That's where my confusion come from... Can you please help me out :) ? Is JPA a complete different system? As far as I know Hibernate is a JPA implementation, isn't it?


Top
 Profile  
 
 Post subject: Re: How to use Tomcat + Hibernate + JPA?
PostPosted: Tue Feb 16, 2010 5:24 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
IAs far as I know Hibernate is a JPA implementation, isn't it?


JPA is a standard specification for persistence made by the Java_Community
http://en.wikipedia.org/wiki/Java_Community_Process
and Hibernate is since longer time (I believe since version 3) an implementor of JPA.

Quote:
Is JPA a complete different system?


I would say no.
The main access class with JPA is the entitymanager whilst with plain 'old-style' hibernate it is the session.
Both classes have very similiar methods and it is also allowed to use both interfaces contemporaneosly,
as most implementation behind JPA delegates to plain hiberante
Code:
Session hibernatesession = (Session) entitymanager.getDelegate();


As you use annotations, like @PreRemove, @PostRemove you have to use the JPA approach (persistence.xml)
or AnnotationConfiguration in order that your annotation are properly parsed.
With old-style hibernate configuraton it may happen that only hbm-files are be parsed whilst your annotations are ignored. I suppose this is the reason why mmerder asked you if you are using JPA or plain hibernate?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.