我正在开发一个包含JAR和WAR文件的EAR文件的简单
Java EE应用程序.在EarContent / Meta-INF下的EAR项目中,我有以下glassfish-resources.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd"> <resources> <jdbc-connection-pool name="java:app/jdbc/test" res-type="javax.sql.XADataSource" datasource-classname="org.apache.derby.jdbc.ClientXADataSource"> <property name="serverName" value="localhost"/> <property name="portNumber" value="1527"/> <property name="databaseName" value="test"/> <property name="createDatabase" value="create"/> <property name="user" value="APP"/> <property name="password" value="APP"/> </jdbc-connection-pool> <jdbc-resource jndi-name="java:app/jdbc/test" pool-name="java:app/jdbc/test"/> </resources>
在Meta-INF下的EJB项目中,我有以下persistence.xml:
<?xml version="1.0" encoding="UTF-8"?> <persistence version="2.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_2_0.xsd"> <persistence-unit name="events" transaction-type="JTA"> <description>Manages events,users and comments</description> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> <jta-data-source>java:app/jdbc/test</jta-data-source> <class>com.hank.entity.Question</class> <class>com.hank.entity.QuizWalk</class> <class>com.hank.entity.User</class> <class>com.hank.entity.QuizWalkParticipants</class> <properties> <property name="eclipselink.ddl-generation" value="create-tables"/> <property name="eclipselink.logging.connection" value="false"/> <property name="eclipselink.logging.level.sql" value="ALL"/> <property name="eclipselink.logging.parameters" value="true"/> <property name="eclipselink.logging.session" value="false"/> <property name="eclipselink.logging.thread" value="false"/> <property name="eclipselink.logging.timestamp" value="false"/> </properties> </persistence-unit> </persistence>
我有一个运行的Derby服务器,端口号是正确的.该应用程序正在工作,但不创建任何数据库.可能有什么不对这种方法与Glassfish 3.1合作.
汉克
解决方法
看来,Glassfish v4配置的jdbc数据源从v3更改了一点.您需要指定connectionAttributes属性来创建数据库.属性createDatabase没有记录,可能被忽略.
属性connectionAttributes还没有很好地记录,但是您可以在Glassfish 4 PDF文档(Administration Guide – 管理JDBC连接池)部分或源自Glassfish 4的Payara server中找到一个示例.