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

1

There are 1 answers

2
Vlad Bochenin On

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)