Hibernate allocationSize use in custom sequence generator2019 Community Moderator ElectionHow to generate a random alpha-numeric string?How do I generate random integers within a specific range in Java?What are the possible values of the #Hibernate hbm2ddl.auto configuration and what do they doWrong ordering in generated table in jpaWhat's the difference between JPA and Hibernate?Using hibernate3-maven-plugin to generate Sequence ScriptsJPA with SequenceGenerator and GeneratedValueIm getting "com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505Hibernate Id Sequence Resulting nullprimary key constraint violation exception with oracle sequence Generator and JPA
Idiom for feeling after taking risk and someone else being rewarded
Sampling from Gaussian mixture models, when are the sampled data independent?
Logistic regression BIC: what's the right N?
Are small insurances worth it?
What would be the most expensive material to an intergalactic society?
Create chunks from an array
Computation logic of Partway in TikZ
Insult for someone who "doesn't know anything"
Are these two graphs isomorphic? Why/Why not?
If nine coins are tossed, what is the probability that the number of heads is even?
When to use a QR code on a business card?
Rationale to prefer local variables over instance variables?
How to copy the rest of lines of a file to another file
Cycles on the torus
How do you make a gun that shoots melee weapons and/or swords?
Either of .... (Plural/Singular)
Does the US political system, in principle, allow for a no-party system?
Is "cogitate" used appropriately in "I cogitate that success relies on hard work"?
PTIJ: Sport in the Torah
What can I do if someone tampers with my SSH public key?
Are all players supposed to be able to see each others' character sheets?
What is the purpose of a disclaimer like "this is not legal advice"?
Optimal Proportions for Flying Humans
(Codewars) Linked Lists-Sorted Insert
Hibernate allocationSize use in custom sequence generator
2019 Community Moderator ElectionHow to generate a random alpha-numeric string?How do I generate random integers within a specific range in Java?What are the possible values of the #Hibernate hbm2ddl.auto configuration and what do they doWrong ordering in generated table in jpaWhat's the difference between JPA and Hibernate?Using hibernate3-maven-plugin to generate Sequence ScriptsJPA with SequenceGenerator and GeneratedValueIm getting "com.ibm.db2.jcc.am.SqlIntegrityConstraintViolationException: DB2 SQL Error: SQLCODE=-803, SQLSTATE=23505Hibernate Id Sequence Resulting nullprimary key constraint violation exception with oracle sequence Generator and JPA
We are using a SequenceGenerator which is using sequence of our PostgreSQL DB. We know that by default allocationSize() is 50.
Problem is we are moving to custom sequence generator which extends SequenceGenerator class and overridden the function generate(). But some how this is not working and this is contacting DB every time and not keeping buffer on server after multiplying the current sequence by allocationSize().
This is current code of customer sequence generator:
public class UseExistingOrGenerateIdGenerator extends SequenceGenerator
@Override
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException
Serializable id = session.getEntityPersister(null, object)
.getClassMetadata().getIdentifier(object, session);
return id != null ? id : (super.generate(session, object));
In some other class defined the getter:
@Id
@Column(name = "PrimaryID", nullable = false, precision = 38, scale = 0)
@GenericGenerator(name = "primaryIdSeq",
strategy = "com.data.generator.sequence.UseExistingOrGenerateIdGenerator",
parameters =
@Parameter(name = "sequence", value = "Primary_id_SEQUENCE")
)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "primaryIdSeq")
public BigDecimal getReturnId()
return this.returnId;
java postgresql hibernate jpa
add a comment |
We are using a SequenceGenerator which is using sequence of our PostgreSQL DB. We know that by default allocationSize() is 50.
Problem is we are moving to custom sequence generator which extends SequenceGenerator class and overridden the function generate(). But some how this is not working and this is contacting DB every time and not keeping buffer on server after multiplying the current sequence by allocationSize().
This is current code of customer sequence generator:
public class UseExistingOrGenerateIdGenerator extends SequenceGenerator
@Override
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException
Serializable id = session.getEntityPersister(null, object)
.getClassMetadata().getIdentifier(object, session);
return id != null ? id : (super.generate(session, object));
In some other class defined the getter:
@Id
@Column(name = "PrimaryID", nullable = false, precision = 38, scale = 0)
@GenericGenerator(name = "primaryIdSeq",
strategy = "com.data.generator.sequence.UseExistingOrGenerateIdGenerator",
parameters =
@Parameter(name = "sequence", value = "Primary_id_SEQUENCE")
)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "primaryIdSeq")
public BigDecimal getReturnId()
return this.returnId;
java postgresql hibernate jpa
add a comment |
We are using a SequenceGenerator which is using sequence of our PostgreSQL DB. We know that by default allocationSize() is 50.
Problem is we are moving to custom sequence generator which extends SequenceGenerator class and overridden the function generate(). But some how this is not working and this is contacting DB every time and not keeping buffer on server after multiplying the current sequence by allocationSize().
This is current code of customer sequence generator:
public class UseExistingOrGenerateIdGenerator extends SequenceGenerator
@Override
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException
Serializable id = session.getEntityPersister(null, object)
.getClassMetadata().getIdentifier(object, session);
return id != null ? id : (super.generate(session, object));
In some other class defined the getter:
@Id
@Column(name = "PrimaryID", nullable = false, precision = 38, scale = 0)
@GenericGenerator(name = "primaryIdSeq",
strategy = "com.data.generator.sequence.UseExistingOrGenerateIdGenerator",
parameters =
@Parameter(name = "sequence", value = "Primary_id_SEQUENCE")
)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "primaryIdSeq")
public BigDecimal getReturnId()
return this.returnId;
java postgresql hibernate jpa
We are using a SequenceGenerator which is using sequence of our PostgreSQL DB. We know that by default allocationSize() is 50.
Problem is we are moving to custom sequence generator which extends SequenceGenerator class and overridden the function generate(). But some how this is not working and this is contacting DB every time and not keeping buffer on server after multiplying the current sequence by allocationSize().
This is current code of customer sequence generator:
public class UseExistingOrGenerateIdGenerator extends SequenceGenerator
@Override
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException
Serializable id = session.getEntityPersister(null, object)
.getClassMetadata().getIdentifier(object, session);
return id != null ? id : (super.generate(session, object));
In some other class defined the getter:
@Id
@Column(name = "PrimaryID", nullable = false, precision = 38, scale = 0)
@GenericGenerator(name = "primaryIdSeq",
strategy = "com.data.generator.sequence.UseExistingOrGenerateIdGenerator",
parameters =
@Parameter(name = "sequence", value = "Primary_id_SEQUENCE")
)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "primaryIdSeq")
public BigDecimal getReturnId()
return this.returnId;
java postgresql hibernate jpa
java postgresql hibernate jpa
edited Mar 6 at 13:35
jarlh
29.7k52138
29.7k52138
asked Mar 6 at 13:32
rohit royrohit roy
62
62
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024336%2fhibernate-allocationsize-use-in-custom-sequence-generator%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024336%2fhibernate-allocationsize-use-in-custom-sequence-generator%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown