openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: allocationSize Problem, please Help!!!
Date Sun, 14 Mar 2010 04:03:06 GMT
Hi,
On first blush, this looks like a potential problem with OpenJPA's usage of
Sequence generators with Postgres, but I'm not an expert with Postgres.

As a first test, I would try using the default Sequence generator and see if
OpenJPA's default sequence generator and usage works okay with Postgres.
Comment out your generator:

// @SequenceGenerator(name = "TipoMetricaSeq", sequenceName =
// "TIPO_METRICA_ID_SEQ", initialValue = 1, allocationSize = 10)

And, then use the default generator:

   @GeneratedValue(strategy = GenerationType.SEQUENCE)

See what happens with that.

The other thing to do is to turn on the SQL trace on see what is actually
being sent to the database to generate and utilize the Sequence generator.
You can do that with the openjpa.Log property:

       <property name="openjpa.Log" value="SQL=TRACE"/>

The Postgres dictionary provides all of the unique logic with Postgres.  If
there's a problem, that would be the first place to debug.

Thanks,
Kevin

On Sat, Mar 13, 2010 at 4:47 PM, Horacio Andrés Antonelli <
horacioantonelli@gmail.com> wrote:

> Hi everybody!
>
> I'm working in a small project with postgres and today I noticed a problem
> with the cache.
> Basically, the problem is that the cache is not using the alocation size
> properly. It is asking each time for 10 IDs, using ONLY one of them, and
> then asking for another 10, resulting in big ID holes (I get 9 empty spaces
> for every.time an entity is inserted in the database)
>
> Here are the classes:
>
>
> -Main.java------------------------------------------------------------------------
>
> package test;
>
> import javax.persistence.EntityManager;
> import javax.persistence.EntityManagerFactory;
> import javax.persistence.EntityTransaction;
> import javax.persistence.Persistence;
>
>
> public class Main {
>
>    public static void main(String[] args) {
>        try {
>
>            System.out.println("test");
>            EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("TEST");
>            EntityManager em = emf.createEntityManager();
>            EntityTransaction et = em.getTransaction();
>            et.begin();
>
>            TipoMetrica tipoMetrica = new TipoMetrica();
>            tipoMetrica.setCodigo(7001);
>            tipoMetrica.setDescripcion("Metrica de Prueba");
>            tipoMetrica.setDescripcionDato1("reporteId");
>            tipoMetrica.setDescripcionDato2("ContenedorId");
>            tipoMetrica.setDescripcionDato3("DetalleContenedorId");
>            tipoMetrica.setProceso("ProcesarArchivo");
>            em.persist(tipoMetrica);
>
>            TipoMetrica tipoMetrica2 = new TipoMetrica();
>            tipoMetrica2.setCodigo(7001);
>            tipoMetrica2.setDescripcion("Metrica de Prueba");
>            tipoMetrica2.setDescripcionDato1("reporteId");
>            tipoMetrica2.setDescripcionDato2("ContenedorId");
>            tipoMetrica2.setDescripcionDato3("DetalleContenedorId");
>            tipoMetrica2.setProceso("ProcesarArchivo");
>            em.persist(tipoMetrica2);
>
>            et.commit();
>            em.close();
>
>        } catch(Exception rte) {
>
> System.out.println(rte.getCause().toString()+rte.getStackTrace());
>        }
>    }
>
> }
>
>
>
> -TipoMetrica.java------------------------------------------------------------------------
>
> package test;
>
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.SequenceGenerator;
> import javax.persistence.Table;
>
> @Entity
> @Table(name = "TIPO_METRICA")
> @SequenceGenerator(name = "TipoMetricaSeq", sequenceName =
> "TIPO_METRICA_ID_SEQ", initialValue = 1, allocationSize = 10)
> public class TipoMetrica {
>    private Integer id;
>
>    private String descripcion;
>
>    private String descripcionDato1;
>
>    private String descripcionDato2;
>
>    private String descripcionDato3;
>
>    private Integer codigo;
>
>    private String proceso;
>
>    @Id
>    @Column(name = "TIPO_METRICA_ID", nullable = false)
>    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "TipoMetricaSeq")
>    public Integer getId() {
>        return id;
>    }
>
>    public void setId(Integer id) {
>        // begin-user-code
>        this.id = id;
>        // end-user-code
>    }
>
>    @Column(name = "DESCRIPCION", length = 30)
>    public String getDescripcion() {
>        // begin-user-code
>        return descripcion;
>        // end-user-code
>    }
>    public void setDescripcion(String descripcion) {
>        // begin-user-code
>        this.descripcion = descripcion;
>        // end-user-code
>    }
>
>
>
>    @Column(name = "DESCRIPCION_DATO_1", length = 30)
>    public String getDescripcionDato1() {
>        // begin-user-code
>        return descripcionDato1;
>        // end-user-code
>    }
>
>    public void setDescripcionDato1(String descripcionDato1) {
>        // begin-user-code
>        this.descripcionDato1 = descripcionDato1;
>        // end-user-code
>    }
>
>
>
>    @Column(name = "DESCRIPCION_DATO_2", length = 30)
>    public String getDescripcionDato2() {
>        // begin-user-code
>        return descripcionDato2;
>        // end-user-code
>    }
>
>    public void setDescripcionDato2(String descripcionDato2) {
>        // begin-user-code
>        this.descripcionDato2 = descripcionDato2;
>        // end-user-code
>    }
>
>
>    @Column(name = "DESCRIPCION_DATO_3", length = 30)
>    public String getDescripcionDato3() {
>        // begin-user-code
>        return descripcionDato3;
>        // end-user-code
>    }
>
>    public void setDescripcionDato3(String descripcionDato3) {
>        // begin-user-code
>        this.descripcionDato3 = descripcionDato3;
>        // end-user-code
>    }
>
>
>    @Column(name = "CODIGO")
>    public Integer getCodigo() {
>        // begin-user-code
>        return codigo;
>        // end-user-code
>    }
>
>    public void setCodigo(Integer codigo) {
>        // begin-user-code
>        this.codigo = codigo;
>        // end-user-code
>    }
>
>
>    @Column(name = "PROCESO", length = 30)
>    public String getProceso() {
>        // begin-user-code
>        return proceso;
>        // end-user-code
>    }
>    public void setProceso(String proceso) {
>        // begin-user-code
>        this.proceso = proceso;
>        // end-user-code
>    }
> }
>
>
> and here is the
>
> persistence.xml------------------------------------------------------------------------
>
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    version="1.0">
>    <persistence-unit name="TEST" transaction-type="RESOURCE_LOCAL">
>
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>
>
>      <class>test.TipoMetrica</class>
>
>      <properties>
>          <property name="openjpa.ConnectionDriverName"
> value="org.postgresql.Driver"/>
>          <property name="openjpa.ConnectionURL"
> value="jdbc:postgresql://localhost:5432/IM2"/>
>          <property name="openjpa.ConnectionUserName" value="user"/>
>          <property name="openjpa.ConnectionPassword" value="pass"/>
>          <property name="openjpa.jdbc.Schema" value="APP"/>
>      </properties>
>
>    </persistence-unit>
> </persistence>
>
>
> This is the sequence
>
> generated-------------------------------------------------------------------------------
> CREATE SEQUENCE app.tipo_metrica_id_seq
>  INCREMENT 1
>  MINVALUE 1
>  MAXVALUE 9223372036854775807
>  START 40
>  CACHE 10;
> ALTER TABLE app.tipo_metrica_id_seq OWNER TO "Hantone";
>
> here is what is stored in the
>
> database------------------------------------------------------------------------
>
> tipo_metrica_id;codigo;descripcion;descripcion_dato_1;descripcion_dato_2;descripcion_dato_3;proceso
> 1;7001;"Metrica de
> Prueba";"reporteId";"ContenedorId";"DetalleContenedorId";"ProcesarArchivo"
> 11;7001;"Metrica de
> Prueba";"reporteId";"ContenedorId";"DetalleContenedorId";"ProcesarArchivo"
> 21;7001;"Metrica de
> Prueba";"reporteId";"ContenedorId";"DetalleContenedorId";"ProcesarArchivo"
> 31;7001;"Metrica de
> Prueba";"reporteId";"ContenedorId";"DetalleContenedorId";"ProcesarArchivo"
>
> As you can see, the tipo_metrica_id "jumps" for 1 to 11 to 21 to 31,
> "jumping" the allocationSize
> Thanks in advance for all your help in this matter!
>
> Horacio Antonelli
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message