将 glassfish JEE8 weapp 迁移到 Wildfly10 (Jboss) - eclipseLink 不创建数据库表

Posted

技术标签:

【中文标题】将 glassfish JEE8 weapp 迁移到 Wildfly10 (Jboss) - eclipseLink 不创建数据库表【英文标题】:migrate glassfish JEE8 weapp to Wildfly10 (Jboss) - eclipseLink dont create database tables 【发布时间】:2018-02-02 14:27:20 【问题描述】:

我正在wildfly 10 中的jee8 安全示例上安装一个开源项目,因为它只在glassfish 中工作。 我的项目来源在那里:

https://github.com/robyp1/javaee8sec/

您可以在 src/jboss 中找到配置文件和模块:

https://github.com/robyp1/javaee8sec/tree/master/src/main/jboss

我使用 cargo maven 2 插件下载 wildfly10 实例以安装在我的 货物/目标目录。 我将 hsqldb 和 eclipselink 作为模块安装。 Wildfly 使用 EclipseLink jap 持久性提供程序而不是 ibernate 默认提供程序正确启动,但似乎我的 persistence.xml 没有进行更改。

为什么?

<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="soteria" transaction-type="JTA">
        <jta-data-source>java:jboss/jdbc/soteria</jta-data-source>
        <!-- only for jboss -->
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <!-- TODO: parameterize this -->
        <properties>
            <property name="eclipselink.logging.level.sql" value="FINE"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.logging.timestamp" value="true"/>
            <property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
            <property name="eclipselink.ddl-generation.output-mode" value="database"/>

        </properties>
    </persistence-unit>
</persistence>

我将wildfly日志设置为DEBUG:

[INFO] [talledLocalContainer] 14:56:16,869 INFO  [org.jboss.as.jpa] (MSC service thread 1-6) WFLYJPA0002: Read persistence.xml for soteria
[INFO] [talledLocalContainer] 14:56:16,884 DEBUG [io.undertow.session] (ServerService Thread Pool -- 65) Setting default session timeout to 1800
[INFO] [talledLocalContainer] 14:56:16,894 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) persistence unit search for unitName=null referenced from class=id.swhp.javaee.soteria.business.account.boundary.AccountStore (annotation=@PersistenceContext)
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) persistence unit search for unitName=null referenced from class=id.swhp.javaee.soteria.business.security.boundary.TokenScheduler (annotation=@PersistenceContext)
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) persistence unit search for unitName=null referenced from class=id.swhp.javaee.soteria.business.security.boundary.TokenStore (annotation=@PersistenceContext)
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) added javax.persistence.api:main dependency to javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) added org.jboss.as.jpa:main dependency to javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) added org.jboss.as.jpa.spi:main dependency to javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:16,901 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) added org.javassist:main dependency to javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) added org.eclipse.persistence:main dependency to javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) soteria is configured to use persistence provider 'org.eclipse.persistence.jpa.PersistenceProvider', adding an optional dependency on module 'org.eclipse.persistence'
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.business.account.boundary.AccountStore
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component javax.servlet.jsp.jstl.tlv.PermittedTaglibsTLV
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component javax.servlet.jsp.jstl.tlv.ScriptFreeTLV
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.business.security.control.PbkdfGenerator
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component javax.faces.webapp.FacetTag
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component org.omnifaces.ApplicationListener
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.business.security.control.SHAGenerator
[INFO] [talledLocalContainer] 14:56:16,902 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component javax.faces.webapp.FacesServlet
[INFO] [talledLocalContainer] 14:56:16,903 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.application.servlet.AuthenticationFilter
[INFO] [talledLocalContainer] 14:56:16,903 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component com.sun.faces.config.ConfigureListener
[INFO] [talledLocalContainer] 14:56:16,903 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.business.security.boundary.TokenStore
[INFO] [talledLocalContainer] 14:56:16,903 DEBUG [org.jboss.as.jpa] (MSC service thread 1-6) Adding dependency on PU service service jboss.persistenceunit."javaee-soteria.war#soteria" for component id.swhp.javaee.soteria.business.security.boundary.TokenScheduler
[INFO] [talledLocalContainer] 14:56:16,904 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Creating module: deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,904 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource "/C:/Progetti/altri/javaee-soteria-master/target/cargo/configurations/wildfly10x/content/javaee-soteria.war" to module deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,906 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource "/C:/Progetti/altri/javaee-soteria-master/target/cargo/configurations/wildfly10x/content/javaee-soteria.war/WEB-INF/classes" to module deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,906 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource "/C:/Progetti/altri/javaee-soteria-master/target/cargo/configurations/wildfly10x/content/javaee-soteria.war/WEB-INF/lib/hsqldb-2.4.0.jar" to module deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,910 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource "/C:/Progetti/altri/javaee-soteria-master/target/cargo/configurations/wildfly10x/content/javaee-soteria.war/WEB-INF/lib/javax.security.enterprise-1.0.jar" to module deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,919 DEBUG [io.undertow.request] (default I/O-3) Matched default handler path /cargocpc/index.html
[INFO] [talledLocalContainer] 14:56:16,927 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource "/C:/Progetti/altri/javaee-soteria-master/target/cargo/configurations/wildfly10x/content/javaee-soteria.war/WEB-INF/lib/javax.security.enterprise-api-1.1-b01-20170827.084736-2.jar" to module deployment.javaee-soteria.war:main
[INFO] [talledLocalContainer] 14:56:16,938 DEBUG [org.jboss.as.server.deployment] (MSC service thread 1-6) Adding resource

