10 Replies Latest reply on Oct 13, 2008 12:37 PM by Sanne Grinovero

    Property access

    Aslak Knutsen Master


      I'm getting the exception:
      Could not find a setter for property id in class ...

      I see Envers use the BasicPropertyAccessor to set/get values from the Versioned Entity. Personally I like not having to make setters (even protected/private ones) if I don't have to. Hibernate core supports direct access, so entities will not work 'out of the box' with Envers.

      Is there a reason behind using the BasicPropertyAccessor as apposed to the DirectPropertyAccessor ? or a combination?


        • 1. Re: Property access
          Adam Warski Master


          no, there's no reason other that I simply didn't add it yet :)

          If you know what should be added and where, please write, that way it will be much easier :). Preferrably, in a new JIRA issue :)


          • 2. Re: Property access
            Aslak Knutsen Master

            Of course.. :)


            I will supply a patch soon..


            • 3. Re: Property access
              Adam Warski Master

              Great, thanks!


              • 4. Re: Property access
                Sanne Grinovero Master

                This fix is very welcome, but FYI I have added a warning comment on the JIRA about the proposed patch.

                • 5. Re: Property access
                  Aslak Knutsen Master

                  Thanks for your comment, sannegrinovero !

                  I tried the easy way out.. :o)

                  I'll supply a new patch that set the proper accessor based on AccessType.

                  I guess this should be passed down from the EntityConfiguration to the different IdMapper/PropertyMappers ?

                  (Where ever ReflectionTools.get/set is used more or less.. it could be placed on the ReflectionTools pr call as well, but it should be handled one time as a 'main' configuration)


                  • 6. Re: Property access
                    Sanne Grinovero Master

                    cool, but please ask for Adam's decision, I just told you how it is done in Hibernate Annotations.
                    I see he didn't use the Annotations module to scan the entities, maybe he has got some good reasons.

                    • 7. Re: Property access
                      Adam Warski Master


                      @aslak: Yes, I think that a property (in a Id/Property mapper) should know how it is accessed. I guess the best way is to collect this data in AnnotationMetadataReader, and then pass it to the mappers, which would invoke ReflectionTools with an additional "direct or property" parameter. In fact, it would be best to restructure the PersistentClassVersioningData class and create, for example, "PropertyData" class, which would store all the information, now spread in various maps.

                      Also, maybe it would be a good idea to encapsulate the property name+access method in one class. This "Property" class would then have getName(), getValue(Object o), setValue(Object o, Object val) methods. But that's something to consider :).

                      @sannegrinovero: how I could have used the annotations module? That is, which module (class) are you specifically talking about? :)


                      • 8. Re: Property access
                        Sanne Grinovero Master

                        Hi Adam,
                        I am speaking about the Hibernate Annotations project: http://www.hibernate.org/hib_docs/annotations/reference/en/html_single/
                        I don't know exactly how you could have used it, but in Hibernate Search we are currently not supporting configuration by xml, only by annotations, and Emmanuel once told me that it would be actually easy to implement as the Annotations module is quite flexbile and could read them exactly as they were declared in an xml.

                        What I know is that Search is not using reflection at all, it is importing

                        import org.hibernate.annotations.common.reflection.ReflectionManager;
                        import org.hibernate.annotations.common.reflection.XClass;
                        import org.hibernate.annotations.common.reflection.java.JavaReflectionManager;
                        (in SearchFactoryImpl)

                        You should ask on the dev list for details, Emmanuel is on vacations for some days but others (Hardy?) should know as well: even on Search I didn't use this classes much.

                        • 9. Re: Property access
                          Adam Warski Master


                          sure I know the project :)
                          From what I remember, when I started writing Envers, I read quite a lot of Hibernate code, to see what I can reuse. However, I think that either - there isn't, or I didn't find any way to plug into the parsing of Hibernate Annotation's annotation-reading module. You are right that it's written so that it's easy to add support for new annotations, but then I would have to modify Hibernate Annotations :). It's the same as auto-registering the event listeners - it is hard-coded. But asking on the dev lists may be a good idea :). Or when we get a chance to meet (on Devoxx?).

                          I'm using the XClass/ReflectionManager classess as well, to read annotations from (persistent) classes. But I don't think they might be useful in properties getting/setting.


                          • 10. Re: Property access
                            Sanne Grinovero Master

                            I think you're right... maybe it will be possible someday to support "pluggable annotation classes to scan for".

                            Ah so you're going to speak at Devoxx! cool.. I wrote it on my agenda, I hope to see you there.