2013-10-15 20 views
0

我使用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。

+0

請不要將RuntimeUtenhancedClass設置爲受支持。從長遠來看,如果您閱讀OpenJPA網頁中關於增強功能的介紹,那麼您將會更加高興。DynamicEnhancementAgent很好,但不是長期保存的內容。 http://openjpa.apache.org/entity-enhancement.html – Rick

+0

@Rick 我試了一次。經過一個星期,通過無法讀取的文檔,我放棄了。這對我來說太難了,所以我使用它,因爲它是WORK。 – abc

+0

我100%理解......當您遇到由於使用該功能導致的錯誤時,請不要不高興。 – Rick

回答

1

另外,我不明白爲什麼每個PK是以前使用上面的+50。

之所以每個PK都是+50的原因很可能是因爲你頻繁?創建新的EntityManagerFactories。每次創建一個新的EMF時,它都會返回到序列表,以默認獲得一批新的50個密鑰。每次扔掉EMF時,任何未使用的鍵都將被丟棄。

+0

對不起,遲到接受。你是對的,只要我在servlet上下文中改變任何東西,重載和序列就會拋出未使用的值。雖然不在生產環境中發生。 – abc

相關問題