[INFO] [talledLocalContainer] 14:56:17,820 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The access type for the persistent class [class id.swhp.javaee.soteria.business.security.entity.Token] is set to [FIELD].
[INFO] [talledLocalContainer] 14:56:17,843 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The target entity (reference) class for the many to one mapping element [field account] is being defaulted to: class id.swhp.javaee.soteria.business.account.entity.Account.
[INFO] [talledLocalContainer] 14:56:17,843 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The access type for the persistent class [class id.swhp.javaee.soteria.business.account.entity.Account] is set to [FIELD].
[INFO] [talledLocalContainer] 14:56:17,849 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The target entity (reference) class for the one to many mapping element [field tokens] is being defaulted to: class id.swhp.javaee.soteria.business.security.entity.Token.
[INFO] [talledLocalContainer] 14:56:17,850 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The alias name for the entity class [class id.swhp.javaee.soteria.business.security.entity.Token] is being defaulted to: Token.
[INFO] [talledLocalContainer] 14:56:17,860 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [created] is being defaulted to: CREATED.
[INFO] [talledLocalContainer] 14:56:17,861 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [description] is being defaulted to: DESCRIPTION.
[INFO] [talledLocalContainer] 14:56:17,861 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [expiration] is being defaulted to: EXPIRATION.
[INFO] [talledLocalContainer] 14:56:17,861 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [id] is being defaulted to: ID.
[INFO] [talledLocalContainer] 14:56:17,865 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The alias name for the entity class [class id.swhp.javaee.soteria.business.account.entity.Account] is being defaulted to: Account.
[INFO] [talledLocalContainer] 14:56:17,865 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [password] is being defaulted to: PASSWORD.
[INFO] [talledLocalContainer] 14:56:17,865 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [id] is being defaulted to: ID.
[INFO] [talledLocalContainer] 14:56:17,865 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [email] is being defaulted to: EMAIL.
[INFO] [talledLocalContainer] 14:56:17,865 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The column name for element [username] is being defaulted to: USERNAME.
[INFO] [talledLocalContainer] 14:56:17,876 INFO  [org.eclipse.persistence.metadata] (ServerService Thread Pool -- 65) The primary key column name for the mapping element [field account] is being defaulted to: ID.
[INFO] [talledLocalContainer] 14:56:18,069 DEBUG [org.jboss.as.ejb3] (MSC service thread 1-3) Installing timer service for component TokenScheduler
[INFO] [talledLocalContainer] 14:56:18,086 INFO  [org.jboss.weld.deployer] (MSC service thread 1-3) WFLYWELD0003: Processing weld deployment javaee-soteria.war
[INFO] [talledLocalContainer] 14:56:18,125 DEBUG [org.jboss.weld.deployer] (MSC service thread 1-3) Discovered EXPLICIT BeanDeploymentArchive (javaee-soteria.war/WEB-INF/lib/omnifaces-2.6.4.jar)
[INFO] [talledLocalContainer] 14:56:18,126 DEBUG [org.jboss.weld.deployer] (MSC service thread 1-3) Discovered EXPLICIT BeanDeploymentArchive (javaee-soteria.war/WEB-INF/classes)
[INFO] [talledLocalContainer] 14:56:18,181 INFO  [org.hibernate.validator.internal.util.Version] (MSC service thread 1-3) HV000001: Hibernate Validator 5.2.4.Final
[INFO] [talledLocalContainer] 14:56:18,205 DEBUG [org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-3) Found javax.persistence.Persistence on classpath containing 'getPersistenceUtil'. Assuming JPA 2 environment. Trying to instantiate JPA aware TraversableResolver
[INFO] [talledLocalContainer] 14:56:18,206 DEBUG [org.hibernate.validator.internal.engine.resolver.DefaultTraversableResolver] (MSC service thread 1-3) Instantiated JPA aware TraversableResolver of type org.hibernate.validator.internal.engine.resolver.JPATraversableResolver.

