[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

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.
0
rajeevy69
Asked:
rajeevy69
  • 4
  • 3
4 Solutions
 
Ajay-SinghCommented:
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
 
Ajay-SinghCommented:
Your mapping looks OK, but the behavior is weired. Are you
getting the same sequence all the time?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
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-SinghCommented:
Are you sharing the session across threads?
0
 
rajeevy69Author Commented:
yes.
0
 
rajeevy69Author Commented:
NA
0

Featured Post

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.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now