2013-10-15 18 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

相关问题