views:

21

answers:

1

Hi,

I have an entity, a Group, which has User objects inside it. On creation of a User, that User is added to a Group. This is done through an API, so the flow of control is roughly:

  1. Complete web form for new user, submit
  2. Hibernate creates new user, adds user to group
  3. Website requests group and list of users
  4. Hibernate loads and returns group
  5. Website displays group

Now, when the User is first created, they are never present in the Group that is returned. On refresh, the User appears. On another refresh, the User is present, upon a third (?!) refresh, an ObjectNotFoundException is thrown for the newly-created User object.

I have been battling with this for days, I don't know which parts of the Hibernate actions are relevant, so will eagerly provide more details when needed.

A: 

I was trying to be clever, I was updating the many-to-many table via SQL and then trying to force Hibernate to reload. I've re-architected the process such that I just let Hibernate take care of the many-to-many table and now everything seems to work fine.

Martin