1

Is there any possibility to do a kind of "refactor" of allocationSize in order to put it inside the perssitence.xml instead of having to configure it inside each Entity ?

here's what I don't want to have :

@SequenceGenerator(name="AGENT_IDAGENT_GENERATOR", sequenceName="AGENT_SEQ", allocationSize=1)

here's what I'm expecting to have

    <properties>
        <property name="allocationSize" value="1"/>
    </properties>
</persistence-unit>

Thank's in advance

Abderrazak BOUADMA
  • 1,526
  • 2
  • 16
  • 38

2 Answers2

1

If wanting a JPA solution, then you can't put it in persistence.xml, just use orm.xml

DataNucleus
  • 15,497
  • 3
  • 32
  • 37
  • But then again - if every entity have a separate SequenceGenerator, the 'allocationSize=1' must occur in every SequenceGenerator element in orm.xml, right? There is no 'override default value of 50 for allocationSize' for all sequence generators? – Piotr Nowicki Nov 01 '11 at 12:37
  • 1
    Of course, each is specified individually; there is no "persistence-unit-default" for that attribute, as per the JPA spec. JPA implementations themselves usually provide global defaults, DataNucleus does certainly; but we always encourage sticking to the spec. – DataNucleus Nov 01 '11 at 13:34
  • Ok, thanks for clarification @DataNucleus; I just thought that the OP was asking for one-for-all solution. – Piotr Nowicki Nov 01 '11 at 14:11
1

You could use a SessionCustomizer in your persistence.xml, iterate over the Session's login's Sequence objects and set their preallocation size.

An allocation size of 1, it not recommended, it will have poor performance, you may be better off with the default.

James
  • 17,965
  • 11
  • 91
  • 146
  • Agreed about the allocationSize=1. However, maybe the OP must not have a non-continuous IDs? Can't the 'holes' in IDs occur if the server crashes after allocation of some ID blocks? And by the way what is a SessionCustomizer? Is this some Eclipselink specific feature? – Piotr Nowicki Nov 01 '11 at 12:33
  • 1
    Yes, SessionCustomizer is specific to EclipseLink, it gives access to the API and advanced functionality – James Nov 01 '11 at 14:02