Skip to content

Instantly share code, notes, and snippets.

@bytestree
bytestree / Employee.java
Created September 11, 2016 20:43
Repository class for Employee entity using Spring Data JPA
package com.bytestree.restful.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@bytestree
bytestree / CRUDService.java
Created September 11, 2016 19:29
Service layer for Restful Web Service using CRUDService interface for CRUD operations.
package com.bytestree.restful.service;
import java.io.Serializable;
import java.util.List;
public interface CRUDService<E> {
E save(E entity);
E getById(Serializable id);
@bytestree
bytestree / EmployeeController.java
Last active December 21, 2016 14:32
Restful Web Service Controller for CRUD operations
package com.bytestree.restful.controller;
import java.util.Arrays;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
@bytestree
bytestree / Application.java
Last active December 21, 2016 14:46
pom file to create RESTful Web Services using Spring Boot and PostgreSQL
package com.bytestree.restful;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
@bytestree
bytestree / TestApplication.java
Last active May 7, 2016 23:45
Generic DAO in Hibernate - Client Application
package com.bytestree;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import com.bytestree.config.AppConfiguration;
public class TestApplication {
public static void main(String[] args) {
// Load the Spring context and beans
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AppConfiguration.class);
@bytestree
bytestree / MyApplication.java
Created May 7, 2016 21:40
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;
@Component
@bytestree
bytestree / Employee.java
Last active May 7, 2016 23:46
Generic DAO in Hibernate - EmployeeDao.java using GeneticDao.java
package com.bytestree.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@bytestree
bytestree / AbstractGenericDao.java
Last active May 7, 2016 14:59
Generic DAO in Hibernate interface and abstract implementation
package com.bytestree.dao;
import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Example;
import org.springframework.beans.factory.annotation.Autowired;
@bytestree
bytestree / initDatabase.sql
Created May 7, 2016 14:03
Generic DAO in Hibernate initialize data script
-- Create table --
CREATE TABLE employee
(
id bigserial NOT NULL,
firstname character varying(50),
lastname character varying(50),
designation character varying(50),
salary integer,
CONSTRAINT employee_pk PRIMARY KEY (id)
);
@bytestree
bytestree / AppConfiguration.java
Created May 7, 2016 13:55
Hibernate and Spring Configuration for Generic DAO example
package com.bytestree.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@ComponentScan(value={"com.bytestree"})
public class AppConfiguration {
}