created on | January 28, 2022 |
provide the JDBC library
there a several ways to provide the JDBC library
- copy the library to the directory META-INF/lib
- provide the classpath to the library on startup of payara micro with
config file is
example:
<?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="whateverCP"
res-type="javax.sql.ConnectionPoolDataSource"
datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource"
pool-resize-quantity="2"
max-pool-size="32"
steady-pool-size="8">
<property name="serverName" value="idoru"></property>
<property name="portNumber" value="5432"></property>
<property name="databaseName" value="whatever"></property>
<property name="user" value="spongebob"/>
<property name="password" value="devel42"/>
</jdbc-connection-pool>
<jdbc-resource pool-name="whateverCP"
jndi-name="java:app/whateverCP"
enabled="true"
object-type="user">
</jdbc-resource>
</resources>
config file is
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.2"
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_2.xsd">
<persistence-unit name="jpa-unit" transaction-type="JTA">
<jta-data-source>java:app/whateverCP</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<shared-cache-mode>NONE</shared-cache-mode>
<properties>
<property name="eclipselink.logging.level.sql" value="FINE" />
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.level.cache" value="FINE" />
</properties>
</persistence-unit>
</persistence>
persistance unit access in repos
public class WhateverRepo {
@PersistenceContext(unitName = "jpa-unit")
private EntityManager em;
public void create(Whatever entity) {
em.persist(entity);
}
...
reference
stackoverflow.com
How do I add JDBC drivers and configure JDBC Resources in Payara Micro?