Announcement Announcement Module
Collapse
No announcement yet.
Spring SessionFactory passing is at the root of a hibernate bug Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring SessionFactory passing is at the root of a hibernate bug

    So, I wasn't sure whether to post this on Spring or Hibernate, so I decided to go with both. I've found a bug (null pointer exception in Hibernate) that only can happen when the Hibernate session used is obtained by passing in a Hibernate SessionFactory through Spring Autowiring and using the getCurrentSession() method. The actual causation of the bug is too complex to post here, but I've attached a zipped up Maven project that demonstrates the bug. Is there a Jira or some such I can post this to?

    EDIT:
    forgot to put the database schema in the zip.


    Attachment

    -Scott-
    Attached Files
    Last edited by scott.albertine; Apr 27th, 2012, 10:53 AM.

  • #2
    For starters you aren't managing your relationships properly. You have a bi-directional relationship but only set 1 part of the relationship whereas you should set both. Next to that you should NEVER override a hibernate managed collection as you do in your setLinkedEntities method (clear the current collection and add all entries). YOu should never have a setCollection method with hibernate managed entities, next to that your getCollection should actually be returning an unmodifiable collection so that only the owning entity can modify the content.

    So in short I doubt it is a (hibernate) bug but more or less programming things you shouldn't be doing with managed entities.

    Comment


    • #3
      I tried setting both parts of the bi-directional relationship, and the bug still persists in the same manner.

      I've also tried doing the clear+addAll method for replacing collections, it doesn't work for the initial creation of the collection, which causes the issue shown here. The reason is, the collection Hibernate uses to represent an empty set of a many-to-many collection is an internal PersistentSet, which (if empty) cannot be added to, because it wraps EmptySet, an unmodifiable singleton. Thus, the only way to add the first linked element set to the parent object is to create a set and assign it to the collection, which is what I'm doing here.

      I don't think I ever use the getLinkedEntities method, I included it for standards and completeness' sake.

      Comment


      • #4
        That is not what I see. Everything works all green bars... So not sure what you and I do differently.

        Comment

        Working...
        X