7 Replies Latest reply on Nov 25, 2008 10:27 AM by adamw

    Collection problem

    mirtzi

      Hi,

      I've recently upgraded to 1.1.0 for hibernate 3.3 version and I wanted to try the collections support, but I'm getting the following error org.hibernate.MappingException: Unable to read the mapped by attribute for components in model.Equipment!

      My entities are:


      @MappedSuperclass
      public class BaseEntity implements Serializable {
      
       private Long id;
      
       @Id
       @GeneratedValue(strategy=GenerationType.TABLE)
       public Long getId() {
       return this.id;
       }
      
       //setter
      }



      @Entity
      @Table(name = "EQUIPMENT")
      @Versioned
      public class Equipment extends BaseEntity{
      
       private List<Component> components;
      
       @IndexColumn(name = "id")
       @OneToMany(mappedBy = "equipment")
       public List<Component> getComponents() {
       return components;
       }
      
       //setter
      }
      


      @Entity
      @Table(name = "COMPONENT")
      @Versioned
      public class Component extends BaseEntity{
      
       private Equipment equipment;
      
       @ManyToOne
       @JoinColumn(name = "equipment_id", nullable = false)
       public Equipment getEquipment() {
       return equipment;
       }
      
       //setter
      }
      


      Any ideas? Please help.

        • 1. Re: Collection problem
          mirtzi

          I forgot to say... it works if I make the collection unversioned... so I think it's an envers problem

          • 2. Re: Collection problem
            adamw

            Hello,

            how can you have a bi-directional relation with @IndexColumn? If two Equipments are referencing the same Component, on different indexes, you clearly need a join table, so the "mappedBy" won't work here (even without versioning - try it and check that the field in the database is always null)

            --
            Adam

            • 3. NotSerializableException
              mirtzi

              Hi,

              I fixed my bi-directional relation. This is how it looks like:

              @Entity
              @Table(name = "EQUIPMENT")
              @Versioned
              public class Equipment extends BaseEntity{
              
               private List<Component> components;
              
               @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
               @org.hibernate.annotations.IndexColumn(name = "idx")
               @JoinColumn(name = "equipment_id")
               public List<Component> getComponents() {
               return components;
               }
              
               //setter
              }



              @Entity
              @Table(name = "COMPONENT")
              @Versioned
              public class Component extends BaseEntity{
              
               private Equipment equipment;
              
               @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
               @JoinColumn(name = "equipment_id", insertable = false, updatable = false)
               public Equipment getEquipment() {
               return equipment;
               }
              
               //setter
              }


              All works well in my tests but in my application (a Spring WebFlow app) I get java.io.NotSerializableException: org.jboss.envers.entities.mapper.relation.lazy.proxy.ListProxy

              Has anybody encountered serialization problems before with Envers?



              • 4. Re: NotSerializableException
                mirtzi

                Shouldn't this class implement Serializable?

                Offtopic: How can I edit a post?

                • 5. Re: Collection problem
                  adamw

                  Hello,

                  maybe it should :) - please create a JIRA issue, with a test case, if you could.

                  I've got two remarks though:
                  - versioning a list of components won't yet work (it's not yet supported)
                  - the list proxy is there for lazy initializaition, so I guess you can get exceptions when trying to access the elements on the list after transporting the class somewhere. Why are you serializing the classes?

                  --
                  Adam

                  • 6. Re: Collection problem
                    mirtzi

                    Hi,

                    I created a JIRA issue, http://opensource.atlassian.com/projects/hibernate/browse/HHH-3623 , I hope it's filled correctly... it's my first one :)

                    I wrote there why my classes need serialization and what was the (temporary) fix.

                    I didn't find the project's road map... when will it be a new release?

                    I know about the collection of components, mine are entities (the id is in the superclass from the first post... I forgot to copy it).

                    P.S: Thanks for the quick responses.

                    • 7. Re: Collection problem
                      adamw

                      Hello,

                      ok, resolved :)

                      A new release will be in about 1-2 months.

                      --
                      Adam