سؤال

I'm using OpenJPA 2.2.2 my persistence.xml is like follows

<?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>

and User.java

@Entity
@Table(name = "users")
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    private long id;
    ...

despite that seq_table is created and sequence (native one) is not. How to fix it to use built-in sequence I'm using postgreSQL. Also I do not understand why each PK is +50 of previous one when using above.

هل كانت مفيدة؟

المحلول

Also I do not understand why each PK is +50 of previous one when using above.

The reason that every PK is +50 from the previous is most likely because you're frequently? creating new EntityManagerFactories. Each time a new EMF is created, it will go back to the sequence table to get a new batch of 50 keys by default. Each time you throw away an EMF, any of the keys that aren't used will essentially be thrown away.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top