是否有可能使JPA使用SSL進行連接。我不太瞭解JPA,因此我無法提供有關使用哪個版本和提供程序的許多詳細信息,但這裏是我的persistence.xml文件的一個簡化版本。是否有可以添加的屬性使其使用安全連接?SSL與EclipseLink JPA
<?xml version="1.0" encoding="UTF-8" ?>
<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"
version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="MY_PERSISTENCE_UNIT" transaction-type="RESOURCE_LOCAL">
<!-- declare class entities here -->
<properties>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://URL_TO_SERVER" />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="javax.persistence.jdbc.user" value="USERNAME" />
<property name="javax.persistence.jdbc.password" value="PASSWORD" />
<!-- Optimize database writes to use batching. -->
<property name="eclipselink.jdbc.batch-writing" value="JDBC" />
<!-- Avoids flush being triggered before every query execution. -->
<property name="eclipselink.persistence-context.flush-mode"
value="COMMIT" />
<!-- Configure connection pool. -->
<property name="eclipselink.jdbc.connections.initial" value="1" />
<property name="eclipselink.jdbc.connections.min" value="64" />
<property name="eclipselink.jdbc.connections.max" value="64" />
<!-- Timeout for connection. -->
<property name="eclipselink.jdbc.timeout" value="10" />
<!-- Configure cache size. -->
<property name="eclipselink.cache.size.default" value="1000" />
<!-- Configure database to be created on startup if not already existing.-->
<property name="eclipselink.ddl-generation" value="create-tables" />
<!-- Configure simple SQL logging for demonstration. -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.exceptions" value="false" />
<property name="eclipselink.logging.timestamp" value="false" />
</properties>
</persistence-unit>
謝謝!這些信息看起來很有希望得到這個工作。在初始化數據庫連接(使用System.setProperty)之前,我是否必須在java代碼中設置這些屬性,或者可以在問題中設置persistence.xml文件中的屬性(使用
Nitrex88
請注意,我不直接使用JDBC連接字符串(JPA處理此問題,這就是爲什麼JPA特定於我) – Nitrex88
不會有太大的差別,參數可以添加到javax.persistence.jdbc的值中。網址 –