我知道这个问题在持久性用户中很常见。我在很多论坛上访问了很多线索和问题,但我还没有得到解决方案。
我已经从数据库创建了 RESTful Web服务(Netbeans 8.0.2中的一个选项)。 我还为这个项目创建了连接池和JNDI。名称如下所示正确给出。
默认使用EclipseLink(JPA 2.1) 我得到了这样的回应:
GET RequestFailed RequestFailed - >状态:(500) 回复:{ HTTP状态500 - 内部服务器错误
输入例外报告
messageInternal Server Error
description服务器遇到内部错误,导致无法完成此请求。
例外
javax.servlet.ServletException:javax.ejb.EJBException
根本原因
javax.ejb.EJBException异常
根本原因
javax.persistence.PersistenceException:Exception [EclipseLink-4002](Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql.SQLException:未选择任何数据库 错误代码:1046 调用:SELECT id,access_expires,access_token,address,bank_account_type,created,device_id,device_type,email,facebook_id,grazie_code,latitude,longitude,password,phone_number,profile_pic,refresh_expires,refresh_token,reg_id,token_created,total_balance,type_work,user_name,user_type来自用户 查询:ReadAllQuery(referenceClass = Users sql =" SELECT id,access_expires,access_token,address,bank_account_type,created,device_id,device_type,email,facebook_id,grazie_code,latitude,longitude,password,phone_number,profile_pic,refresh_expires,refresh_token, reg_id,token_created,total_balance,type_work,user_name,user_type FROM users")
根本原因
异常[EclipseLink-4002](Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):org.eclipse.persistence.exceptions.DatabaseException 内部异常:java.sql.SQLException:未选择任何数据库 错误代码:1046 调用:SELECT id,access_expires,access_token,address,bank_account_type,created,device_id,device_type,email,facebook_id,grazie_code,latitude,longitude,password,phone_number,profile_pic,refresh_expires,refresh_token,reg_id,token_created,total_balance,type_work,user_name,user_type来自用户 查询:ReadAllQuery(referenceClass = Users sql =" SELECT id,access_expires,access_token,address,bank_account_type,created,device_id,device_type,email,facebook_id,grazie_code,latitude,longitude,password,phone_number,profile_pic,refresh_expires,refresh_token, reg_id,token_created,total_balance,type_work,user_name,user_type FROM users")
根本原因
java.sql.SQLException:未选择数据库
注意GlassFish Server Open Source Edition 4。1日志中提供了异常的完整堆栈跟踪及其根本原因。 GlassFish Server开源4.1版
我的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="dwolla_apiPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/dwolla</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>ALL</shared-cache-mode>
<properties>
<property name="eclipselink.target-database" value="MySQL"/>
<property name="eclipselink.logging.logger" value="DefaultLogger"/>
<property name="eclipselink.ddl-generation" value="create-tables"/>
<property name="eclipelink.logging.level" value="FINEST"/>
<!-- JDBC connection properties -->
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/dwolla"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value=""/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="eclipselink.jdbc.batch-writing" value="JDBC"/>
<property name="javax.persistence.schema-generation.database.action" value="create-tables"/>
</properties>
</persistence-unit>
</persistence>
domain.xml中:
<resources>
<jdbc-resource pool-name="__TimerPool" jndi-name="jdbc/__TimerPool" object-type="system-admin" />
<jdbc-resource pool-name="DerbyPool" jndi-name="jdbc/__default" object-type="system-all" />
<jdbc-resource pool-name="APIConnectionPool" jndi-name="jdbc/dwolla" object-type="user" />
<jdbc-connection-pool name="__TimerPool" datasource-classname="org.apache.derby.jdbc.EmbeddedXADataSource" res-type="javax.sql.XADataSource">
<property value="${com.sun.aas.instanceRoot}/lib/databases/ejbtimer" name="databaseName" />
<property value=";create=true" name="connectionAttributes" />
</jdbc-connection-pool>
<jdbc-connection-pool is-isolation-level-guaranteed="false" name="DerbyPool" datasource-classname="org.apache.derby.jdbc.ClientDataSource" res-type="javax.sql.DataSource">
<property value="1527" name="PortNumber" />
<property value="APP" name="Password" />
<property value="APP" name="User" />
<property value="localhost" name="serverName" />
<property value="sun-appserv-samples" name="DatabaseName" />
<property value=";create=true" name="connectionAttributes" />
</jdbc-connection-pool>
<jdbc-connection-pool is-isolation-level-guaranteed="false" name="APIConnectionPool" datasource-classname="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" res-type="javax.sql.DataSource">
<property name="URL" value="jdbc:mysql://localhost:3306/dwolla"/>
<property value="3306" name="PortNumber" />
<property value="" name="Password" />
<property value="root" name="User" />
<property value="localhost" name="serverName" />
<property value="dwolla" name="DatabaseName" />
<property value=";create=true" name="connectionAttributes" />
</jdbc-connection-pool>
</resources>
<servers>
<server name="server" config-ref="server-config">
<resource-ref ref="jdbc/__TimerPool" />
<resource-ref ref="jdbc/__default" />
<resource-ref ref="jdbc/dwolla" />
</server>
</servers>
答案 0 :(得分:2)
我得到了解决方案。您可以看到我编辑了glassfish服务器的domain.xml并设置了连接池属性和JNDI。我去了glassfish管理控制台并编辑了连接池,我得知服务器没有认识到我所做的更改。它显示了URL属性,如“jdbc:mysql://:3306 /”,不知道为什么它没有从domain.xml获取属性,但最后它现在正在工作。
答案 1 :(得分:1)