Return-Path: Delivered-To: apmail-geronimo-user-archive@www.apache.org Received: (qmail 24290 invoked from network); 9 Jun 2008 18:06:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Jun 2008 18:06:30 -0000 Received: (qmail 51184 invoked by uid 500); 9 Jun 2008 18:06:30 -0000 Delivered-To: apmail-geronimo-user-archive@geronimo.apache.org Received: (qmail 50963 invoked by uid 500); 9 Jun 2008 18:06:29 -0000 Mailing-List: contact user-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: user@geronimo.apache.org List-Id: Delivered-To: mailing list user@geronimo.apache.org Received: (qmail 50559 invoked by uid 99); 9 Jun 2008 18:06:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 09 Jun 2008 11:06:28 -0700 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=HTML_MESSAGE,SPF_PASS,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [98.136.44.63] (HELO smtp108.prem.mail.sp1.yahoo.com) (98.136.44.63) by apache.org (qpsmtpd/0.29) with SMTP; Mon, 09 Jun 2008 18:05:28 +0000 Received: (qmail 96751 invoked from network); 9 Jun 2008 18:05:48 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Received:X-YMail-OSG:X-Yahoo-Newman-Property:Message-Id:From:To:In-Reply-To:Content-Type:Mime-Version:Subject:Date:References:X-Mailer; b=rMvRgwrfVDyPxfxp54EQKdwiFdOPXouRTjFWHrx580KF/oTYKCYmwy7DkOrG6cfsDFdYmEpLclqKT6sCbtN8Bk5V38zEZgHMwD5+AQVVo9U8NX9anOr9HjEmym2modTWO2GiAnP+kA3gHLC645oR83cymsuIQJn7xuy1OVCK1/Q= ; Received: from unknown (HELO ?10.11.55.42?) (david_jencks@63.105.20.225 with plain) by smtp108.prem.mail.sp1.yahoo.com with SMTP; 9 Jun 2008 18:05:28 -0000 X-YMail-OSG: 8cy7UIMVM1lHxeIK98p5ha3eJNNOfbBkraRHEkqpPpOVBN.n06X.HxR15_o0nFydhkNBmfykRFBUouuamkaom3Zl6crtt8ZMB1XEnqk6ncRZKTfJgud4 X-Yahoo-Newman-Property: ymail-3 Message-Id: <827F5A36-631D-4EB1-BE43-E123C0A8ED10@yahoo.com> From: David Jencks To: user@geronimo.apache.org In-Reply-To: <83e2fc4d0806090143o35fb5de5g5bb80f2ee2e022fa@mail.gmail.com> Content-Type: multipart/alternative; boundary=Apple-Mail-21-651796433 Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: JPA, entities and EJB3 Date: Mon, 9 Jun 2008 11:05:13 -0700 References: <17502079.post@talk.nabble.com> <88DA26C3-5794-4E20-87FA-E333445DDF07@yahoo.com> <83e2fc4d0806090143o35fb5de5g5bb80f2ee2e022fa@mail.gmail.com> X-Mailer: Apple Mail (2.919.2) X-Virus-Checked: Checked by ClamAV on apache.org --Apple-Mail-21-651796433 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit I looked in the spec a bit and am not sure I understand how all the parts are meshing, maybe david blevins can chime in... I think that you've specified contradictory information and maybe we should be complaining rather than supplying a container managed jta EntityManager. I _think_ that your annotation-injected EntityManager has to be container managed and hence jta. I _think_ that if you want a resource-local EntityManager you have to inject the EMF with a PersistenceUnit annotation and get the EntityManager yourself. In the spec, section 5.6 starts: Whenacontainer-managedentitymanager isused, thelifecycleof thepersistencecontext isalways managedautomatically, transparentlytotheapplication, andthepersistencecontextispropagatedwith the JTA transaction. I think this means that with your @PersistenceContext annotation, you are definitely going to get a tx-type=JTA EM. Since you specified RESOURCE_LOCAL in the persistence.xml I think we should perhaps be objecting. I also think this means that you need an application managed persistence context to get RESOURCE_LOCAL. There are a bunch of examples in section 5.7 that all use @PersistenceUnit. Also hoping for clarification.... david jencks On Jun 9, 2008, at 1:43 AM, Phani Madgula wrote: > Hi, > I have tried to play with and > as follows. > > I have the following peristence.xml in a web application. > *********** > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation="http://java.sun.com/xml/ns/persistence > http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" > version="1.0"> > > > type="RESOURCE_LOCAL"> > org.apache.openjpa.persistence.PersistenceProviderImpl provider> > ProductDS-nonJTA > orm.xml > samples.jpa.Product > samples.jpa.Book > > > > > > *********** > > In the servlet, I have the following code > > *********** > @PersistenceContext(unitName="Tutorial") > private EntityManager em; > ..... > .... > UserTransaction ut; > try{ > Context ctx = new InitialContext(); > > //ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction"); > //ut.begin(); > > //EntityTransaction et = em.getTransaction(); > //et.begin(); > > Book book = new Book("DDDDD","John", > 1.0,"Joe","1934834-23823","Phani"); > em.persist(book); > > //et.commit(); > //ut.commit(); > > }catch(Exception e){ > e.printStackTrace(); > throw new ServletException (e); > } > *********************** > > 1. When I hit the servlet, I get the following error. > > *********************** > javax.persistence.TransactionRequiredException : No Active > transaction > *********************** > > 2. Suppose I have the following code in the servlet > ********************** > *********** > @PersistenceContext(unitName="Tutorial") > private EntityManager em; > ..... > .... > UserTransaction ut; > try{ > Context ctx = new InitialContext(); > > //ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction"); > //ut.begin(); > > //Uncomment EntityTransaction > EntityTransaction et = em.getTransaction(); > et.begin(); > > Book book = new Book("DDDDD","John", > 1.0,"Joe","1934834-23823","Phani"); > em.persist(book); > > et.commit(); > //ut.commit(); > > }catch(Exception e){ > e.printStackTrace(); > throw new ServletException (e); > } > *********************** > I get the following error > *********************** > > java.lang.IllegalStateException : You can not call getTransaction on > a container managed EntityManager > > ************************* > > 3. Only if I use JTA API, I am able to get the entity persisted > properly as below. > *************************** > @PersistenceContext(unitName="Tutorial") > private EntityManager em; > ..... > .... > UserTransaction ut; > try{ > Context ctx = new InitialContext(); > > ut = (UserTransaction)ctx.lookup("java:comp/UserTransaction"); > ut.begin(); > > > Book book = new Book("DDDDD","John", > 1.0,"Joe","1934834-23823","Phani"); > em.persist(book); > > > ut.commit(); > > }catch(Exception e){ > e.printStackTrace(); > throw new ServletException (e); > } > **************************** > > Please note that I am using "RESOURCE_LOCAL" persistence unit. I also > used . I deployed the database pool with > tag in the connector deployment plan. > > My questions are > > 1. Should we always use UserTransaction object irrespective of > or in JEE environment?? > > 2. How is the use of different from the use > in JEE environment?? > > 3. In EJBs, when ContainerManaged Transactions are used, there is no > need to use JTA. Is that correct?? > > 4. Only in J2SE environments, we can use EntityTransaction object. is > that correct?? > > Thanks in advance. > Phani > > On 5/28/08, David Jencks wrote: >> 1. I hope you named the file openejb-jar.xml >> 2. jta-datasource and non-jta-datasource have to contain the names of >> the datasources in the geronimo plan used for the pool, NOT some jndi >> name you might also map them to. The datasources don't need to be >> bound in jndi in order to be used for jpa >> 3. The non-jta-datasource must be a datasource that really has no >> transaction support, using the element instead of >> or ... in the connector plan. >> With derby I find it necessary to have a non-jta-datasource if any >> ddl >> is needed or if openjpa is generating the primary keys. I don't know >> if you can get away without one for other databases. If you want to >> experiment, leave out the non-jta-datasource rather than duplicating >> the jta-datasource contents. >> >> hope this helps >> david jencks >> >> On May 27, 2008, at 4:09 PM, zeros wrote: >> >>> >>> Good evening: >>> >>> I'm newbie with EJB3.0. I want to configure the persistence.xml >>> to have >>> entities managed with JPA. I have the next configuration files: >>> OPENJPA-JAR.XML >>> >>> >> xmlns:nam="http://geronimo.apache.org/xml/ns/naming-1.1" >>> xmlns:pkgen="http://www.openejb.org/xml/ns/pkgen-2.0" >>> xmlns:sec="http://geronimo.apache.org/xml/ns/security-1.1" >>> xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2"> >>> >>> >>> o2o.marketing >>> EJB >>> 1.0.8 >>> jar >>> >>> >>> >>> console.dbpool >>> marketing >>> 1.0 >>> rar >>> >>> >>> >>> >>> >>> And I have also persistence.xml >>> >>> >>> >> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >>> xsi:schemaLocation="http://java.sun.com/xml/ns/persistence >>> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> >>> >>> Entity Beans for User >>> >>> org.apache.openjpa.persistence.PersistenceProviderImpl>> provider> >>> java:comp/env/marketing >>> java:comp/env/marketing>> source> >>> META-INF/orm.xml >>> >>> >>> >>> >>> The error which I'm having is the next one: Unable to resolve >>> reference >>> "JtaDataSourceWrapper" and Unable to resolve reference >>> "NonJtaDataSourceWrapper", which are basically the same error. >>> >>> I think this is produced because I'm not mapping the Datasocurce to >>> the >>> DBPool. Geronimo returns to me examples to do it for web, but no >>> example to >>> do it for an EJB. >>> >>> Please could you help me? >>> >>> WATCH OUT! I'm talking about entities and EJB3.0, not entiti beans >>> and >>> EJB2.0 >>> >>> Thanks in advance >>> >>> SERGIO >>> -- >>> View this message in context: >>> http://www.nabble.com/JPA%2C-entities-and-EJB3-tp17502079s134p17502079.html >>> Sent from the Apache Geronimo - Users mailing list archive at >>> Nabble.com. >>> >> >> --Apple-Mail-21-651796433 Content-Type: text/html; charset=US-ASCII Content-Transfer-Encoding: quoted-printable I looked in the spec a bit and = am not sure I understand how all the parts are meshing, maybe david = blevins can chime in...   I think that you've specified = contradictory information and maybe we should be complaining rather than = supplying a container managed jta EntityManager.

