java - Architecture and project organization -


we are, in company, @ beginning of huge refactoring migrate home made database access hibernate. want clean, , therefore wiil use entities, daos, etc... use maven, , therefore have 2 maven projects, 1 entities, 1 daos (is good, or better have both in same project ?).

knowing that, our question following : our business layer use daos. of dao's methods return entities, our business layer have know entities. , therefore, our business layer have know hibernate, our entities hibernate annotated (or @ least jpa annotated). problem ? if yes, solution give business layer minimum knowledge data layer ?

thank you,

seb

here how typically model dependencies, along reasoning.

  1. let's distinguish 4 things:

    a. business logic

    b. entities

    c. dao interfaces

    d. dao implementations

  2. for me first 3 belong , therefor belong in same maven module, , in same package. closely related , change in 1 cause change in other. , things change should close together.

  3. the implementation of dao large extend independent of business logic. , more important business logic should not depend on data coming from. separate concern. if data comes today database , tomorrow webservice, nothing should change in business logic.

  4. you right, hibernate (or jpa) annotations on enities violate rule extent. have 3 options:

    a. live it. while creates dependency hibernate artifacts, not create dependency on hibernate implementation. in scenarios, having annotations around acceptable

    b. use xml configuration. fix dependency issue, in opinion @ rather hefty cost of dealing xml based configuration. not worth in opinion

    c. don't use hibernate. don't think dependency on annotations important problem have consider. more serious problem is, hibernate rather invasive. when navigate object graph, hibernate trigger lazy loading, i.e. execution of sql statements @ points not @ obvious looking @ code. means, data access code starts leak every part of application if not careful. 1 can keep contained, not easy , requires great care , in depth understanding of hibernate, teams don't have when start it. hibernate (or jpa) trades simple tedious task of writing sql-statments difficult task of creating software architecture, keeps invisible dependencies in check. therefore recommend avoid hiberante @ , try simpler. have high hopes toward mybatis, haven't used in real projects yet.

  5. more important managing dependencies between technical layers in opinion separation of domain modules. and i'm not alone opinion.

  6. i use separate artifacts (i.e. maven modules) separate things want deploy independently. if example have rich client , backend server 2 maven artifacts those, plus maybe third 1 common code make sens. else i'd use packages , tests fail when illegal dependencies created. use degraph, i'm author of might biased.


Comments