Thread: Moving to EclipseLink (SessionCustomizer problem)

This question is answered.


Permlink Replies: 5 - Pages: 1 - Last Post: Jun 2, 2009 10:45 PM Last Post By: Pavel Zelenka Threads: [ Previous | Next ]
Pavel Zelenka

Posts: 13
Registered: 03/25/09
Moving to EclipseLink (SessionCustomizer problem)
Posted: May 30, 2009 4:43 AM
 
Click to report abuse...   Click to reply to this thread Reply
Hi,

I moved from Toplink Essentials to EclipseLink with Tomcat 6.0.18 and have this problem:

I created two web applications both uses EclipseLink. Due to using non-jta-datasources I created in both applications JPAEclipseLinkSessionCustomizer as shown here: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial

When I start one application everything works fine. As soon as I run the other application which uses EclipseLink I got exception:

Exception [EclipseLink-28014] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Exception was thrown while processing property (eclipselink.session.customizer) with value (hlaseni.JPAEclipseLinkSessionCustomizer).
Internal Exception: java.lang.ClassCastException: hlaseni.JPAEclipseLinkSessionCustomizer cannot be cast to org.eclipse.persistence.config.SessionCustomizer

Can anyone help?

Thanks

PERSISTENCE.XML
<?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="hlaseniPU" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/jdbc/Hlaseni</non-jta-data-source>
<class>hlaseni.entity.Zmeny</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.session.customizer" value="hlaseni.JPAEclipseLinkSessionCustomizer"/>
<property name="eclipselink.logging.level" value="INFO"/>
</properties>
</persistence-unit>
</persistence>

CLASS JPAEclipseLinkSessionCustomizer:
package hlaseni;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.eclipse.persistence.config.SessionCustomizer;
import org.eclipse.persistence.sessions.JNDIConnector;
import org.eclipse.persistence.sessions.Session;