I = _think_ that your annotation-injected EntityManager has to be container = managed and hence jta.
I _think_ that if you want a = resource-local EntityManager you have to inject the EMF with a = PersistenceUnit annotation and get the EntityManager = yourself.

In the spec, section 5.6 = starts:
Whenacontainer-managedentitymanager isused, = thelifecycleof thepersistencecontext isalways 
managedautomatically, = transparentlytotheapplication, = andthepersistencecontextispropagatedwith 
the JTA transaction. 


I think = this means that with your @PersistenceContext annotation, you are = definitely going to get a tx-type=3DJTA EM.  Since you specified = RESOURCE_LOCAL in the persistence.xml I think we should perhaps be = objecting.

I also think this means that you = need an application managed persistence context to get RESOURCE_LOCAL. =  There are a bunch of examples in section 5.7 that all use = @PersistenceUnit.

Also hoping for = clarification....
david = jencks

On Jun 9, 2008, at 1:43 AM, Phani = Madgula wrote:

Hi,
I have tried to play with <jta-datasource> and = <non-jta-datasource> as follows.

I have the following = peristence.xml in a web application.
***********
<?xml = version=3D"1.0" encoding=3D"UTF-8" ?>
<persistence xmlns=3D"http://java.sun.com/xml/ns= /persistence"
   xmlns:xsi=3D"http://www.w3.org/2001/= XMLSchema-instance"
   xsi:schemaLocation=3D"http://java.sun.com/xml/ns= /persistence
