Announcement Announcement Module
No announcement yet.
Pattern for accessing static data and setting in domain Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Pattern for accessing static data and setting in domain


    We have static data like country, state, order status which we retrieve from database only once and store in cache (using ehcache)
    This static data can come from database tables or hard coded in Java code or xml files.

    Now we have Customer table in database which contains country and state code.
    We are using SimpleJDBC template to retrieve data.
    In rowMapper of CustomerDAO we are creating new instance of Country and sate object and setting only countrycode and statecode respectively.

    In Service layer (CustomerService) we are retrieving actual country and state object from cache (DAO of country and state) and setting it on customer object.

    Same pattern we are using for Hibernate JPA.
    (Embedded country and state object in Customer class and only countrycode and statecode of those objects are mapped to corresponding columns in customer table)

    In this pattern we/hibernate create instance of country and state which is only used for retrieving countrycode and statecode and then actual object is featched from cache based on those code and set in customer object.
    Thus temporary objects are created only to get key fields.

    Is there any better way of implementing above scenario which works for JPA and also for JDBC.

    Another approche that we are thinking are
    a) Having statecode and countrycode directly on customer object
    which will be mapped directly to database columns of customer table
    and country and state variable will be marked as transistent
    This approch will also work but there will be reduntant data
    b) Having data access object in rowmapper which will work only for JDBC.
    As there are no rowmapper for JPA.

    All above three approches will be work, but we want to know which one is the best and should be followed as standard practise.