Solved

Hibernate seq genration issue

Posted on 2009-07-12
7
394 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
  • 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now