@TableGenerator - Pre-allocate ID block not work fine [SOLVED] [message #1320011] |
Mon, 28 April 2014 14:32 |
Antonio Iovino Messages: 3 Registered: April 2014 |
Junior Member |
|
|
Hi at all.
I'm trying to manage the ID generation through the annotation @TableGenerator with allocationSize default. As I understand it, to avoid updating the row for every single identifier that gets requested, an allocation size is used. In theory, the provider should pre-allocate a block of identifiers equal to the value of allocationSize - 50 in this case - and then give out identifiers from memory as requested until the block is used up or the transaction comes to an end. I use Eclipselink with JBoss 7.1 and MySQL.
The problem is that this does not happen. Inserting 3 records in the table Students, EL pre allocates for each record a block of 50 ID, even if the transaction is the same. Then, for each record, there is always access to the table. From the logs I see 3 pre allocations and three pairs of select/update query for the ID and the IDs are generated 1- 51 -101 and the sequence has as its final value 150. Piece of log.
Being a single transaction, I expected sequential IDs (1-2-3) and the final value of the sequence 50. Where am I wrong? Below is the simple test code.
Thanks for the help.
Student Entity
@Entity
@Table(name="STUDENTS")
public class Student implements Serializable
{
private static final long serialVersionUID = 4771385985502937621L;
@TableGenerator(name="TABLE_SEQ")
@Id @Column(name="ID_STUDENT") @GeneratedValue(generator="TABLE_SEQ")
private int idStudent;
private String name;
public int getIdStudent() {
return idStudent;
}
public void setIdStudent(int idStudent) {
this.idStudent = idStudent;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name= name;
}
}
Stateless EJB
@Stateless(name="EJBStudent")
public class EJBStudent implements EJBStudentRemote
{
@PersistenceContext(unitName="JPA_Test")
private EntityManager manager;
public EJBStudent() {
}
@Override
public void insertStudents()
{
manager.getTransaction().begin();
Student student1 = new Student();
student1.setName("Anna");
manager.persist(student1);
Student student2 = new Student();
student2.setName("Paolo");
manager.persist(student2);
Student student3 = new Student();
student3.setName("Luigi");
manager.persist(student3);
manager.getTransaction().commit();
}
}
I tried to replace the commit() with flush(), but nothing changes.
[Updated on: Mon, 05 May 2014 15:40] Report message to a moderator
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04062 seconds