Solved

Hibernate seq genration issue

Posted on 2009-07-12
7
422 Views
Last Modified: 2012-05-07
I am trying to instantiate an entity that is mapped to database through hibernate. Id of this entity is generated through seq.

I have instantiated this entity inside thread and trying to save it. Each time seq
in multithreded environemnt, it creates same id.

It seems that hibernate sequence generator is not thread safe. Can anyone help me out in finding a way to make it thread safe in my multithreaded java app.
0
Comment
Question by:rajeevy69
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 250 total points
ID: 24833943
Can you post the mapping file?
0
 

Author Comment

by:rajeevy69
ID: 24838996
Hii,
mapping file looks like this:

<hibernate-mapping>
       
    <class name="Employer" table="employers">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">employer_id_seq</param>
            </generator>
        </id>
        <property name="name"/>
     <property name="country"/>

    </class>
</hibernate-mapping>
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 250 total points
ID: 24840542
Your mapping looks OK, but the behavior is weired. Are you
getting the same sequence all the time?
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:rajeevy69
ID: 24840606
not always.

when accessing from different thread,this problem is happening. bu if i try from another instance it works fine.
0
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 250 total points
ID: 24840813
Are you sharing the session across threads?
0
 

Accepted Solution

by:
rajeevy69 earned 0 total points
ID: 24841273
yes.
0
 

Author Comment

by:rajeevy69
ID: 25502517
NA
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question