You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Cil-Gamir <ha...@rmb.co.za> on 2010/03/06 14:43:19 UTC

Two OpenJPA Applications in the same container

Hi

I'm running two webapplications in the same JBOSS container.

They both access the same database and they access the same tables (there is
an overlap)

The applications cannot eb combined into one application.

The problem now is, whichever application I access first after the JBOSS
startup is the one that works, the other appliction doesn't load it's
entities correctly and gives me errors like

An error occurred while parsing the query filter "select a from
KycRequestBusinessContactPerson a where a.userName =?1". Error message: The
name "KycRequestBusinessContactPerson" is not a recognized entity or
identifier. Known entity names: []

It has no known entity names for the second application.

What's the correct way to have two applications access the same datasource
using openjpa ?

-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4686242.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
Hi Milosz

What you suggest was definitely a problem when I started, but the error
message was clear enough so I fixed that issue. 

My entities are definitely in different packages now.

I still get the same issue.

I've also changed the package location of the class that returns my
EntityManager. And that class returns a differently named persistence unit
in each project.

My persistence.xml looks like this

<?xml version="1.0" encoding="UTF-8"?>

  
    org.apache.openjpa.persistence.PersistenceProviderImpl
    java:kyc-dev-ds
    za.co.rmb.rac.kyc.request.entities.KycRequestSubsystems
	...
	...
	...
    
      
      
      
      
    
  


The persistence.xml in the other project is exactly the same except for the
persistence-unit element, which has a different name.

They both use the same datasource.
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4693584.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
Another thing that I notice now. I get this error right at the top of the
stacktrace

Error occured retrieving Kyc Request[Ljava.lang.StackTraceElement;@4f36836c
<openjpa-1.2.1-r752877:753278 fatal user error>
org.apache.openjpa.persistence.ArgumentException: The type "class
za.co.rmb.rac.kyc.management.entities.KycMRequest" has not been enhanced.

But I'm running the maven build time enhancer automatically with evety
build.

Again, as with my other problems, if I access this project first then JBOSS
loads it first and all is well, but then the other one is broken...
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4694029.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Miłosz <mt...@o2.pl>.
Hi Pinaki,

I suggested this change because I was suspecting OpenJPA was trying to participate in an XA transaction.

Regards,
Milosz

> Hi Milosz,
>   Can you please elaborate how the error got resolved with
>   <property name="openjpa.TransactionMode" value="managed"/> 
> 
>   Initially it looked more like a class loading issue.
> 
> -----
> Pinaki 
> -- 


Re: Two OpenJPA Applications in the same container

Posted by Pinaki Poddar <pp...@apache.org>.
Hi Milosz,
  Can you please elaborate how the error got resolved with
  <property name="openjpa.TransactionMode" value="managed"/> 

  Initially it looked more like a class loading issue.

-----
Pinaki 
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4754580.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
Hi Milosz

Yes that does it, thanks so much for the help.

If I remove that TransactionMode then it seems to work.

Running it in Tomcat also seemed to work fine.

I'm not running any transactions, all my database access is done with one
query at a time. So I don't think this will affect my in any way.

Thanks again

Hannes
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4700397.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Miłosz Tylenda <mt...@o2.pl>.
Hi,

Does anything change if you use the datasource but remove the following property?

<property name="openjpa.TransactionMode" value="managed"/>

Cheers,
Milosz

> 
> A "work-around" of sorts seems to be to not use a datasource. But that's bad
> practice, I can get away with it because my application doesn't take heavy
> traffic. But if I don't use a jta datasource and just connect to the
> database directly then it works fine.
> 
> So
> 
>     <property name="openjpa.ConnectionURL"
> 				value="jdbc:oracle:thin:@server:1530:schema" />
>     <property name="openjpa.ConnectionDriverName"
> value="oracle.jdbc.driver.OracleDriver" />
>     <property name="openjpa.ConnectionUserName" value="user" />
>     <property name="openjpa.ConnectionPassword" value="pass" />
> </properties>
> 
> instead of 
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
> <properties>
>       <property name="openjpa.DataCache" value="true"/>
>       <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
>       <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
>       <property name="openjpa.TransactionMode" value="managed"/>
> </properties>
> -- 
> View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4693652.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
> 

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
A "work-around" of sorts seems to be to not use a datasource. But that's bad
practice, I can get away with it because my application doesn't take heavy
traffic. But if I don't use a jta datasource and just connect to the
database directly then it works fine.

So

    <property name="openjpa.ConnectionURL"
				value="jdbc:oracle:thin:@server:1530:schema" />
    <property name="openjpa.ConnectionDriverName"
value="oracle.jdbc.driver.OracleDriver" />
    <property name="openjpa.ConnectionUserName" value="user" />
    <property name="openjpa.ConnectionPassword" value="pass" />
</properties>

instead of 
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<properties>
      <property name="openjpa.DataCache" value="true"/>
      <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
      <property name="openjpa.TransactionMode" value="managed"/>
</properties>
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4693652.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
Just a note, I am currently running the JBOSS class loader isolation feature
that you suggested. But it's not changing anything. But I think I could have
done that from the start to avoid changing my class names.
-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4693641.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Cil-Gamir <ha...@rmb.co.za>.
Hi Milosz 

What you suggest was definitely a problem last week sometime, but the error
message on that was clear enough for me to fix it by myself. 

My entities are definitely in different packages now. 

I still get the same issue. 

I've also changed the package location of the class that returns my 
EntityManager. And that class returns a differently named persistence unit 
in each project. 

My persistence.xml looks like this 

<?xml version="1.0" encoding="UTF-8"?>
<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="kyc-request-data-engine">
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <jta-data-source>java:kyc-dev-ds</jta-data-source>
    <class>za.co.rmb.rac.kyc.request.entities.KycRequestSubsystems</class>
	...
	...
	...
    <properties>
      <property name="openjpa.DataCache" value="true"/>
      <property name="openjpa.RemoteCommitProvider" value="sjvm"/>
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO"/>
      <property name="openjpa.TransactionMode" value="managed"/>
    </properties>
  </persistence-unit>
</persistence>

The persistence.xml in the other project is exactly the same except for the 
persistence-unit element, which has a different name. 

They both use the same datasource. 

-- 
View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4693587.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Two OpenJPA Applications in the same container

Posted by Miłosz Tylenda <mt...@o2.pl>.
Hi,

Do your entities have the same class and package names in both applications? If so, I suspect an issue with unified class loader in JBoss [1]. You might try configuring your applications to use separate class loaders.

Let us know whether it helps.

Cheers,
Milosz

[1] http://community.jboss.org/wiki/ClassLoadingConfiguration



> Hi
> 
> I'm running two webapplications in the same JBOSS container.
> 
> They both access the same database and they access the same tables (there is
> an overlap)
> 
> The applications cannot eb combined into one application.
> 
> The problem now is, whichever application I access first after the JBOSS
> startup is the one that works, the other appliction doesn't load it's
> entities correctly and gives me errors like
> 
> An error occurred while parsing the query filter "select a from
> KycRequestBusinessContactPerson a where a.userName =?1". Error message: The
> name "KycRequestBusinessContactPerson" is not a recognized entity or
> identifier. Known entity names: []
> 
> It has no known entity names for the second application.
> 
> What's the correct way to have two applications access the same datasource
> using openjpa ?
> 
> -- 
> View this message in context: http://n2.nabble.com/Two-OpenJPA-Applications-in-the-same-container-tp4686242p4686242.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>