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

    Property access

    aslak

      Hi

      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?


      -aslak-

        • 1. Re: Property access
          adamw

          Hello,

          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 :)

          Thanks,
          Adam

          • 2. Re: Property access
            aslak

            Of course.. :)

            https://jira.jboss.org/jira/browse/ENVERS-56

            I will supply a patch soon..

            -aslak-

            • 3. Re: Property access
              adamw

              Great, thanks!

              Adam

              • 4. Re: Property access
                sannegrinovero

                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

                  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)

                  -aslak-

                  • 6. Re: Property access
                    sannegrinovero

                    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
                      adamw

                      Hello,

                      @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? :)

                      Adam

                      • 8. Re: Property access
                        sannegrinovero

                        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
                          adamw

                          Hello,

                          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.

                          Adam

                          • 10. Re: Property access
                            sannegrinovero

                            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.