Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hibernate seq genration issue

Posted on 2009-07-12
7
Medium Priority
?
432 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 1000 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 1000 total points
ID: 24840542
Your mapping looks OK, but the behavior is weired. Are you
getting the same sequence all the time?
0
Independent Software Vendors: 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!

 

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 1000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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 …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Suggested Courses

886 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