title: Service layer in java swing application
body: <p>i'm thinking if i really need a service layer.</p>
  
  <p>I'm using spring + hibernate for a desktop swing application and at this moment i have gui/swing layer->service layer->dao layer. I use spring only for @Transactional support and for IOC-injection</p>
  
  <p>Best practice say that i have to write a service to use my daos, and put all transactions management in the service.</p>
  
  <p>But i'm realizing that very very often, service layer only replicate dao methods, so for example:</p>
  
  <pre><code>// a DAO example
  @Repository
  public class CustomerHibernateDAO extends BaseHibernateDAO implements CustomerDAO {
  
   public List&lt;Customer&gt; findAllCustomerILikeName(String name){
    return getSession()
     .createCriteria(Customer.class)
     .add(Restriction.ilike("name", name))
     .list();
   }
  }
  
  // Customer service to use this dao...
  @Service
  @Transactional
  public class CustomerService {
  
   @Autowired
   CustomerDAO customerDAO;
  
   // Why i can't call DAO instead the service?
   public List&lt;Customer&gt; getAllCustomersByName(String name){
        return customerDAO.findAllCustomerILikeName(name);
   }
  
  }
  </code></pre>
  
  <p>This is a mine tipical usage of service layer... Hibernate is db-agnostic, spring are tecnology-agnostic: so, i really need it?</p>
  
  <p>What about a unique Service class to manage all DAO?? I think this may be a good compromise, or, is a bad practice?</p>
  
  <p>I know put @Transactional on DAO is a bad way, but at this moment i have to write services only for put @Transactional on it...</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>More infos about my app.</p>
  
  <p>My application is a management software and manage user registration, products, order and other things like those.
  In practice it contains a lot of read entity->edit->save entity or create->edit->save operations, and, thanks to hibernate, these operations are managed by ONE dao most of the time, becouse hibernate with @manyto... collection and cascade.save_update permits to save two or more entities in the same persist operation.</p>
  
  <p>So, for example, in my items JFrame where i can insert, edit or create an Item(a product to sell) there are:</p>
  
  <pre><code>public ItemFrame(){
   // the constructor
   itemService=springAppContext.getBeans(ItemService.class);
  }
  
  public boolean validateForm(){
   // test if the gui is correctly filled by user
  }
  
  public boolean save(){
   // create an Item entity taking value from swing gui(JTextField etc)
   Item item=new Item();
   item.setName(nameTextField.getText());
   item.setEtc...
   // ItemService ' save method is a wrap around itemDao.save(item)...
   itemService.save(item);
  }
  
  private void saveItemActionPerformed(ActionEvent evt){
   // When i press SAVE button
   if(validateForm()){
    save();
   }
  }
  </code></pre>
  
  <p>This is what i have in the most of cases, so i think i fell in anemic-domain-antipattern...</p>
  
  <p>Thanks.</p>