JavaEE7-实验室教程 - 无法加载数据库?

时间:2014-10-01 20:25:26

标签: java-ee java-ee-7 wildfly-8

我正在关注Java EE7上的教程 - 动手实验here。我按照那里提供的说明设置我的WildFly Application server。一切正常。教程zip附带了示例数据和sql load scripts,用于初始化数据源。如果persistence.xml中未提供数据源,则WildFly将提供教程中提到的default data-source

tutorial link的第3步结束时,我的屏幕截图如下:

enter image description here

但是预期的结果(根据tutorial link:图12)是这样的:

enter image description here

区别在于“在影院放映电影!”就我而言,“在7家影院放映20部电影!”在预期的一个。 用于显示这些数字的JSF模板进行EJB调用,从数据源获取数据。看看这个,我认为我的数据源没有初始化。但我不知道为什么因为我逐字逐句地遵循了教程。我也很难解决这个问题。

提前感谢您的帮助

修改

服务器日志显示Unable to determine H2 database version, certain features may not work.

2014-10-02 18:02:50,167 INFO  [org.hibernate.Version] (ServerService Thread Pool -- 50) HHH000412: Hibernate Core {4.3.5.Final}
2014-10-02 18:02:50,170 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000206: hibernate.properties not found
2014-10-02 18:02:50,172 INFO  [org.hibernate.cfg.Environment] (ServerService Thread Pool -- 50) HHH000021: Bytecode provider name : javassist
2014-10-02 18:02:50,330 INFO  [org.jboss.ws.common.management] (MSC service thread 1-6) JBWS022052: Starting JBoss Web Services - Stack CXF Server 4.2.4.Final
2014-10-02 18:02:50,491 INFO  [org.jboss.as.jpa] (ServerService Thread Pool -- 50) JBAS011409: Starting Persistence Unit (phase 2 of 2) Service 'movieplex7.war#movieplex7PU'
2014-10-02 18:02:50,641 INFO  [org.hibernate.annotations.common.Version] (ServerService Thread Pool -- 50) HCANN000001: Hibernate Commons Annotations {4.0.4.Final}
2014-10-02 18:02:50,875 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 50) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2014-10-02 18:02:50,883 WARN  [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 50) HHH000431: Unable to determine H2 database version, certain features may not work
2014-10-02 18:02:50,922 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 50) HHH000397: Using ASTQueryTranslatorFactory
2014-10-02 18:02:51,047 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 50) HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2014-10-02 18:02:51,048 WARN  [org.hibernate.dialect.H2Dialect] (ServerService Thread Pool -- 50) HHH000431: Unable to determine H2 database version, certain features may not work
2014-10-02 18:02:51,055 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE SALES]
2014-10-02 18:02:51,055 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE POINTS]
2014-10-02 18:02:51,055 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE SHOW_TIMING]
2014-10-02 18:02:51,055 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE MOVIE]
2014-10-02 18:02:51,056 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE TIMESLOT]
2014-10-02 18:02:51,056 WARN  [org.hibernate.jpa.internal.schemagen.GenerationTargetToDatabase] (ServerService Thread Pool -- 50) Unable to execute JPA schema generation drop command [DROP TABLE THEATER]
2014-10-02 18:02:51,250 INFO  [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-8) Initializing Mojarra 2.2.6-jbossorg-4 20140501-1134 for context '/movieplex7'
2014-10-02 18:02:51,867 INFO  [org.wildfly.extension.undertow] (MSC service thread 1-8) JBAS017534: Registered web context: /movieplex7
2014-10-02 18:02:51,905 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS018559: Deployed "movieplex7.war" (runtime-name : "movieplex7.war")
2014-10-02 18:02:51,910 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Http management interface listening on http://127.0.0.1:9990/management
2014-10-02 18:02:51,911 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Admin console listening on http://127.0.0.1:9990
2014-10-02 18:02:51,911 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: WildFly 8.1.0.Final "Kenny" started in 5525ms - Started 256 of 310 services (91 services are lazy, passive or on-demand)

我还在github repo中提出了一个问题: https://github.com/javaee-samples/javaee7-hol/issues/17#issuecomment-57561731

2 个答案:

答案 0 :(得分:2)

所以我得到了应用程序,并尝试运行它(Netbeans,Wildfly-8.1)。它根本没有运行。无法找到数据源的问题。所以(Wildfly开始)我去了管理控制台localhost:9990并输入了我的凭据。在控制台中,选择[配置]选项卡,然后选择[数据源]。没有defaultDataSource。有一个java:jboss/datasources/ExampleDS作为预配置的数据源。所以在persistence.xml中,我将数据源更改为了,并且它有效。仅供参考,我从下载

的解决方案目录中运行了movieplex7

这是我改变整个项目的唯一方法。刚刚将数据源的jndi名称更改为<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>


修改

所以@ArunGupta是正确的。在应用程序中,在persistence.xml中有这个注释掉的行

<!--<jta-data-source>java:comp/DefaultDataSource</jta-data-source>-->

我认为我必须取消注释。通过取消注释,这是导致它最初无法工作的原因。所以我回复了它,并且没有指定任何数据源,即java:jboss/datasources/ExampleDS,它按指定的方式工作。所以你的问题似乎在其他地方。

答案 1 :(得分:0)

添加

<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source>
不应该要求

,因为Java EE 7定义了一个应该自动拾取的新默认数据源。

此问题也在https://github.com/javaee-samples/javaee7-hol/issues/17讨论。