Java – why not create a JDBC connection pool?

I'm developing a simple Java EE application with ear files containing jar and war files In the ear project under earcontent / meta inf, I have the following 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>

In the EJB project under meta inf, I have the following 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>

I have a running Derby server with the correct port number The application is working without creating any databases There may be something wrong with this approach working with GlassFish 3.1

Hank

Solution

It seems that the JDBC data source of GlassFish V4 configuration has changed a little from v3 You need to specify the connectionattributes attribute to create the database The attribute createdatabase has no record and may be ignored

The attribute connectionattributes is not well documented, but you can find an example in the GlassFish 4 PDF document (administration guide – managing JDBC connection pools) or the payara server from GlassFish 4

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>