public class JPAEclipseLinkSessionCustomizer implements SessionCustomizer {
public void customize(Session session) throws Exception {
JNDIConnector connector = null;
Context context = null;
try {
context = new InitialContext();
if (null != context) {
connector = (JNDIConnector) session.getLogin().getConnector(); // possible CCE
connector.setLookupType(JNDIConnector.STRING_LOOKUP);
System.out.println("_JPAEclipseLinkSessionCustomizer: configured " + connector.getName());
} else {
throw new Exception("_JPAEclipseLinkSessionCustomizer: Context is null");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
michael_obrien

Posts: 149
Registered: 12/10/07
Re: Moving to EclipseLink (SessionCustomizer problem)
Posted: Jun 1, 2009 7:51 AM   in response to: Pavel Zelenka in response to: Pavel Zelenka
 
Click to report abuse...   Click to reply to this thread Reply
Pavel,
Hi, the Tomcat tutorial requires an update to describe changing the lookupType on both JTA and non-JTA connections - to match the same process as used in JBoss - I have updated the pages to match - in your case this should not affect your single non-jta-data-source.

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer
http://wiki.eclipse.org/EclipseLink/Examples/JPA/JBoss_Web_Tutorial#Session_Customizer

There is also a related post in the following post that may be of interest.
http://forums.oracle.com/forums/thread.jspa?messageID=3205242&tstart=0

For your issue. Both WAR files use EclipseLink - Is there any difference in your persistence.xml or JPAEclipseLinkSessionCustomizer that could cause the CCE in the 2nd one. Also, does the first application work fine with the STRING_LOOKUP change in your JPAEclipseLinkSessionCustomizer class - are reads and persists working on the first one?

I am installing Tomcat 6.0.18 to reverify the example last tested in March 2009 and will advise.

Some triage:
The following line in EntityManagerSetupImpl.processSessionCustomizer():1392 is causing your CCE before your customizer is run.
try {
CCE--> sessionCustomizer = (SessionCustomizer)sessionCustomizerClass.newInstance();
sessionCustomizer.customize(session);
} catch (Exception ex) {
Not enough context ----> throw EntityManagerSetupException.failedWhileProcessingProperty(PersistenceUnitProperties.SESSION_CUSTOMIZER, sessionCustomizerClassName, ex);

There is a secondary issue with this function above in our code where the "sessionCustomizerClass" Class returned may be null but the exception reported only reports on the String class name - I will raise a bug for this - although I am unable to reproduce the CCE yet.

Are you deploying your eclipselink.jar as as a shared-library in the lib directory? This may be a classLoader issue.
Verify your classLoader for the customizer is running off your WAR in ClassLoader: WebappClassLoader Parent Classloader:
org.apache.catalina.loader.StandardClassLoader

Also, the following user is having your CCE when switching to an RCP runtime context.
http://dev.eclipse.org/newslists/news.eclipse.rt.eclipselink/msg00223.html

thank you
/michael

Edited by: michael_obrien on Jun 1, 2009 1:00 PM
michael_obrien

Posts: 149
Registered: 12/10/07
Re: Moving to EclipseLink (SessionCustomizer problem)
Posted: Jun 1, 2009 12:51 PM   in response to: michael_obrien in response to: michael_obrien
 
Click to report abuse...   Click to reply to this thread Reply
Pavel,
I was able to run EclipseLink JPA using a non-JTA datasource on Tomcat 6.0.18 using the following configuration.
I will update the tutorial with this 3rd type of database connectivity.
1) transaction-type RESOURCE_LOCAL direct connection using "javax.persistence.jdbc" properties - previously working
2) transaction-type RESOURCE_LOCAL non-JTA datasource connection using "non-jta-data-source" or "javax.persistence.nonJtaDataSource" - verified today
3) transaction-type JTA "jta-data-source" - working only when Tomcat is run as a service

2) non-jta-datasource setup for persistence.xml, web.xml and server.xml
Note: if the resource-ref setup is missing or if the jndi names do not match you will see "name not bound" exceptions

persistence.xml
<persistence-unit name="statJPA" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<non-jta-data-source>java:comp/env/ds/OracleDS</non-jta-data-source>
<class>org.eclipse.persistence.example.unified.business.***</class>
<properties>
<property name="eclipselink.session.customizer" value="org.eclipse.persistence.example.unified.integration.JPAEclipseLinkSessionCustomizer"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
<!-- this one overrides -->
<property name="javax.persistence.nonJtaDataSource" value="java:comp/env/ds/OracleDS"/>
<property name="eclipselink.logging.level" value="FINEST"/>
</properties>
</persistence-unit>

JPAEclipseLinkSessionCustomizer.java
- matches what is on
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Session_Customizer

web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>UnifiedTomcatWeb</display-name>
<servlet>
<display-name>FrontController</display-name>
<servlet-name>FrontController</servlet-name>
<servlet-class>org.eclipse.persistence.example.unified.presentation.FrontController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FrontController</servlet-name>
<url-pattern>/FrontController</url-pattern>
</servlet-mapping>
<persistence-context-ref>
<persistence-context-ref-name>persistence/em</persistence-context-ref-name>
<persistence-unit-name>statJPA</persistence-unit-name>
</persistence-context-ref>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>ds/OracleDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>

server.xml

<GlobalNamingResources>
....
<Resource
name="ds/OracleDS"
auth="Container"
type="javax.sql.DataSource"
maxActive="100"
maxIdle="30"
maxWait="10000"
username="scott"
password="pw"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@y.y.y.y:1521:orcl"
/>
</GlobalNamingResources>
....
<Context
className="org.apache.catalina.core.StandardContext"
cachingAllowed="true"
charsetMapperClass="org.apache.catalina.util.CharsetMapper"
cookies="true" crossContext="false" debug="0"
displayName="UnifiedTomcatWeb"
docBase="C:\opt\tomcat6018\webapps\UnifiedTomcatWeb.war"
mapperClass="org.apache.catalina.core.StandardContextMapper"
path="/UnifiedTomcatWeb"
privileged="false" reloadable="false"
swallowOutput="false" useNaming="true"
wrapperClass="org.apache.catalina.core.StandardWrapper">
<ResourceLink
global="ds/OracleDS"
name="ds/OracleDS"
type="javax.sql.DataSource"/>
</Context>
</Host>

Logs:
[EL Finest]: 2009-06-01 15:19:23.828--ServerSession(13961193)--Thread(Thread[http-8080-1,5,main])--property=javax.persistence.nonJtaDataSource; value=java:comp/env/ds/OracleDS
[EL Finest]: 2009-06-01 15:19:23.844--ServerSession(13961193)--Thread(Thread[http-8080-1,5,main])--property=eclipselink.session.customizer; value=org.eclipse.persistence.example.unified.integration.JPAEclipseLinkSessionCustomizer
_JPAEclipseLinkSessionCustomizer: configured java:comp/env/ds/OracleDS
[EL Info]: 2009-06-01 15:19:23.844--ServerSession(13961193)--Thread(Thread[http-8080-1,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.0.0.qualifier
[EL Config]: 2009-06-01 15:19:23.859--ServerSession(13961193)--Connection(6427893)--Thread(Thread[http-8080-1,5,main])--connecting
(DatabaseLogin(
platform=>OraclePlatform
user name=> ""
connector=>JNDIConnector datasource name=>java:comp/env/ds/OracleDS
))
[EL Config]: 2009-06-01 15:19:24.327--ServerSession(13961193)--Connection(24968504)--Thread(Thread[http-8080-1,5,main])--Connected
: jdbc:oracle:thin:@y.y.y.y:1521:orcl
User: SCOTT
Database: Oracle Version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
Driver: Oracle JDBC driver Version: 11.1.0.0.0-Beta5
EL Info]: 2009-06-01 15:19:24.358--ServerSession(13961193)--Thread(Thread[http-8080-1,5,main])--file:/C:/opt/tomcat6018/webapps/UnifiedTomcatWeb/WEB-INF/classes/-statJPA login successful

- user sends "demo" command to servlet....

[EL Finer]: 2009-06-01 15:19:24.39--ServerSession(13961193)--Thread(Thread[http-8080-1,5,main])--client acquired
[EL Finest]: 2009-06-01 15:19:24.39--UnitOfWork(13645178)--Thread(Thread[http-8080-1,5,main])--PERSIST operation called on: org.eclipse.persistence.example.unified.business.StatLabel@b31b77.
[EL Finer]: 2009-06-01 15:19:24.483--UnitOfWork(13645178)--Thread(Thread[http-8080-1,5,main])--begin unit of work commit
[EL Finer]: 2009-06-01 15:19:24.483--ClientSession(26548428)--Connection(16408563)--Thread(Thread[http-8080-1,5,main])--begin transaction
[EL Finest]: 2009-06-01 15:19:24.499--ClientSession(26548428)--Thread(Thread[http-8080-1,5,main])--reconnecting to external connection pool
[EL Finest]: 2009-06-01 15:19:24.499--UnitOfWork(13645178)--Thread(Thread[http-8080-1,5,main])--Execute query InsertObjectQuery(org.eclipse.persistence.example.unified.business.StatLabel@c22a3b)
[EL Fine]: 2009-06-01 15:19:24.499--ClientSession(26548428)--Connection(26760685)--Thread(Thread[http-8080-1,5,main])--INSERT INTO
STAT_LABEL (ID, DATE_STAMP) VALUES (?, ?)
bind => [7127, null]

thank you
/michael

Pavel Zelenka

Posts: 13
Registered: 03/25/09
Re: Moving to EclipseLink (SessionCustomizer problem)
Posted: Jun 2, 2009 1:41 AM   in response to: michael_obrien in response to: michael_obrien
 
Click to report abuse...   Click to reply to this thread Reply
Hi Michael,

thanks for your help. Unfortunately it still doesn't work for me. Eclipselink.jar is in $TOMCAT_HOME$/webapps/hlaseni/WEB-INF/lib, javax.persistence_1.0.0.jar and persistence_1_0.xsd are in $TOMCAT_HOME$/lib. As a datasource I use this:

CONTEXT.XML
<Context path="/hlaseni">
<Resource name="jdbc/Hlaseni" auth="Container"
type="javax.sql.DataSource" username="..." password="..."
driverClassName="com.microsoft.jdbc.sqlserver.SQLServerDriver"
url="jdbc:microsoft:sqlserver://pha-ei:1433;DatabaseName=HLASENI"
maxActive="10" maxIdle="0"/>
</Context>

This is the only difference to your approach. In the first reply you asked whether first running application worked. Answer is yes. The first running application works fine (reading, writing data from database).

Thanks

Pavel

michael_obrien

Posts: 149
Registered: 12/10/07
Re: Moving to EclipseLink (SessionCustomizer problem)
Posted: Jun 2, 2009 4:33 AM   in response to: Pavel Zelenka in response to: Pavel Zelenka
Correct
Click to report abuse...   Click to reply to this thread Reply
Pavel,
Hi, our two applcations differ in where eclipselink.jar sits in the catalina classpath tree.
try moving eclipselink.jar in your 2nd application higher up the classpath tree into the tomcat/lib directory.
see
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#EclipseLink_JAR_location

Q1) Is there a reason why you need to distribute a version of eclipselink within your 2nd application - the recommended approach is to use a shared global library in tomcat/lib unless a particular application needs a specific version of the jar.
Q2) Does your first working EclipseLink application use an eclipselink.jar from tomcat/jlib (same place as the javax.persistence jar)
Q3) Take the datasource out of the equation: Are you able to run your 2nd application fine using jdbc parameters instead of a non-jta datasource, try replacing the datasource property with javax.persistence.jdbc properties for a direct connection

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Tomcat_Web_Tutorial#Direct_connection_.28RESOURCE_LOCAL.29_Persistence.xml

thank you
/michael
Pavel Zelenka

Posts: 13
Registered: 03/25/09
Re: Moving to EclipseLink (SessionCustomizer problem)
Posted: Jun 2, 2009 10:45 PM   in response to: michael_obrien in response to: michael_obrien
 
Click to report abuse...   Click to reply to this thread Reply
Hi Michael,

moving eclipselink.jar into $TOMCAT_HOME$/lib seems to be the solution. After doing so the applications work fine.

So again many thanks for your help.
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums