Search⌘ K
AI Features

Develop the Data Access Tier

Explore how to develop the data access tier by implementing CRUD operations using Hibernate methods in Java Spring. Understand how to handle retrieval, insertion, deletion, and updates of entities with a focus on portability and test-driven development.

Now let’s turn to the data access tier. We will start with the test case for the get all records procedure.

Find all records operation

Java
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath:context.xml" } )
@TransactionConfiguration( defaultRollback = true )
@Transactional
public class StudentDaoImplTest {
@Autowired
private StudentDao dao ;
@Test
public void testGetAll() {
Assert.assertEquals(0L, dao.getAll().size());
}
}

For the test above, let’s look at the corresponding data access operation. The Hibernate 4 Session.createQuery method is used with SQL to retrieve all the records from the Student ...