Menu

populate properties directly

Help
hari
2008-07-21
2013-04-25
  • hari

    hari - 2008-07-21

    Hi,
    I am using my domain model as a DTO. So there are instances where bean properties have private setters or there are no setters defined at all.
    a. Hibernate can populate my model bean by accessing the fields directly. Is there a way get the Hibernate bean replicator to set bean properties directly using reflection or even access private setter methods?
    b. Hibernate allows package protected constructors. Is there a way get the Hibernate bean replicator to construct such beans?
    Regards,
    Hari.

     
    • Hanson Char

      Hanson Char - 2008-07-21

      a.  Look for the classes ProtectedSetterMethodCollector and ProtectedReaderMethodFinder.  There should be some examples of how they are used in the junit tests.  You just need to do the equivalent classes for private methods.  (There already exists PrivateSetterMethodCollector IIRC.)

      b. IIRC it should just work.

      Cheers.

       
    • hari

      hari - 2008-07-21

      a. I used PrivateSetterMethodCollector and that takes care of my private setter copy. I guess I could always create private setters if beanlib does not support direct property access.

      b. If I can now just as easily copy beans with empty package protected constructor ...

       

Log in to post a comment.