我使用OpenJPA的2.2.2我的persistence.xml就像如下爲什麼雖然我不指定它產生table_seq
<?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="PU" transaction-type="RESOURCE_LOCAL">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<class>package.User</class>
<properties>
<property name="openjpa.ConnectionURL" value="jdbc:postgresql://localhost:5432/postgres" />
<property name="openjpa.ConnectionDriverName" value="org.postgresql.Driver" />
<property name="openjpa.ConnectionUserName" value="postgres" />
<property name="openjpa.ConnectionPassword" value="****" />
<property name="openjpa.DynamicEnhancementAgent" value="true" />
<property name="openjpa.RuntimeUnenhancedClasses" value="supported" />
<property name="openjpa.Log" value="SQL=TRACE" />
<property name="openjpa.ConnectionFactoryProperties" value="PrettyPrint=true, PrettyPrintLineLength=72, PrintParameters=true, MaxActive=10, MaxIdle=5, MinIdle=2, MaxWait=60000" />
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema" />
</properties>
</persistence-unit>
和User.java
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
...
儘管seq_table被創建並且序列(本地一個)不是。如何解決它使用內置序列我正在使用postgreSQL。另外我不明白爲什麼每個PK在上面使用時都是前一個的+50。
請不要將RuntimeUtenhancedClass設置爲受支持。從長遠來看,如果您閱讀OpenJPA網頁中關於增強功能的介紹,那麼您將會更加高興。DynamicEnhancementAgent很好,但不是長期保存的內容。 http://openjpa.apache.org/entity-enhancement.html – Rick
@Rick 我試了一次。經過一個星期,通過無法讀取的文檔,我放棄了。這對我來說太難了,所以我使用它,因爲它是WORK。 – abc
我100%理解......當您遇到由於使用該功能導致的錯誤時,請不要不高興。 – Rick