Hibernate seq genration issue

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.
rajeevy69Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
rajeevy69Connect With a Mentor Author Commented:
yes.
0
 
Ajay-SinghConnect With a Mentor Commented:
Can you post the mapping file?
0
 
rajeevy69Author Commented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
Ajay-SinghConnect With a Mentor Commented:
Your mapping looks OK, but the behavior is weired. Are you
getting the same sequence all the time?
0
 
rajeevy69Author Commented:
not always.

when accessing from different thread,this problem is happening. bu if i try from another instance it works fine.
0
 
Ajay-SinghConnect With a Mentor Commented:
Are you sharing the session across threads?
0
 
rajeevy69Author Commented:
NA
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.