0

As a yet "newbie" of JavaEE, say I try to implement a rather big RESTful API with Spring 4 and Hibernate and, the final JSON objects should be transformed to flattened Objects other than the original Java bean entities annotated with @Entity.

Due to the "out-of-the-box" feature of Spring and Hibernate, I am sure most programmers can easily get the work done. But as an experienced programmer, we would focus more on the code structure, design architecture so that the whole project is more maintainable and code is easy to read.

So my first question is the package structure:

  • where to place the Java bean entities annotated with @Entity? I have seen some people place them in the package called model, I am not exactly clear about their purpose anyway

  • Where to place the final flattened objects transformed from the Java bean entities? I placed it in the package called dto as this is data transfer object between the service layer and the controller layer

so I have the following package structure:

sample.model //place the @Entity Java beans
sample.dto //place the aforementioned DTO
sample.controller //place the controller class

Anyone can give some comments on it? Thanks in advance

Rui
  • 3,454
  • 6
  • 37
  • 70

1 Answers1

2

There's two different ways to organize packages in Java project.

  • package-per-feature
  • package-per-layer

Comparison

But how to name your package it's really up to you.

In different projects, I faced with names like:

  • for entity: model, domain, entity
  • for DTO: dto, transport, response or request (depending on direction)
Community
  • 1
  • 1
Vlad Bochenin
  • 3,007
  • 1
  • 20
  • 33
  • Thanks a lot for the link :) but what about my solution in that I put the Java bean entity into the dao package? is it logical? – Rui Sep 03 '17 at 11:43
  • Why not? )) if there just a few entities and repositories they could be in one package, when it become uncomfortable to have repositories and entities in one package, you always can split them by different packages – Vlad Bochenin Sep 03 '17 at 12:40