Solved

Hibernate seq genration issue

Posted on 2009-07-12
7
402 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 22
SHA2 certs for IIS AND Java? 2 94
servlet example 17 32
Adding multiple JVM environments to RedHat 6 7 23
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

823 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