Skip to main content

Decoupled architecurearchitecture between business and data layers in Spring JPA / Hibernate

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

Following the advices given in this answeranswer, I'm not injecting anything into the entities and I'm using business proxy objects. But then, it seems that, I have to use @ConfigurableI have to use @Configurable and AspectJ LTW for injecting the repositories into the business objects because "Spring AOP only supports method execution join points for Spring beans".

Following the advices given in this answer, I'm not injecting anything into the entities and I'm using business proxy objects. But then, it seems that, I have to use @Configurable and AspectJ LTW for injecting the repositories into the business objects because "Spring AOP only supports method execution join points for Spring beans".

Following the advices given in this answer, I'm not injecting anything into the entities and I'm using business proxy objects. But then, it seems that, I have to use @Configurable and AspectJ LTW for injecting the repositories into the business objects because "Spring AOP only supports method execution join points for Spring beans".

deleted 28 characters in body
Source Link
public class Drawer{
    @Autowired
    private CardRepository cardRepository;
    
    private DrawerEntity drawerEntity;
    
    public Drawer(){this.drawerEntity = new DrawerEntity();}
    public Drawer(DrawerEntity drawerEntity){this.drawerEntity = drawerEntity;}

    public int getId(){return drawerEntity.getId();}
    public void setId(int id){drawerEntity.setId(id);}
    
    public String getLabel(){return drawerEntity.getLabel();}
    public void setLabel(String label){drawerEntity.setLabel(label);}
    
    public int getNumberOfCards(){return cardRepository.countByDrawerId(this.getId());}return this.drawerEntity;}
}
public class Drawer{
    @Autowired
    CardRepository cardRepository;
    
    private DrawerEntity drawerEntity;
    
    public Drawer(){this.drawerEntity = new DrawerEntity();}
    public Drawer(DrawerEntity drawerEntity){this.drawerEntity = drawerEntity;}

    public int getId(){return drawerEntity.getId();}
    public void setId(int id){drawerEntity.setId(id);}
    
    public String getLabel(){return drawerEntity.getLabel();}
    public void setLabel(String label){drawerEntity.setLabel(label);}
    
    public int getNumberOfCards(){return cardRepository.countByDrawerId(this.getId());}return this.drawerEntity;}
}
public class Drawer{
    @Autowired
    private CardRepository cardRepository;
    private DrawerEntity drawerEntity;
    
    public Drawer(){this.drawerEntity = new DrawerEntity();}
    public Drawer(DrawerEntity drawerEntity){this.drawerEntity = drawerEntity;}

    public int getId(){return drawerEntity.getId();}
    public void setId(int id){drawerEntity.setId(id);}
    
    public String getLabel(){return drawerEntity.getLabel();}
    public void setLabel(String label){drawerEntity.setLabel(label);}
    
    public int getNumberOfCards(){return cardRepository.countByDrawerId(this.getId());}
}
deleted 9 characters in body
Source Link
Loading
added 962 characters in body
Source Link
Loading
added 296 characters in body
Source Link
Loading
added 188 characters in body
Source Link
Loading
Source Link
Loading