Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

org.hibernate.id.SequenceHiLoGenerator giving wrong id

Getting wrong values from sequence

In weblogic 11, I have 2 manages severs under 1 cluster. I have created 1 datasource on Admin server and attached to cluster. In hibernate side I am using

@XmlTransient
@Id
@Column(name = "id", nullable = false)  
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_NAME")
@SequenceGenerator(name = "SEQ_NAME", sequenceName = "SEQ_NAME")    
public Integer getId() {
    return this.id;
}   

Exception:

org.hibernate.event.def.AbstractSaveEventListener saveWithGeneratedId - generated identifier: 41813, using strategy: org.hibernate.id.SequenceHiLoGenerator org.hibernate.util.JDBCExceptionReporter logExceptions - Could not execute JDBC batch update ......bla..bla..java.sql.BatchUpdateException: ORA-00001: unique constraint

Assumption is only on 2nd managed server I am facing this problem.
Can anyone suggest me please.

like image 753
Sivaji Kummamuri Avatar asked Dec 03 '25 12:12

Sivaji Kummamuri


1 Answers

This might have nothing to do with the server configuration(Cluster etc).

You need to use the allocationSize option.

@SequenceGenerator(name = "productprice_productpriceid_seq", sequenceName = "productprice_productpriceid_seq", allocationSize=1)

Refer below for more details.

https://forum.hibernate.org/viewtopic.php?f=1&t=992448

like image 157
ArunM Avatar answered Dec 06 '25 01:12

ArunM



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!