从Glassfish迁移到Wildfly / JBoss

时间:2017-05-17 11:43:14

标签: java mysql jboss glassfish wildfly

我正在尝试在 JBoss(wildfly-10.1.0.Final)中运行我的.ear应用程序。 以前它与 Glassfish 4.1 一起运行没有任何问题。 在JBoss上,我成功地部署了它,但它引发了大量例外。

例如:

2017-05-17 13:42:00,911 ERROR [org.jboss.as.ejb3.invocation] (default task-18) WFLYEJB0034: EJB Invocation failed on component VersionDao for method public abstract java.util.List com.valor.anthillprodashboard.db.dao.VersionDaoLocal.getAllVersions(): javax.ejb.EJBTransactionRolledbackException: NamedQuery of name: Version.findAll not found.
            at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:159)

2017-05-17 13:40:03,504 ERROR [org.jboss.as.ejb3.invocation] (default task-110) WFLYEJB0034: EJB Invocation failed on component DataAccessFacade for method public abstract java.util.List com.valor.anthillprodashboard.bl.da.DataAccessFacadeLocal.getAllVersions(): javax.ejb.EJBTransactionRolledbackException: NamedQuery of name: Version.findAll not found.
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:159)

在这两种情况下,我都使用 eclipselink &的的MySQL

我尝试使用与Glassfish相同的参数配置JBoss。

Glassfish配置:

  • JDBC资源: JDBC Resource
  • JDBC连接池: JDBC Connection Pool

JBoss Config(来自standalone.xml):

<datasources>
    <datasource jta="true" jndi-name="java:/jdbc/anthillprodashboard" pool-name="mysql_anthillprodashboard_rootPool" enabled="true" use-java-context="true" use-ccm="true">
        <connection-url>jdbc:mysql://localhost:3306/anthillprodashboard?zeroDateTimeBehavior=convertToNull</connection-url>
        <driver>mysql</driver>
        <security>
            <user-name>****</user-name>
            <password>****</password>
        </security>
        <statement>
            <prepared-statement-cache-size>100</prepared-statement-cache-size>
            <share-prepared-statements>true</share-prepared-statements>
        </statement>
    </datasource>
    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
        <driver>h2</driver>
        <security>
            <user-name>sa</user-name>
            <password>sa</password>
        </security>
    </datasource>
    <drivers>
        <driver name="mysql" module="com.mysql"/>
        <driver name="h2" module="com.h2database.h2">
            <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
        </driver>
    </drivers>
</datasources>

My Persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="AnthillProDashboard-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/anthillprodashboard</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
    </properties>
  </persistence-unit>
</persistence>

这些例外没有任何意义,因为同样的方法在glassfish上运行良好。 这些例外可能是什么原因?

1 个答案:

答案 0 :(得分:0)

出于某种原因,JBoss无法识别实体,我必须在 persistence.xml 中指定它们:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
  <persistence-unit name="AnthillProDashboard-ejbPU" transaction-type="JTA">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <jta-data-source>jdbc/anthillprodashboard</jta-data-source>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <shared-cache-mode>NONE</shared-cache-mode>
    <class>com.valor.anthillprodashboard.db.entity.Build</class>
    <class>com.valor.anthillprodashboard.db.entity.Commit</class>
    <class>com.valor.anthillprodashboard.db.entity.Project</class>
    <class>com.valor.anthillprodashboard.db.entity.ProjectVersion</class>
    <class>com.valor.anthillprodashboard.db.entity.ProjectVersionPK</class>
    <class>com.valor.anthillprodashboard.db.entity.Status</class>
    <class>com.valor.anthillprodashboard.db.entity.TestSet</class>
    <class>com.valor.anthillprodashboard.db.entity.TestSetUpdate</class>
    <class>com.valor.anthillprodashboard.db.entity.TestStatus</class>
    <class>com.valor.anthillprodashboard.db.entity.Version</class>
    <class>com.valor.anthillprodashboard.db.entity.Workflow</class>

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
    </properties>
  </persistence-unit>
</persistence>