Search⌘ K
AI Features

Develop the Data Access Tier

Explore how to develop the data access tier within a Java Spring application using Hibernate. Learn to implement and test CRUD operations—find all records, insert, update, and delete—focusing on managing one-to-many self-referencing relationships efficiently. This lesson prepares you to handle server-side data management in a test-driven development environment.

Now, we will look at the data access tier.

“Find all records” operation

We will jump in with the test case for the “find all records” method.

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

We will then write the rival data access operation for the test above. The Hibernate 4 Session.createQuery method is used with SQL to retrieve all the ...