当我尝试从Netbeans(JavaEE5示例)部署bookstore1 Web应用程序时,我已将persistence.xml文件更改为使用hibernate:
<persistence version="1.0" 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">
<persistence-unit name="book" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/jdbc/BookDB</jta-data-source>
<class>com.sun.bookstore.database.Book</class>
</persistence-unit>
</persistence>
和我的mysql-ds.xml
文件是:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/BookDB</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/bookdb</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>1234</password>
<exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
我收到以下错误:
[STDOUT] Couldn't create bookstore database bean: null 19:16:53,846 INFO [[/bookstore1]] Marking servlet ShowCartServlet as unavailable 19:16:53,846 ERROR [[ShowCartServlet]] Allocate exception for servlet ShowCartServlet javax.servlet.UnavailableException: Couldn't get database. at com.sun.bookstore1.servlets.ShowCartServlet.init(ShowCartServlet.java:39) at javax.servlet.GenericServlet.init(GenericServlet.java:212) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179) at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) at java.lang.Thread.run(Thread.java:619) 19:17:17,534 INFO [[ShowCartServlet]] Servlet ShowCartServlet is currently unavailable
你能告诉我我在哪里做错了吗?
答案 0 :(得分:1)
JBoss 4.0.x不是JavaEE5 appserver,它太旧了 - 它只支持J2EE 1.4
这可能不是问题(不可能从你给我们的信息中得知),但是没有必要继续使用JavaEE5示例和JBoss 4.0.x,它只是不起作用。
您需要使用J2EE 1.4示例应用程序,或升级JBoss(版本5或6)。