You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Martin Mucha <al...@gmail.com> on 2011/02/20 19:04:04 UTC

datasource & persistenceUnit configuration

Hi,

I'm using tomcat-6.0.32 on linux. I primarily use different AS (fully
J2EE compliant) so this the result of my lack of knowledge about
Tomcat.

I got here WebApp, using JPA. I need to configure Tomcat somehow, to
be able to get EntityManager. That's the whole problem ;)
I found almost NO information how to do it, and what I found either
did not work or led me to "reinstall" tomcat.

Could someone be so kind and send me information (or link to it) how
to do it? Something like: configure datasource here in this format,
place persistence.xml here in this way, call this and you're done.

I would be very grateful for this. Thanks in advance
martin.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: datasource & persistenceUnit configuration

Posted by Martin Mucha <al...@gmail.com>.
Christopher,

I'm sorry. I do read too much of walkthroughs and tutorials messing
with tomcat configuration which ended badly, that I got myself into
some mindless frenzy mode. I check everything once again in setup with
resource-local transaction and found out, that I've overlooked
misconfigured oracle dialect.

I'm really sorry that I did waste your time in vain. Thank you for
your effort in helping me, everything is ok now.
martin.

2011/2/22 Christopher Schultz <ch...@christopherschultz.net>:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Martin,
>
> On 2/20/2011 1:51 PM, Martin Mucha wrote:
>> Yes, I know I cannot use container managed EntityManager. Tomcat does
>> not support JTA, ok. But I should be able, also the article points it
>> out, to use application managed EntityManager with RESOURCE_LOCAL
>> transaction type. Just like in SE java.
>>
>> In SE java everything works just fine for me.
>
> Good to know.
>
>> Actually the code looks just as in that article:
>>
>> EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory("insolvencePU");
>> EntityManager em = emf.createEntityManager();
>> em.getTransaction().begin();
>>
>> //and the rest of transaction.
>>
>> my persistence.xml looks like:
>
> So, this persistence.xml file works fine in a standalone Java SE
> program? You should be able to get it to work under Tomcat then. Where
> is your persistence.xml file when you run your standalone Java SE test
> program, and what is the effective CLASSPATH?
>
> Where is your persistence.xml file when you deploy it along with your
> webapp? I would expect that it should be in WEB-INF/classes (or at the
> root of a JAR file found in WEB-INF/lib).
>
>> Line
>> EntityManagerFactory emf =
>> Persistence.createEntityManagerFactory("insolvencePU");
>> fires an Exception complaining about unability to build
>> EntityManagerFactory. That leads me to suspicion that either the
>> persistence.xml, the data source or "something-else" is wrong. But I'm
>> quite to unable to find out what.
>
> I'm guessing that the Persistence framework just can't find your
> configuration file.
>
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk1kFHoACgkQ9CaO5/Lv0PBbBACgi5UegxQ/aplal11hRHnGI2z0
> BjYAnRCl4gFqH8H1DqmwXlB1mwzUO5YJ
> =6EHI
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: datasource & persistenceUnit configuration

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Martin,

On 2/20/2011 1:51 PM, Martin Mucha wrote:
> Yes, I know I cannot use container managed EntityManager. Tomcat does
> not support JTA, ok. But I should be able, also the article points it
> out, to use application managed EntityManager with RESOURCE_LOCAL
> transaction type. Just like in SE java.
> 
> In SE java everything works just fine for me.

Good to know.

> Actually the code looks just as in that article:
> 
> EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("insolvencePU");
> EntityManager em = emf.createEntityManager();
> em.getTransaction().begin();
> 
> //and the rest of transaction.
> 
> my persistence.xml looks like:

So, this persistence.xml file works fine in a standalone Java SE
program? You should be able to get it to work under Tomcat then. Where
is your persistence.xml file when you run your standalone Java SE test
program, and what is the effective CLASSPATH?

Where is your persistence.xml file when you deploy it along with your
webapp? I would expect that it should be in WEB-INF/classes (or at the
root of a JAR file found in WEB-INF/lib).

> Line
> EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("insolvencePU");
> fires an Exception complaining about unability to build
> EntityManagerFactory. That leads me to suspicion that either the
> persistence.xml, the data source or "something-else" is wrong. But I'm
> quite to unable to find out what.

I'm guessing that the Persistence framework just can't find your
configuration file.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk1kFHoACgkQ9CaO5/Lv0PBbBACgi5UegxQ/aplal11hRHnGI2z0
BjYAnRCl4gFqH8H1DqmwXlB1mwzUO5YJ
=6EHI
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: datasource & persistenceUnit configuration

Posted by Martin Mucha <al...@gmail.com>.
Thanks for superbly quick answer.

I've read the article you've been referencing. Actually I found it
earlier, but I did not help me, since the problem is elsewhere.

Yes, I know I cannot use container managed EntityManager. Tomcat does
not support JTA, ok. But I should be able, also the article points it
out, to use application managed EntityManager with RESOURCE_LOCAL
transaction type. Just like in SE java.

In SE java everything works just fine for me. Actually the code looks
just as in that article:

EntityManagerFactory emf =
Persistence.createEntityManagerFactory("insolvencePU");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();

//and the rest of transaction.

my persistence.xml looks like:

<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
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">
  <persistence-unit name="insolvencePU" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>

    many classes here

    <properties>
      <property name="hibernate.connection.username" value="user"/>
      <property name="hibernate.connection.driver_class"
value="oracle.jdbc.OracleDriver"/>
      <property name="hibernate.connection.password" value="pass"/>
      <property name="hibernate.connection.url"
value="jdbc:oracle:thin:@//localhost:1521/AlfonzDB"/>
      <property name="hibernate.cache.provider_class"
value="org.hibernate.cache.NoCacheProvider"/>
      <property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/>
    </properties>
  </persistence-unit>
</persistence>


--- Now back to web app in tomcat:

Line
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("insolvencePU");
fires an Exception complaining about unability to build
EntityManagerFactory. That leads me to suspicion that either the
persistence.xml, the data source or "something-else" is wrong. But I'm
quite to unable to find out what.

Could you help me with that configuration? Just ask me for anything
you need to know to be able to create valid configuration for tomcat 6
(if those information from posted persistence.xml are not sufficient).

thank you.
martin.

2011/2/20 Caldarale, Charles R <Ch...@unisys.com>:
>> From: Martin Mucha [mailto:alfonz19@gmail.com]
>> Subject: datasource & persistenceUnit configuration
>
>> I got here WebApp, using JPA. I need to configure Tomcat
>> somehow, to be able to get EntityManager.
>
> Tomcat itself does not supply an EntityManager, as it is only a servlet container, not a full Jave EE implementation.
>
> This article might be of interest:
> http://blogs.sun.com/pblaha/entry/using_toplink_persistence_ri_in
>
> If that's not what you need, you'll need to explain your problem in more detail.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: datasource & persistenceUnit configuration

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Martin Mucha [mailto:alfonz19@gmail.com] 
> Subject: datasource & persistenceUnit configuration

> I got here WebApp, using JPA. I need to configure Tomcat 
> somehow, to be able to get EntityManager.

Tomcat itself does not supply an EntityManager, as it is only a servlet container, not a full Jave EE implementation.

This article might be of interest:
http://blogs.sun.com/pblaha/entry/using_toplink_persistence_ri_in

If that's not what you need, you'll need to explain your problem in more detail.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org