Search⌘ K
AI Features

Develop the Business Service Tier

Explore how to implement the business service tier focusing on Concrete Table Inheritance within a Java Spring and Hibernate application. Learn to perform key CRUD operations like find all, create, remove, edit, and find by ID, managing data flow between access objects and entities to maintain efficient server-side data handling.

Find all records operation

We will proceed with the “find all records” operation.

Java
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class EstateServiceImplTest {
@Autowired
private EstateService service;
@Test
public void testFindAll() {
Assert.assertEquals(0L, service.findAll().size());
}
}

Let’s look at how to code the corresponding “find all records” operation in the business service.

Java
@Service
@Transactional
public class EstateServiceImpl implements EstateService {
@Autowired
private EstateDao estateDao;
@Autowired
private EstateMapper estateMapper;
@Override
public List<EstateDto> findAll() {
List<Estate> estates = estateDao.getAll();
List<EstateDto> estateDtos = new ArrayList<EstateDto>();
for(Estate estate : estates){
estateDtos.add(estateMapper.mapEntityToDto(estate));
}
return estateDtos;
}
}

Mappers

The mapper has two vital operations which are used to convert data access objects to ...