Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generic DAO in Hibernate - Application class
package com.bytestree;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.bytestree.model.Employee;
import com.bytestree.service.EmployeeService;
public class MyApplication {
final static Logger logger = Logger.getLogger(MyApplication.class);
private EmployeeService employeeService;
public void performDbTasks()
// Get all employees
List<Employee> employeeList = employeeService.getAllEmployees();
Employee empNew = new Employee("Bytes", "Tree", "Senior Developer", 2000);
// Save new employee
// Get all employees - to check added employee
employeeList = employeeService.getAllEmployees();
Integer maxSalary = employeeService.getMaxSalary();
logger.debug("Maximum salary given to employee is: " + maxSalary);
private void printEmployees(List<Employee> emplist) {
if (emplist != null) {
logger.debug("Found total " + emplist.size() + " records.");
for (Employee employee : emplist) {

This comment has been minimized.

Copy link
Owner Author

bytestree commented May 7, 2016

Refer Generic DAO in Hibernate for complete example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.