Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

jpa - Liberty class loading issues or problem with hibernate (migrating tomcat app on liberty)?

i have to deploy a multi-module application in ear on Liberty Server 20 in my Eclipse. This application use hibernate as provider jpa2 and Derby client + driver derby-10.12.1.1.jar(as shared fileset). Persistence.xml is configured with non jta. This is server.xml:

<enterpriseApplication id="rubrica-ear" location="rubrica-ear.ear" name="rubrica-ear"/>
    <dataSource jndiName="jdbc/TestappDS" type="javax.sql.ConnectionPoolDataSource">


        <properties.derby.client createDatabase="false" databaseName=".rubrica"></properties.derby.client>
        <jdbcDriver>
            <library>
                <fileset dir="C:programmiMiojava-eclipsedrivers" id="shared"></fileset>
            </library>
            
        </jdbcDriver>
    </dataSource>

My .rubrica db location is in /usr/home. Because I dont want to start a server derby on console but automatically, i do taht in a @WebListener class:

@WebListener
public class ReqListener implements ServletContextListener {
    
    static final Logger log =  LoggerFactory.getLogger(ReqListener.class);
    PrintWriter pw = new PrintWriter(System.out);
    private NetworkServerControl derbyserver;
    
    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        try {
            String userHomeDir = System.getProperty("user.home", ".");
            String systemDir = userHomeDir + "/.rubrica";
            // Set the db system directory and startup Server Derby for incoming connections.
            System.setProperty("derby.system.home", systemDir);//il db viene salvato qui

            derbyserver =   new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
            derbyserver.start(pw);
            log.info("Apache derby settings ok");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            log.error(e.getMessage());
        }

    }

    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        if (derbyserver!=null){
            ...
        }

    }

When i deploy i get this error

[ERROR] An error occurred in the org.hibernate.ejb.HibernatePersistence persistence provider when attempting to create the entity manager factory of the testapp persistence unit container. The following error occurred: java.lang.NullPointerException
    at org.hibernate.engine.jdbc.spi.TypeInfo.extractTypeInfo(TypeInfo.java:128)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:163)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:857)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:152)
    at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:67)
    at com.ibm.ws.jpa.management.JPAPUnitInfo.createEMFactory(JPAPUnitInfo.java:919)
    at [internal classes]

When I debug on Liberty i see that Hibernate classes running before the @WebListener code (this is not the same thing in Tomcat), how can i resolve this issue? Something about class loading settings?

I try derby Embedded instead, but problem still araise again, in server.xml:

 <properties.derby.embedded createDatabase="create" databaseName="C:/Users/myuser/.rubrica" shutdownDatabase="false"/>
        <jdbcDriver>
            <library>
                <fileset dir="C:programmiMiojava-eclipsedrivers" id="shared-libs"/>
            </library>
    </jdbcDriver>

Thanks

Roberto

question from:https://stackoverflow.com/questions/65871459/liberty-class-loading-issues-or-problem-with-hibernate-migrating-tomcat-app-on

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...