你可以在这里找到所有的日志服务器: https://github.com/robyp1/javaee8sec/blob/master/server_20180202.log 或更易读的格式: https://raw.githubusercontent.com/robyp1/javaee8sec/master/server_20180202.log

wng 是什么?

非常感谢

罗伯托

【问题讨论】:

尝试在 Finest 或 ALL 级别进行日志记录,但您是否访问了持久性单元,或者您只是部署然后检查数据库是否已创建? EclipseLink 将延迟部署持久性单元,避免对可能在类路径上但不打算使用的持久性单元进行数据库访问,延迟它们的实际部署,直到它们第一次被访问。您可以通过将 eclipselink.deploy-on-startup 持久性属性设置为 true eclipse.org/eclipselink/documentation/2.4/jpa/extensions/… 来更改此行为 WildFly 与 Java EE 7 兼容,因此您可能需要牢记这一点。 【参考方案1】:

WildFly 使用 Hiberate 作为 JPA 提供程序而不是 EclipseLink!

所以你必须像这样设置属性 hibernate.hbm2ddl.auto

<property name="hibernate.hbm2ddl.auto" value="update"/>

或者您可以使用 JPA 标准属性 javax.persistence.schema-generation.database.action

<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>

这将是可移植的并且独立于 JPA 实现。

您可以在 Hibernate 文档中找到所有选项:

http://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddl

【讨论】:

它随 Hibernate 一起提供,但你应该能够使用任何你想要的 JPA 提供程序。 当然可以,但您为什么要这样做?您不会在社区中找到很多可以帮助您进行该配置的开发人员。此外,RedHat 的所有文档都基于 Hibernate。 拥有像 JPA 这样的规范的想法是可以替换提供者。这并不意味着覆盖应用程序服务器附带的默认 JPA 提供程序是一个好主意。根据我的经验,这通常会导致更多的头痛。 IMO @SimonMartinelli 在这里给出了很好的建议;确保 user 代码可以在不同的 JPA 实现上运行而不是试图弄乱 WildFly 附带的组件可能更容易。 问题在于持久性属性中的一个简单标志。更换供应商类似于有人遇到油灯亮起的问题并说应该将汽车换成福特。尽管他们接受了答案,所以对每个人来说都是如此,但是有很多理由继续使用您在不同部署中使用的不同 JPA 提供程序,因为提供程序仍然有很多独特的细微差别,应用程序可能会被捆绑到。除非服务器做错了什么,否则切换供应商不是,也不应该那么困难。 根据我的经验,切换提供程序是一个坏主意,因为此配置未经任何人测试。因此,您应对使用此配置时出现的任何问题负责。如果您这样做,也没有升级路径,并且您总是必须在应用服务器的每个新版本中重新测试您的配置。所以我的建议。不要那样做!【参考方案2】:

可以在 Wildfly 上使用 EclipseLink,这在参考指南中有记录。简单来说,您需要将 eclipse.jar 添加为模块,然后设置一个属性,以便在standalone.xml 中出现以下条目:

    <property name="eclipselink.archive.factory" value="org.jipijapa.eclipselink.JBossArchiveFactoryImpl"/>

【讨论】:

以上是关于将 glassfish JEE8 weapp 迁移到 Wildfly10 (Jboss) - eclipseLink 不创建数据库表的主要内容,如果未能解决你的问题,请参考以下文章

您如何比较 Apache Tomcat 和 Glassfish 作为生产服务器?

glassfish 3.1.2 - ResultSetWrapper40 无法转换为 oracle.jdbc.OracleResultSet

移至 Glassfish-2.x 集群会导致连接在 1 小时后超时

迁移到 tomcat 后,将枚举值作为参数从 JSF 页面传递给 bean 方法失败

vant Weapp使用 引入

将 WildFly 应用程序服务器与 NetBeans IDE 一起使用