[Logo] Terracotta Discussion Forums
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
JPA and CustomLoader exception  XML
Forum Index -> Terracotta Platform
Author Message
desirazu

neo

Joined: 02/04/2008 20:31:00
Messages: 7
Offline

The following program runs with a system class loader but fails with
the CustomLoader (I am trying to have the ehcache load under the same
classloadername + resource name - sharing an ehcache between a JBOSS
instance and a standalone program using JPA). I am using a hibernate
persistence provider that comes with JBOSS AS.

The stacktrace is

Code:
Exception in thread "main" java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at client.CustomLoader.main(CustomLoader.java:28)
 Caused by: java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence
         at javax.persistence.Persistence.findAllProviders(Persistence.java:112)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:79)
         at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:60)
         at client.ClientEMF.main(ClientEMF.java:14)
         ... 5 more
 

 

Here are the relevant files.

Any ideas as to what is going on.

Thanks

ClientEMF.java
--------------

Code:
package client;
 
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.Persistence;
 
 public class ClientEMF {
 	public static void main(String[] args) {
 
 	    EntityManagerFactory emf = Persistence.createEntityManagerFactory("tDatabase");
 	    EntityManager em  = emf.createEntityManager();
 	    em.close();
 	}
 }

 


CustomLoader.java
-----------------
Code:
package client;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.net.URLClassLoader;
 import com.tc.object.bytecode.hook.impl.ClassProcessorHelper;
 import com.tc.object.loaders.NamedClassLoader;
 
 public class CustomLoader {
 
     // usage: java CustomLoader com.example.MyRealMainClass [arg1] [arg2]
 
     public static void main(String[] args) throws Exception {
         URL[] systemURLs = ((URLClassLoader) ClassLoader.getSystemClassLoader())
                 .getURLs();
 
         ClassLoader loader = new URLClassLoader(systemURLs, ClassLoader
                 .getSystemClassLoader().getParent());
         ((NamedClassLoader) loader).__tc_setClassLoaderName("com/caucho/loader/EnvironmentClassLoader");
         ClassProcessorHelper.registerGlobalLoader((NamedClassLoader) loader);
 
         Class mainClass = loader.loadClass(args[0]);
 
         Method main = mainClass.getMethod("main",
                 new Class[] { args.getClass() });
 
         String[] nextArgs = new String[args.length - 1];
         System.arraycopy(args, 0, nextArgs, 0, nextArgs.length);
         main.invoke(null, new Object[] { nextArgs });
     }
 
 }


 


persistence.xml
----------------

<?xml version="1.0" encoding="UTF-8"?>
<persistence
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"
version="1.0">
<persistence-unit name="tDatabase">
<properties>
<property name="hibernate.archive.autodetection" value="class, hbm"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.password" value="xxxx1234"/>
<property name="hibernate.connection.url" value="jdbc:mysql://xxx:3306/rfoptimise?user=xxxuser&password=xxx1234"/>
<property name="hibernate.connection.username" value="xxxuser"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
</properties>
</persistence-unit>
</persistence>

 
tgautier

seraphim

Joined: 06/05/2006 12:19:26
Messages: 1781
Offline

Are you able to post a sample that we can take a look at?
[WWW]
njain

jedi

Joined: 01/03/2007 06:41:59
Messages: 107
Offline

where do you get this error, is it in JBoss application server or standalone app?

In JBoss application server where did you copy hibernate jars? In war or shared/common lib?

Which version of JBoss and terracotta?

Regards,

Nitin Jain
Terracotta, Inc.

Join the Terracotta Community
desirazu

neo

Joined: 02/04/2008 20:31:00
Messages: 7
Offline

It is a simple standalone application. Just four lines that create an entity manager factory and a entity manager. I use all the hibernate libraries that came with JBOSS 4.2.x

Here is the tc-config.xml

Code:
 <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd">
          <servers>
  
                  <!-- Tell DSO where the Terracotta server can be found. -->
                  <server host="localhost">
                          <data>%(user.home)/terracotta/server-data</data>
                          <logs>%(user.home)/terracotta/server-logs</logs>
                  </server>
          </servers>
  
          <!-- Tell DSO where to put the generated client logs -->  
          <clients>
                  <modules>
                          <module name="clustered-ehcache-1.2.4" version="2.5.0"/>
  			<module name="clustered-cglib-2.1.3" version="2.5.0"/>
  			<module name="clustered-hibernate-3.1.2" version="2.5.0"/>
  			<module name="clustered-ehcache-commons-1.0" version="2.5.0"/>
                  </modules>
                  <logs>%(user.home)/terracotta/client-logs</logs>
          </clients>
 <application>
   <dso>
 <roots>
   <root>
     <field-name>
       org.hibernate.cache.EhCacheProvider.manager
     </field-name>
   </root>
 </roots>
     <instrumented-classes>
       <include>
         <class-expression>
           client..*
         </class-expression>
         <honor-transient>true</honor-transient>
       </include>
          <include>
            <class-expression>org.apache.commons.logging.impl.Log4JLogger</class-expression>
          </include>
          <include>
            <class-expression>org.apache..*</class-expression>
          </include>
     </instrumented-classes>
     <locks>
       <autolock>
         <method-expression>* *..*.*(..)</method-expression>
         <lock-level>write</lock-level>
       </autolock>
     </locks>
 
   </dso>
 </application>
 
  </tc:tc-config>
 

desirazu

neo

Joined: 02/04/2008 20:31:00
Messages: 7
Offline

Here is the command I used to run the program.

Code:
set JAVA=c:\Program Files\Terracotta\terracotta-2.5.0\bin\dso-java.bat
 
 "%JAVA%" %JAVA_OPTS%  -Dtc.config=tc-config.xml -cp "Client.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/antlr.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/cglib.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/commons-collections.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/javassist.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/commons-logging.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/dom4j.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/ejb3-persistence.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/hibernate-annotations.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/hibernate-entitymanager.jar;c:/Servers/jboss-4.2.2.GA/server/default/lib/hibernate3.jar;c:/Servers/jboss-4.2.2.GA/client/jbossall-client.jar;C:/Servers/ReverseEngineer/mysql-connector-java-3.0.17-ga-bin.jar;C:/Servers/ReverseEngineer/ehcache-1.2.4.jar" client.CustomLoader client.ClientEMF

 


desirazu

neo

Joined: 02/04/2008 20:31:00
Messages: 7
Offline

The fix was to make a change to the Custom Loader as described in the last post in
http://forums.terracotta.org/forums/posts/list/805.page
 
Forum Index -> Terracotta Platform
Go to:   
Powered by JForum 2.1.7 © JForum Team