Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4257646
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T05:32:26+00:00 2026-05-21T05:32:26+00:00

I convert the DB from Oracle to MySQL. I’m using both Java & Hibernate.

  • 0

I convert the DB from Oracle to MySQL.
I’m using both Java & Hibernate.
When I used oracle I had the following method that gave me a brand new and unused sequence value:

protected int getSequenceNextValue() {
    Session session = sessionFactory.getCurrentSession();
    Query query = session.createSQLQuery("select MY_SEQUENCE.NEXTVAL from DUAL");
    return ((BigDecimal) query.uniqueResult()).intValueExact();
}

And I’m trying to refactor this method to work on MySQL DB.
I have a table in MySQL that I use as a sequence (through Hibernate):

create table MY_SEQUENCE(
    next_val int(10) NOT NULL
);

Is there any thread safe way to get a new value from this table and in the same transction to increase it?

For most cases I use the Hibernate Generator to generate a new sequence using this table, but in several cases I need to do it manually.

The best solution for me will be a refactoring of the method above, in such way that threads that querying the table at the same time will not fail, but will wait for each other.

Thanks…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T05:32:27+00:00Added an answer on May 21, 2026 at 5:32 am

    Have a look at the InnoDB table type and FOR UPDATE. An example similar to what you describe is in the MySQL manual here http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert the following statement from SQL Server to Oracle, but everything
I'm trying to come up with a search/replace expression that will convert from Oracle
I would like to convert from a set to a List within a method
How can I convert from bytes to float in php? Like in Java int
I need to convert from sqlite2 db to sqlite3, is there any tutorial that
I have a query that works on MySQL but doesn't work on Oracle, and
My app interacts with both Oracle and SQL Server databases using a custom data
I want to retrieve rows from an oracle table and convert them into objects.
I am migrating data from a Oracle on VMS that accesses data on SQL
I am trying to port a php file that is used with MySQL. My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.