http:/= /java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version=3D"1.= 0">

   <!-- Tutorial "unit" -->
=    <persistence-unit name=3D"Tutorial" = transaction-type=3D"RESOURCE_LOCAL">
=    <provider>org.apache.openjpa.persistence.PersistenceP= roviderImpl</provider>
=    <non-jta-data-source>ProductDS-nonJTA</non-jta-dat= a-source>
=    <mapping-file>orm.xml</mapping-file>
=    <class>samples.jpa.Product</class>
=    <class>samples.jpa.Book</class>

=    </persistence-unit>
=
</persistence>

***********

In the servlet, I = have the following = code

***********
@PersistenceContext(unitName=3D"Tutorial")
=   private EntityManager em;
.....
....
= UserTransaction ut;
try{
Context = ctx =3D new InitialContext();

//ut =3D = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
= //ut.begin();

//EntityTransaction et =3D = em.getTransaction();
//et.begin();

Book book = =3D new Book("DDDDD","John",1.0,"Joe","1934834-23823","Phani");
= em.persist(book);

//et.commit();
= //ut.commit();

}catch(Exception e){
= e.printStackTrace();
throw new ServletException = (e);
= = }
***********************

1. When I hit the servlet, I = get the following error.

  ***********************
=   javax.persistence.TransactionRequiredException : No Active = transaction
  ***********************

