Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8148825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:43:18+00:00 2026-06-06T14:43:18+00:00

Having a deadlock in webservice + hibernate… No idea why. I have the following

  • 0

Having a deadlock in webservice + hibernate… No idea why.

I have the following webservice code (core code of the function)

public String createImageRecipe(...)
{
    Session session = ICDBHibernateUtil.getSessionFactory().getCurrentSession();
    try 
    {
        session.beginTransaction();

        User user = (User) session.load(User.class, userid);

        // Create the recipe
        Recipe recipe = new Recipe();
        ...
        ...
        ...

        session.save(recipe);
        session.save(user);

        ...
        ...
        ...

        session.update( recipe );

        // Add new entry to activity log
        Activitylog activityLog = new Activitylog(  user, 
                                                    (byte) ActivityTypeEnum.USER_SHARED_RECIPE.ordinal(), 
                                                    new Date() );
        activityLog.setRecipe(recipe);
        TimelineProcessor.saveTimeline( activityLog, null, true );

        session.getTransaction().commit();

        endMeasurement();

        return recipe.getRecipeid() + "," + recipe.getImageRecipeUrl();
    } 
    catch (RuntimeException e) 
    {
        ICDBHibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
        throw e;
    }
}

Now the timeline thread (TimelineProcessor) does the following (after getting the message):

    Session session = ICDBHibernateUtil.getTimelineSessionFactory().openSession();
    try {
        session.getTransaction().begin();

        ...
        ...
        ...

        TimelineId tlId = new TimelineId();
        tlId.setUserId(userId);

        User u = new User();
        u.setUserid(userId);

        Timeline tl = new Timeline(tlId, timelineData.getActivitylog(), u);
        session.save(tl);

        session.getTransaction().commit();
        session.close();
    } catch (Exception e) {
        logger.error("Error while processing timeline :: ", e);
        session.getTransaction().rollback();
    }
}

Exceptions from log:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions
at org.hibernate.collection.AbstractPersistentCollection.setCurrentSession(AbstractPersistentCollection.java:435)

ERROR com.icdb.TimelineProcessor – processTimeline – Error while processing timeline ::
org.hibernate.exception.LockAcquisitionException: could not insert: [com.icdb.data.Activitylog]

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLTransactionRollbackException: Deadlock found when trying to get lock; try restarting transaction
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

ERROR com.icdb.TimelineProcessor – processTimeline – Error while processing timeline ::
org.hibernate.HibernateException: Illegal attempt to associate a collection with two open sessions

Will really appriciate help…
Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T14:43:19+00:00Added an answer on June 6, 2026 at 2:43 pm

    Well Hibernate is telling you what it doesn’t like:

    Illegal attempt to associate a collection with two open sessions
    

    You are opening two sessions, and have a transaction in each, and when you save the new timeline in the second session, it has an activityLog, and that activityLog has a user and a recipe that stem from the first session. That’s where Hibernate croaks.

    I’m not sure i see what you are trying to accomplish. Is there a reason you need two separate sessions? Is the timeline something that’s semantically associated with the recipe/user entities or is it more like a timestamp collection? In the former case you probably want to store user, recipe and timeline in one and the same collection, or else you’ll end up with corrupt data if one transaction succeeds and the other one fails. In the latter case the Timestamp service should take value objects as arguments rather than entities, because you’re probably going to want to access it from different parts of your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with each function... Will try to explain by example... In my code,
I am having the following deadlock in SQL Server 2005 with a specific delete
I'm having deadlock problems with this piece of code: def _entropy_split_parallel(data_train, answers_train, weights): CPUS
My program is seemingly having a deadlock problem. Basically I have a class that
Having trouble with ClickOnce manifests and our build server. We have a .p12 code
I am having a problem sometimes with a deadlock when destroying some threads. I've
Having used storyboards for a while now I have found them extremely useful however,
Having following sql server coenfiguration. OS : Windows Server 2003 SQL Server 2005 Professional
We are having an issue when using NHibernate with distributed transactions. Consider the following
having a file with the following for example: DEFINE('INTERESTS_1','a'); DEFINE('INTERESTS_2','d'); DEFINE('INTERESTS_3','g'); DEFINE('INTERESTS_4','c'); Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.