Announcement Announcement Module
Collapse
No announcement yet.
Spring/Hibernate issue with Oracle Sequence Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring/Hibernate issue with Oracle Sequence

    Hi,

    I very much hope you will be able to help!

    I have successfully used a Spring/Hibernate web-based application to insert records into an Oracle database. The Oracle database table that I am writing records to is fairly straightforward - but it is important to know that the first column of the table needs to be populated with the value supplied by a dedicated Oracle Sequence. The problem that I am having is that when I insert a row, I DO NOT ALWAYS seem to get the value of the Oracle Sequence.

    Here is some code, which illustrates the steps I have taken to try to resolve this issue myself:

    Code:
    @Entity
    @SequenceGenerator(name="audit_seq", sequenceName="MARTINI_STORE.STY_SOR_ID_SEQUENCE", allocationSize=1, initialValue= 1)
    @Table(name="MARTINI_STORE.STY_ORDER_RETRY_PAYMENT")
    public class STYOrderRetryPayment implements Serializable {
       /**
        * Serializable class - generated UID
        */
       private static final long serialVersionUID = 4396053457149921483L;
       
       @Id
       @GeneratedValue(strategy=GenerationType.AUTO, generator="audit_seq")
       @Column(name="SOR_ID", nullable=false)
       private long sorId;
    
       //other fields and getters/setters omitted
    The code above shows a snippet from the bean I use to persist data to the table. The field sorId is mapped to the column on the database table that should be populated with the value supplied by the dedicated Oracle Sequence.

    What I have noticed is that stopping and starting the servlet container (Tomcat 6x) can sometimes cause the a value to get inserted into the column that does not match the next available value from the dedicated Oracle Sequence.

    I have tried searching for answers to this issue, but have not come up with anything so far...

    I look forward to hearing from you.
Working...
X