2. Suppose I = have the following code in the servlet
=    **********************
***********
@PersistenceCon= text(unitName=3D"Tutorial")
  private EntityManager = em;
.....
....
UserTransaction ut;
= try{
= = = Context ctx =3D new InitialContext();

//ut =3D = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
= //ut.begin();

//Uncomment = EntityTransaction
EntityTransaction et =3D = em.getTransaction();
et.begin();

Book book = =3D new Book("DDDDD","John",1.0,"Joe","1934834-23823","Phani");
= em.persist(book);

=        et.commit();
= //ut.commit();

}catch(Exception e){
= e.printStackTrace();
throw new ServletException = (e);
= = }
 ***********************
 I get the following = error
 ***********************

=  java.lang.IllegalStateException : You can not call getTransaction = on
a container managed EntityManager

=  *************************

3. Only if I use JTA API, I am = able to get the entity persisted
properly as below.
= ***************************
@PersistenceContext(unitName=3D"Tutorial")<= br>   private EntityManager em;
.....
....
= UserTransaction ut;
try{
Context = ctx =3D new InitialContext();

ut =3D = (UserTransaction)ctx.lookup("java:comp/UserTransaction");
= ut.begin();


Book book =3D new = Book("DDDDD","John",1.0,"Joe","1934834-23823","Phani");
= em.persist(book);


ut.commit();

= }catch(Exception e){
e.printStackTrace();
throw new = ServletException (e);
= }
****************************

Please note that I am = using "RESOURCE_LOCAL" persistence unit. I also
used = <non-jta-datasource>. I deployed the database pool = with
</no-transaction> tag in the connector deployment = plan.

My questions are

1. Should we always use = UserTransaction object irrespective of
<jta-datasource> or = <non-jta-datasource> in JEE environment??

2. How is the use of = <non-jta-datsource> different from the use
<jta-datasource> in = JEE environment??

3. In EJBs, when ContainerManaged Transactions = are used, there is no
need to use JTA. Is that correct??

4. = Only in J2SE environments, we can use EntityTransaction object. = is
that correct??

Thanks in advance.
Phani

On = 5/28/08, David Jencks <david_jencks@yahoo.com> = wrote:
1. I hope you named the file = openejb-jar.xml
2. = jta-datasource and non-jta-datasource have to contain the names = of
the datasources in the = geronimo plan used for the pool, NOT some = jndi
name you might also map = them to.  The datasources don't need to = be
bound in jndi in order to = be used for jpa
3. The = non-jta-datasource must be a datasource that really has = no
transaction support, using = the <no-transaction/> element instead of
<local-transaction/> or <xa-transaction>... in the = connector plan.
With derby I = find it necessary to have a non-jta-datasource if any = ddl
is needed or if openjpa is = generating the primary keys.  I don't = know
if you can get away = without one for other databases.  If you want = to
experiment, leave out the = non-jta-datasource rather than duplicating
the jta-datasource contents.

hope this = helps
david = jencks

On May 27, = 2008, at 4:09 PM, zeros wrote:


Good = evening:

  I'm newbie with = EJB3.0. I want to configure the = persistence.xml
to = have
entities managed with JPA. I have the next configuration = files:
OPENJPA-JAR.XML

<openejb-jar xmlns=3D"http://www.openejb.= org/xml/ns/openejb-jar-2.1"
xmlns:nam=3D"http://geronimo.apac= he.org/xml/ns/naming-1.1"
xmlns:pkgen=3D"http://www.openejb.org/xm= l/ns/pkgen-2.0"
xmlns:sec=3D"http://geronimo.ap= ache.org/xml/ns/security-1.1"
xmlns:sys=3D"http://geronimo.= apache.org/xml/ns/deployment-1.2">
= <sys:environment>
=   <sys:moduleId>
=     <sys:groupId>o2o.marketing</sys:groupId>
=
=     <sys:artifactId>EJB</sys:artifactId>
= =     <sys:version>1.0.8</sys:version>
=     <sys:type>jar</sys:type>
=   </sys:moduleId>
=   <sys:dependencies>
=       <sys:dependency>
=           <sys:groupI= d>console.dbpool</sys:groupId>
=        = <sys:artifactId>marketing</sys:artifactId>
=        = <sys:version>1.0</sys:version>
<= blockquote type=3D"cite">
=          = <sys:type>rar</sys:type>
= </sys:dependency>
= </sys:dependencies>
= </sys:environment>
</openejb-jar>

And I have also = persistence.xml

<?xml version=3D"1.0" = encoding=3D"UTF-8"?>
<persistence version=3D"1.0" = xmlns=3D"http://java.sun.com/xml/ns= /persistence
"
xmlns:xsi=3D"http://www.w3.org/2001/= XMLSchema-instance"
xsi:schemaLocation=3D"http://java.sun.com/xml/ns= /persistence
http:/= /java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
= <persistence-unit = name=3D"marketing">
   = <description>Entity Beans for = User</description>

<provider>org.apache.openjpa.persistence.PersistenceProvi= derImpl</
provider>
   = <jta-data-source>java:comp/env/marketing</jta-data-source>
   = <non-jta-data-source>java:comp/env/marketing</non-jta-data-so= urce>
=       <mapping-file>META-INF/orm.xml</= mapping-file>
=       <properties = />
= </persistence-unit>
</persistence>

The error which I'm having is = the next one: Unable to resolve
reference
"JtaDataSourceWrapper" and = Unable to resolve reference
"NonJtaDataSourceWrapper", which = are basically the same error.

I think this is produced because = I'm not mapping the Datasocurce = to
the
DBPool. Geronimo returns to me = examples to do it for web, but = no
example to
do it for an = EJB.

Please could you help = me?

WATCH OUT! I'm talking about = entities and EJB3.0, not entiti beans = and
EJB2.0

Thanks in = advance

SERGIO
--
View this message in = context:
http://www.nabble.com/JPA%2C-entities-and-EJB3-tp17502079s134p1= 7502079.html
Sent from the Apache Geronimo - = Users mailing list archive at
Nabble.com.




= --Apple-Mail-21-651796433--