├── .DS_Store ├── .gitignore ├── associations ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── .DS_Store │ ├── main │ ├── .DS_Store │ ├── java │ │ ├── .DS_Store │ │ └── com │ │ │ ├── .DS_Store │ │ │ └── bharath │ │ │ ├── .DS_Store │ │ │ └── springdata │ │ │ ├── .DS_Store │ │ │ └── associations │ │ │ ├── .DS_Store │ │ │ ├── AssociationsApplication.java │ │ │ ├── manytomany │ │ │ ├── .DS_Store │ │ │ ├── entities │ │ │ │ ├── Programmer.java │ │ │ │ └── Project.java │ │ │ └── repos │ │ │ │ └── ProgrammerRepository.java │ │ │ ├── onetomany │ │ │ ├── .DS_Store │ │ │ ├── entities │ │ │ │ ├── Customer.java │ │ │ │ └── PhoneNumber.java │ │ │ └── repos │ │ │ │ └── CustomerRepository.java │ │ │ └── onetoone │ │ │ ├── entities │ │ │ ├── License.java │ │ │ └── Person.java │ │ │ └── repos │ │ │ └── LicenseRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── associations │ └── AssociationsApplicationTests.java ├── componentmapping ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── componentmapping │ │ │ ├── ComponentmappingApplication.java │ │ │ ├── entities │ │ │ ├── Address.java │ │ │ └── Employee.java │ │ │ └── repos │ │ │ └── EmployeeRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── componentmapping │ └── ComponentmappingApplicationTests.java ├── customerdata ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── .DS_Store │ ├── main │ ├── .DS_Store │ ├── java │ │ ├── .DS_Store │ │ └── com │ │ │ ├── .DS_Store │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── customer │ │ │ ├── CustomerdataApplication.java │ │ │ ├── entities │ │ │ ├── Address.java │ │ │ └── Customer.java │ │ │ └── repository │ │ │ └── CustomerRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── customer │ └── CustomerdataApplicationTests.java ├── filedata ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── files │ │ │ ├── FiledataApplication.java │ │ │ ├── entities │ │ │ └── Image.java │ │ │ └── repos │ │ │ └── ImageRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── files │ └── FiledataApplicationTests.java ├── hibernateinheritance ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── hibernateinheritance │ │ │ ├── HibernateinheritanceApplication.java │ │ │ ├── entities │ │ │ ├── Check.java │ │ │ ├── CreditCard.java │ │ │ └── Payment.java │ │ │ └── repos │ │ │ └── PaymentRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── hibernateinheritance │ └── HibernateinheritanceApplicationTests.java ├── idgenerators ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── idgenerators │ │ │ ├── CustomRandomIDGenerator.java │ │ │ ├── IdgeneratorsApplication.java │ │ │ ├── entities │ │ │ └── Employee.java │ │ │ └── repos │ │ │ └── EmployeeRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── idgenerators │ └── IdgeneratorsApplicationTests.java ├── jpqlandnativesql ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── jpqlandnativesql │ │ │ ├── JpqlandnativesqlApplication.java │ │ │ ├── entities │ │ │ └── Student.java │ │ │ └── repos │ │ │ └── StudentRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── jpqlandnativesql │ └── JpqlandnativesqlApplicationTests.java ├── patientscheduling ├── .DS_Store ├── .gitignore ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── patientscheduling │ │ │ ├── PatientschedulingApplication.java │ │ │ ├── entities │ │ │ ├── Appointment.java │ │ │ ├── Doctor.java │ │ │ ├── Insurance.java │ │ │ └── Patient.java │ │ │ └── repos │ │ │ ├── AppointmentRepository.java │ │ │ ├── DoctorRepository.java │ │ │ └── PatientRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── patientscheduling │ └── PatientschedulingApplicationTests.java ├── productdata ├── .DS_Store ├── .classpath ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.apt.core.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── bharath │ │ │ └── springdata │ │ │ └── product │ │ │ ├── ProductdataApplication.java │ │ │ ├── entities │ │ │ └── Product.java │ │ │ └── repos │ │ │ └── ProductRepository.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── bharath │ └── springdata │ └── product │ └── ProductdataApplicationTests.java └── transactionmanagement ├── .DS_Store ├── .gitignore ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ └── maven-wrapper.properties ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── bharath │ │ └── springdata │ │ └── transactionmanagement │ │ └── TransactionmanagementApplication.java └── resources │ └── application.properties └── test └── java └── com └── bharath └── springdata └── transactionmanagement └── TransactionmanagementApplicationTests.java /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.metadata/ 2 | /.recommenders/ 3 | -------------------------------------------------------------------------------- /associations/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/.DS_Store -------------------------------------------------------------------------------- /associations/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /associations/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /associations/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /associations/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.associations 7 | associations 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | associations 12 | JPA Associations 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /associations/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/bharath/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/bharath/springdata/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/bharath/springdata/associations/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/AssociationsApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class AssociationsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(AssociationsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/manytomany/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/bharath/springdata/associations/manytomany/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/manytomany/entities/Programmer.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.manytomany.entities; 2 | 3 | import java.util.Set; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Column; 7 | import javax.persistence.Entity; 8 | import javax.persistence.FetchType; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.JoinColumn; 13 | import javax.persistence.JoinTable; 14 | import javax.persistence.ManyToMany; 15 | 16 | @Entity 17 | public class Programmer { 18 | 19 | @Id 20 | @GeneratedValue(strategy = GenerationType.AUTO) 21 | private int id; 22 | private String name; 23 | @Column(name = "salary") 24 | private int sal; 25 | @ManyToMany(cascade = CascadeType.ALL,fetch=FetchType.EAGER) 26 | @JoinTable(name = "programmers_projects", joinColumns = @JoinColumn(name = "programmer_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "project_id", referencedColumnName = "id")) 27 | private Set projects; 28 | 29 | public int getId() { 30 | return id; 31 | } 32 | 33 | public void setId(int id) { 34 | this.id = id; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String name) { 42 | this.name = name; 43 | } 44 | 45 | public int getSal() { 46 | return sal; 47 | } 48 | 49 | public void setSal(int sal) { 50 | this.sal = sal; 51 | } 52 | 53 | public Set getProjects() { 54 | return projects; 55 | } 56 | 57 | public void setProjects(Set projects) { 58 | this.projects = projects; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Programmer [id=" + id + ", name=" + name + ", sal=" + sal + "]"; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/manytomany/entities/Project.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.manytomany.entities; 2 | 3 | import java.util.Set; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.ManyToMany; 10 | 11 | @Entity 12 | public class Project { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.AUTO) 16 | private int id; 17 | private String name; 18 | @ManyToMany(mappedBy = "projects") 19 | private Set programmers; 20 | 21 | public int getId() { 22 | return id; 23 | } 24 | 25 | public void setId(int id) { 26 | this.id = id; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public void setName(String name) { 34 | this.name = name; 35 | } 36 | 37 | public Set getProgrammers() { 38 | return programmers; 39 | } 40 | 41 | public void setProgrammers(Set programmers) { 42 | this.programmers = programmers; 43 | } 44 | 45 | @Override 46 | public String toString() { 47 | return "Project [id=" + id + ", name=" + name + "]"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/manytomany/repos/ProgrammerRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.manytomany.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.associations.manytomany.entities.Programmer; 6 | 7 | public interface ProgrammerRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetomany/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/associations/src/main/java/com/bharath/springdata/associations/onetomany/.DS_Store -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetomany/entities/Customer.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetomany.entities; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import javax.persistence.CascadeType; 7 | import javax.persistence.Entity; 8 | import javax.persistence.FetchType; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.OneToMany; 13 | 14 | @Entity 15 | public class Customer { 16 | 17 | @Id 18 | @GeneratedValue(strategy = GenerationType.AUTO) 19 | private long id; 20 | private String name; 21 | @OneToMany(mappedBy = "customer", cascade = CascadeType.ALL,fetch=FetchType.EAGER) 22 | private Set numbers; 23 | 24 | public long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(long id) { 29 | this.id = id; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public Set getNumbers() { 41 | return numbers; 42 | } 43 | 44 | public void setNumbers(Set numbers) { 45 | this.numbers = numbers; 46 | } 47 | 48 | public void addPhoneNumber(PhoneNumber number) { 49 | if (number != null) { 50 | if (numbers == null) { 51 | numbers = new HashSet<>(); 52 | } 53 | number.setCustomer(this); 54 | numbers.add(number); 55 | } 56 | 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetomany/entities/PhoneNumber.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetomany.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.JoinColumn; 8 | import javax.persistence.ManyToOne; 9 | 10 | @Entity 11 | public class PhoneNumber { 12 | 13 | @Id 14 | @GeneratedValue(strategy = GenerationType.AUTO) 15 | private long id; 16 | private String number; 17 | private String type; 18 | 19 | @ManyToOne 20 | @JoinColumn(name = "customer_id") 21 | private Customer customer; 22 | 23 | public long getId() { 24 | return id; 25 | } 26 | 27 | public void setId(long id) { 28 | this.id = id; 29 | } 30 | 31 | public String getNumber() { 32 | return number; 33 | } 34 | 35 | public void setNumber(String number) { 36 | this.number = number; 37 | } 38 | 39 | public String getType() { 40 | return type; 41 | } 42 | 43 | public void setType(String type) { 44 | this.type = type; 45 | } 46 | 47 | public Customer getCustomer() { 48 | return customer; 49 | } 50 | 51 | public void setCustomer(Customer customer) { 52 | this.customer = customer; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetomany/repos/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetomany.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.associations.onetomany.entities.Customer; 6 | 7 | public interface CustomerRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetoone/entities/License.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetoone.entities; 2 | 3 | import java.util.Date; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | import javax.persistence.JoinColumn; 11 | import javax.persistence.OneToOne; 12 | import javax.persistence.Temporal; 13 | import javax.persistence.TemporalType; 14 | 15 | @Entity 16 | public class License { 17 | 18 | @Id 19 | @GeneratedValue(strategy = GenerationType.AUTO) 20 | private Long id; 21 | private String type; 22 | @Temporal(TemporalType.DATE) 23 | private Date validFrom; 24 | @Temporal(TemporalType.DATE) 25 | private Date validTo; 26 | @OneToOne(cascade = CascadeType.ALL) 27 | @JoinColumn(name="person_id") 28 | private Person person; 29 | 30 | public Long getId() { 31 | return id; 32 | } 33 | 34 | public void setId(Long id) { 35 | this.id = id; 36 | } 37 | 38 | public String getType() { 39 | return type; 40 | } 41 | 42 | public void setType(String type) { 43 | this.type = type; 44 | } 45 | 46 | public Date getValidFrom() { 47 | return validFrom; 48 | } 49 | 50 | public void setValidFrom(Date validFrom) { 51 | this.validFrom = validFrom; 52 | } 53 | 54 | public Date getValidTo() { 55 | return validTo; 56 | } 57 | 58 | public void setValidTo(Date validTo) { 59 | this.validTo = validTo; 60 | } 61 | 62 | public Person getPerson() { 63 | return person; 64 | } 65 | 66 | public void setPerson(Person person) { 67 | this.person = person; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetoone/entities/Person.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetoone.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | import javax.persistence.OneToOne; 8 | 9 | @Entity 10 | public class Person { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private Long id; 15 | private String firstName; 16 | private String lastName; 17 | private int age; 18 | @OneToOne(mappedBy = "person") 19 | private License license; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getFirstName() { 30 | return firstName; 31 | } 32 | 33 | public void setFirstName(String firstName) { 34 | this.firstName = firstName; 35 | } 36 | 37 | public String getLastName() { 38 | return lastName; 39 | } 40 | 41 | public void setLastName(String lastName) { 42 | this.lastName = lastName; 43 | } 44 | 45 | public int getAge() { 46 | return age; 47 | } 48 | 49 | public void setAge(int age) { 50 | this.age = age; 51 | } 52 | 53 | public License getLicense() { 54 | return license; 55 | } 56 | 57 | public void setLicense(License license) { 58 | this.license = license; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /associations/src/main/java/com/bharath/springdata/associations/onetoone/repos/LicenseRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations.onetoone.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.associations.onetoone.entities.License; 6 | 7 | public interface LicenseRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /associations/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /associations/src/test/java/com/bharath/springdata/associations/AssociationsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.associations; 2 | 3 | import java.util.Date; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.context.SpringBootTest; 11 | import org.springframework.test.context.junit4.SpringRunner; 12 | import org.springframework.transaction.annotation.Transactional; 13 | 14 | import com.bharath.springdata.associations.manytomany.entities.Programmer; 15 | import com.bharath.springdata.associations.manytomany.entities.Project; 16 | import com.bharath.springdata.associations.manytomany.repos.ProgrammerRepository; 17 | import com.bharath.springdata.associations.onetomany.entities.Customer; 18 | import com.bharath.springdata.associations.onetomany.entities.PhoneNumber; 19 | import com.bharath.springdata.associations.onetomany.repos.CustomerRepository; 20 | import com.bharath.springdata.associations.onetoone.entities.License; 21 | import com.bharath.springdata.associations.onetoone.entities.Person; 22 | import com.bharath.springdata.associations.onetoone.repos.LicenseRepository; 23 | 24 | @RunWith(SpringRunner.class) 25 | @SpringBootTest 26 | public class AssociationsApplicationTests { 27 | 28 | @Autowired 29 | CustomerRepository repository; 30 | 31 | @Autowired 32 | ProgrammerRepository programmerRepository; 33 | 34 | @Autowired 35 | LicenseRepository licenseRepository; 36 | 37 | @Test 38 | public void contextLoads() { 39 | } 40 | 41 | @Test 42 | public void testCreateCustomer() { 43 | 44 | Customer customer = new Customer(); 45 | customer.setName("John"); 46 | 47 | PhoneNumber ph1 = new PhoneNumber(); 48 | ph1.setNumber("1234567890"); 49 | ph1.setType("cell"); 50 | 51 | PhoneNumber ph2 = new PhoneNumber(); 52 | ph2.setNumber("0987654321"); 53 | ph2.setType("home"); 54 | 55 | customer.addPhoneNumber(ph1); 56 | customer.addPhoneNumber(ph2); 57 | 58 | repository.save(customer); 59 | } 60 | 61 | @Test 62 | @Transactional 63 | public void testLoadCustomer() { 64 | Customer customer = repository.findById(4L).get(); 65 | System.out.println(customer.getName()); 66 | 67 | Set numbers = customer.getNumbers(); 68 | numbers.forEach(number -> System.out.println(number.getNumber())); 69 | 70 | } 71 | 72 | @Test 73 | public void testUpdateCustomer() { 74 | Customer customer = repository.findById(4L).get(); 75 | customer.setName("John Bush"); 76 | 77 | Set numbers = customer.getNumbers(); 78 | numbers.forEach(number -> number.setType("cell")); 79 | 80 | repository.save(customer); 81 | 82 | } 83 | 84 | @Test 85 | public void testDelete() { 86 | repository.deleteById(4l); 87 | } 88 | 89 | @Test 90 | public void testmtomCreateProgrammer() { 91 | Programmer programmer = new Programmer(); 92 | programmer.setName("John"); 93 | programmer.setSal(10000); 94 | 95 | HashSet projects = new HashSet(); 96 | Project project = new Project(); 97 | project.setName("Hibernate Project"); 98 | projects.add(project); 99 | 100 | programmer.setProjects(projects); 101 | 102 | programmerRepository.save(programmer); 103 | } 104 | 105 | @Test 106 | @Transactional 107 | public void testmtomFindProgrammer() { 108 | Programmer programmer = programmerRepository.findById(1).get(); 109 | System.out.println(programmer); 110 | System.out.println(programmer.getProjects()); 111 | } 112 | 113 | @Test 114 | public void testOneToOneCreateLicense() { 115 | License license = new License(); 116 | license.setType("CAR"); 117 | license.setValidFrom(new Date()); 118 | license.setValidTo(new Date()); 119 | 120 | Person person = new Person(); 121 | person.setFirstName("John"); 122 | person.setLastName("Clinton"); 123 | person.setAge(35); 124 | 125 | license.setPerson(person); 126 | 127 | licenseRepository.save(license); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /componentmapping/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/componentmapping/.DS_Store -------------------------------------------------------------------------------- /componentmapping/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /componentmapping/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/componentmapping/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /componentmapping/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /componentmapping/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.componentmapping 7 | componentmapping 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | componentmapping 12 | Component Mapping 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /componentmapping/src/main/java/com/bharath/springdata/componentmapping/ComponentmappingApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.componentmapping; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ComponentmappingApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ComponentmappingApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /componentmapping/src/main/java/com/bharath/springdata/componentmapping/entities/Address.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.componentmapping.entities; 2 | 3 | import javax.persistence.Embeddable; 4 | 5 | @Embeddable 6 | public class Address { 7 | 8 | private String streetaddress; 9 | private String city; 10 | private String state; 11 | private String zipcode; 12 | private String country; 13 | 14 | public String getCity() { 15 | return city; 16 | } 17 | 18 | public void setCity(String city) { 19 | this.city = city; 20 | } 21 | 22 | public String getState() { 23 | return state; 24 | } 25 | 26 | public void setState(String state) { 27 | this.state = state; 28 | } 29 | 30 | public String getZipcode() { 31 | return zipcode; 32 | } 33 | 34 | public void setZipcode(String zipcode) { 35 | this.zipcode = zipcode; 36 | } 37 | 38 | public String getCountry() { 39 | return country; 40 | } 41 | 42 | public void setCountry(String country) { 43 | this.country = country; 44 | } 45 | 46 | public String getStreetaddress() { 47 | return streetaddress; 48 | } 49 | 50 | public void setStreetaddress(String streetaddress) { 51 | this.streetaddress = streetaddress; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /componentmapping/src/main/java/com/bharath/springdata/componentmapping/entities/Employee.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.componentmapping.entities; 2 | 3 | import javax.persistence.Embedded; 4 | import javax.persistence.Entity; 5 | import javax.persistence.Id; 6 | 7 | @Entity 8 | public class Employee { 9 | 10 | @Id 11 | private int id; 12 | private String name; 13 | @Embedded 14 | private Address address; 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public Address getAddress() { 33 | return address; 34 | } 35 | 36 | public void setAddress(Address address) { 37 | this.address = address; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /componentmapping/src/main/java/com/bharath/springdata/componentmapping/repos/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.componentmapping.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.componentmapping.entities.Employee; 6 | 7 | public interface EmployeeRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /componentmapping/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /componentmapping/src/test/java/com/bharath/springdata/componentmapping/ComponentmappingApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.componentmapping; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import com.bharath.springdata.componentmapping.entities.Address; 10 | import com.bharath.springdata.componentmapping.entities.Employee; 11 | import com.bharath.springdata.componentmapping.repos.EmployeeRepository; 12 | 13 | @RunWith(SpringRunner.class) 14 | @SpringBootTest 15 | public class ComponentmappingApplicationTests { 16 | 17 | @Autowired 18 | EmployeeRepository repository; 19 | 20 | @Test 21 | public void contextLoads() { 22 | } 23 | 24 | @Test 25 | public void testCreate() { 26 | Employee employee = new Employee(); 27 | employee.setId(123); 28 | employee.setName("Bharath"); 29 | Address address = new Address(); 30 | address.setCity("Austin"); 31 | address.setStreetaddress("Spicewood Springs"); 32 | address.setCountry("USA"); 33 | address.setState("TEXAS"); 34 | address.setZipcode("78750"); 35 | employee.setAddress(address); 36 | 37 | repository.save(employee); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /customerdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/.DS_Store -------------------------------------------------------------------------------- /customerdata/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /customerdata/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /customerdata/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /customerdata/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.customer 7 | customerdata 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | customerdata 12 | Assignment Solution 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /customerdata/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/src/.DS_Store -------------------------------------------------------------------------------- /customerdata/src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/src/main/.DS_Store -------------------------------------------------------------------------------- /customerdata/src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/src/main/java/.DS_Store -------------------------------------------------------------------------------- /customerdata/src/main/java/com/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/customerdata/src/main/java/com/.DS_Store -------------------------------------------------------------------------------- /customerdata/src/main/java/com/bharath/springdata/customer/CustomerdataApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.customer; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class CustomerdataApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(CustomerdataApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /customerdata/src/main/java/com/bharath/springdata/customer/entities/Address.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.customer.entities; 2 | 3 | import javax.persistence.Embeddable; 4 | 5 | @Embeddable 6 | public class Address { 7 | 8 | private String streetAddress; 9 | private String city; 10 | private String state; 11 | private String zipcode; 12 | private String country; 13 | 14 | public String getCity() { 15 | return city; 16 | } 17 | 18 | public void setCity(String city) { 19 | this.city = city; 20 | } 21 | 22 | public String getState() { 23 | return state; 24 | } 25 | 26 | public void setState(String state) { 27 | this.state = state; 28 | } 29 | 30 | public String getZipcode() { 31 | return zipcode; 32 | } 33 | 34 | public void setZipcode(String zipcode) { 35 | this.zipcode = zipcode; 36 | } 37 | 38 | public String getCountry() { 39 | return country; 40 | } 41 | 42 | public void setCountry(String country) { 43 | this.country = country; 44 | } 45 | 46 | public String getStreetAddress() { 47 | return streetAddress; 48 | } 49 | 50 | public void setStreetAddress(String streetAddress) { 51 | this.streetAddress = streetAddress; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /customerdata/src/main/java/com/bharath/springdata/customer/entities/Customer.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.customer.entities; 2 | 3 | import javax.persistence.Embedded; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | 9 | @Entity 10 | public class Customer { 11 | 12 | @Id 13 | @GeneratedValue(strategy = GenerationType.AUTO) 14 | private int id; 15 | private String name; 16 | private String email; 17 | @Embedded 18 | private Address address; 19 | 20 | public int getId() { 21 | return id; 22 | } 23 | 24 | public void setId(int id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | public String getEmail() { 37 | return email; 38 | } 39 | 40 | public void setEmail(String email) { 41 | this.email = email; 42 | } 43 | 44 | public Address getAddress() { 45 | return address; 46 | } 47 | 48 | public void setAddress(Address address) { 49 | this.address = address; 50 | } 51 | 52 | @Override 53 | public String toString() { 54 | return "Customer [id=" + id + ", name=" + name + ", email=" + email + "]"; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /customerdata/src/main/java/com/bharath/springdata/customer/repository/CustomerRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.customer.repository; 2 | 3 | import org.springframework.data.jpa.repository.Modifying; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.data.repository.query.Param; 7 | 8 | import com.bharath.springdata.customer.entities.Customer; 9 | import java.lang.String; 10 | import java.util.List; 11 | 12 | public interface CustomerRepository extends CrudRepository { 13 | 14 | List findByNameAndEmail(String name, String email); 15 | 16 | List findByEmailLike(String email); 17 | 18 | List findByIdIn(List ids); 19 | 20 | @Modifying 21 | @Query("update Customer cust set cust.email = :email where cust.id=:id") 22 | void updateEmail(@Param("id") int id, @Param("email") String email); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /customerdata/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /customerdata/src/test/java/com/bharath/springdata/customer/CustomerdataApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.customer; 2 | 3 | import java.util.Arrays; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.test.annotation.Rollback; 10 | import org.springframework.test.context.junit4.SpringRunner; 11 | import org.springframework.transaction.annotation.Transactional; 12 | 13 | import com.bharath.springdata.customer.entities.Address; 14 | import com.bharath.springdata.customer.entities.Customer; 15 | import com.bharath.springdata.customer.repository.CustomerRepository; 16 | 17 | @RunWith(SpringRunner.class) 18 | @SpringBootTest 19 | public class CustomerdataApplicationTests { 20 | 21 | @Autowired 22 | private CustomerRepository customerRepository; 23 | 24 | @Test 25 | public void testCreateCustomer() { 26 | Customer customer = new Customer(); 27 | customer.setName("John"); 28 | customer.setEmail("john@gmail.com"); 29 | customerRepository.save(customer); 30 | } 31 | 32 | @Test 33 | public void testReadCustomer() { 34 | Customer customer = customerRepository.findOne(1); 35 | System.out.println(customer); 36 | } 37 | 38 | @Test 39 | public void testUpdateCustomer() { 40 | Customer customer = customerRepository.findOne(1); 41 | customer.setName("John Reddy"); 42 | customerRepository.save(customer); 43 | } 44 | 45 | @Test 46 | public void testDeleteCustomer() { 47 | customerRepository.delete(1); 48 | } 49 | 50 | @Test 51 | public void testCreateCustomerWithAddress() { 52 | Customer customer = new Customer(); 53 | customer.setName("John"); 54 | customer.setEmail("john@gmail.com"); 55 | 56 | Address address = new Address(); 57 | address.setCity("Austin"); 58 | address.setState("Texas"); 59 | address.setStreetAddress("Spice Wood Springs"); 60 | address.setCountry("USA"); 61 | address.setZipcode("78755"); 62 | customer.setAddress(address); 63 | 64 | customerRepository.save(customer); 65 | 66 | } 67 | 68 | @Test 69 | public void testFindByNameAndEmail() { 70 | System.out.println(customerRepository.findByNameAndEmail("John","john@gmail.com")); 71 | } 72 | 73 | @Test 74 | public void testFindByEmailLike() { 75 | System.out.println(customerRepository.findByEmailLike("%john@g%")); 76 | } 77 | 78 | @Test 79 | public void testFindByIdIn() { 80 | System.out.println(customerRepository.findByIdIn(Arrays.asList(2))); 81 | } 82 | 83 | @Test 84 | @Transactional 85 | @Rollback(false) 86 | public void testUpdateEmail() { 87 | customerRepository.updateEmail(2, "john@bharathmail.com"); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /filedata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/filedata/.DS_Store -------------------------------------------------------------------------------- /filedata/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /filedata/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/filedata/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /filedata/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /filedata/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.files 7 | filedata 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | filedata 12 | Transaction Management 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /filedata/src/main/java/com/bharath/springdata/files/FiledataApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.files; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class FiledataApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(FiledataApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /filedata/src/main/java/com/bharath/springdata/files/entities/Image.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.files.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Lob; 6 | 7 | @Entity 8 | public class Image { 9 | 10 | @Id 11 | private long id; 12 | private String name; 13 | @Lob 14 | private byte[] data; 15 | 16 | public long getId() { 17 | return id; 18 | } 19 | 20 | public void setId(long id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public byte[] getData() { 33 | return data; 34 | } 35 | 36 | public void setData(byte[] data) { 37 | this.data = data; 38 | } 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /filedata/src/main/java/com/bharath/springdata/files/repos/ImageRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.files.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.files.entities.Image; 6 | 7 | public interface ImageRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /filedata/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /filedata/src/test/java/com/bharath/springdata/files/FiledataApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.files; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileNotFoundException; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.bharath.springdata.files.entities.Image; 16 | import com.bharath.springdata.files.repos.ImageRepository; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | public class FiledataApplicationTests { 21 | 22 | @Autowired 23 | ImageRepository repository; 24 | 25 | @Test 26 | public void testImageSave() throws IOException { 27 | Image image = new Image(); 28 | image.setId(1); 29 | image.setName("MAVEN.JPG"); 30 | 31 | File file = new File("/Users/bharaththippireddy/Documents/Images/MAVEN.JPG"); 32 | byte fileContent[] = new byte[(int) file.length()]; 33 | FileInputStream inputStream = new FileInputStream(file); 34 | inputStream.read(fileContent); 35 | 36 | image.setData(fileContent); 37 | repository.save(image); 38 | inputStream.close(); 39 | 40 | } 41 | 42 | @Test 43 | public void testReadImage() { 44 | Image image = repository.findById(1L).get(); 45 | File file = new File("/Users/bharaththippireddy/Documents/Images/downloaded/" + image.getName()); 46 | FileOutputStream fos = null; 47 | try { 48 | fos = new FileOutputStream(file); 49 | fos.write(image.getData()); 50 | } catch (FileNotFoundException e) { 51 | e.printStackTrace(); 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | } finally { 55 | try { 56 | fos.close(); 57 | } catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /hibernateinheritance/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/hibernateinheritance/.DS_Store -------------------------------------------------------------------------------- /hibernateinheritance/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /hibernateinheritance/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/hibernateinheritance/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /hibernateinheritance/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.0/apache-maven-3.5.0-bin.zip 2 | -------------------------------------------------------------------------------- /hibernateinheritance/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.hibernateinheritance 7 | hibernateinheritance 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | hibernateinheritance 12 | Inheritance in hibernate 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.7.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/java/com/bharath/springdata/hibernateinheritance/HibernateinheritanceApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class HibernateinheritanceApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(HibernateinheritanceApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/java/com/bharath/springdata/hibernateinheritance/entities/Check.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.PrimaryKeyJoinColumn; 5 | import javax.persistence.Table; 6 | 7 | @Entity 8 | @Table(name = "bankcheck") 9 | @PrimaryKeyJoinColumn(name = "id") 10 | public class Check extends Payment { 11 | 12 | private String checknumber; 13 | 14 | public String getChecknumber() { 15 | return checknumber; 16 | } 17 | 18 | public void setChecknumber(String checknumber) { 19 | this.checknumber = checknumber; 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/java/com/bharath/springdata/hibernateinheritance/entities/CreditCard.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.PrimaryKeyJoinColumn; 5 | import javax.persistence.Table; 6 | 7 | @Entity 8 | @Table(name="card") 9 | @PrimaryKeyJoinColumn(name="id") 10 | public class CreditCard extends Payment{ 11 | 12 | private String cardnumber; 13 | 14 | public String getCardnumber() { 15 | return cardnumber; 16 | } 17 | 18 | public void setCardnumber(String cardnumber) { 19 | this.cardnumber = cardnumber; 20 | } 21 | 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/java/com/bharath/springdata/hibernateinheritance/entities/Payment.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.Id; 5 | import javax.persistence.Inheritance; 6 | import javax.persistence.InheritanceType; 7 | 8 | @Entity 9 | @Inheritance(strategy = InheritanceType.JOINED) 10 | public abstract class Payment { 11 | 12 | @Id 13 | private int id; 14 | private double amount; 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public double getAmount() { 25 | return amount; 26 | } 27 | 28 | public void setAmount(double amount) { 29 | this.amount = amount; 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/java/com/bharath/springdata/hibernateinheritance/repos/PaymentRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.hibernateinheritance.entities.Payment; 6 | 7 | public interface PaymentRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /hibernateinheritance/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /hibernateinheritance/src/test/java/com/bharath/springdata/hibernateinheritance/HibernateinheritanceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.hibernateinheritance; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import com.bharath.springdata.hibernateinheritance.entities.Check; 10 | import com.bharath.springdata.hibernateinheritance.entities.CreditCard; 11 | import com.bharath.springdata.hibernateinheritance.repos.PaymentRepository; 12 | 13 | @RunWith(SpringRunner.class) 14 | @SpringBootTest 15 | public class HibernateinheritanceApplicationTests { 16 | 17 | @Autowired 18 | PaymentRepository repository; 19 | 20 | @Test 21 | public void contextLoads() { 22 | } 23 | 24 | @Test 25 | public void createPayment() { 26 | CreditCard cc = new CreditCard(); 27 | cc.setId(123); 28 | cc.setAmount(1000); 29 | cc.setCardnumber("1234567890"); 30 | repository.save(cc); 31 | } 32 | 33 | @Test 34 | public void createCheckPayment() { 35 | Check ch = new Check(); 36 | ch.setId(124); 37 | ch.setAmount(1000); 38 | ch.setChecknumber("1234567890"); 39 | repository.save(ch); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /idgenerators/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/idgenerators/.DS_Store -------------------------------------------------------------------------------- /idgenerators/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /idgenerators/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/idgenerators/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /idgenerators/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /idgenerators/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.idgenerators 7 | idgenerators 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | idgenerators 12 | IG Generators 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /idgenerators/src/main/java/com/bharath/springdata/idgenerators/CustomRandomIDGenerator.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.idgenerators; 2 | 3 | import java.io.Serializable; 4 | import java.util.Random; 5 | 6 | import org.hibernate.HibernateException; 7 | import org.hibernate.engine.spi.SharedSessionContractImplementor; 8 | import org.hibernate.id.IdentifierGenerator; 9 | 10 | public class CustomRandomIDGenerator implements IdentifierGenerator { 11 | 12 | @Override 13 | public Serializable generate(SharedSessionContractImplementor si, Object obj) throws HibernateException { 14 | Random random = null; 15 | int id = 0; 16 | random = new Random(); 17 | id = random.nextInt(1000000); 18 | return new Long(id); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /idgenerators/src/main/java/com/bharath/springdata/idgenerators/IdgeneratorsApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.idgenerators; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class IdgeneratorsApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(IdgeneratorsApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /idgenerators/src/main/java/com/bharath/springdata/idgenerators/entities/Employee.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.idgenerators.entities; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.Id; 6 | 7 | import org.hibernate.annotations.GenericGenerator; 8 | 9 | @Entity 10 | public class Employee { 11 | 12 | //@TableGenerator(name = "employee_gen", table = "id_gen", pkColumnName = "gen_name", valueColumnName = "gen_val",allocationSize=100) 13 | @GenericGenerator(name="emp_id",strategy="com.bharath.springdata.idgenerators.CustomRandomIDGenerator") 14 | @GeneratedValue(generator="emp_id") 15 | @Id 16 | //@GeneratedValue(strategy = GenerationType.TABLE,generator="employee_gen") 17 | private Long id; 18 | private String name; 19 | 20 | public Long getId() { 21 | return id; 22 | } 23 | 24 | public void setId(Long id) { 25 | this.id = id; 26 | } 27 | 28 | public String getName() { 29 | return name; 30 | } 31 | 32 | public void setName(String name) { 33 | this.name = name; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /idgenerators/src/main/java/com/bharath/springdata/idgenerators/repos/EmployeeRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.idgenerators.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.idgenerators.entities.Employee; 6 | 7 | 8 | public interface EmployeeRepository extends CrudRepository { 9 | 10 | } 11 | -------------------------------------------------------------------------------- /idgenerators/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /idgenerators/src/test/java/com/bharath/springdata/idgenerators/IdgeneratorsApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.idgenerators; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.boot.test.context.SpringBootTest; 7 | import org.springframework.test.context.junit4.SpringRunner; 8 | 9 | import com.bharath.springdata.idgenerators.entities.Employee; 10 | import com.bharath.springdata.idgenerators.repos.EmployeeRepository; 11 | 12 | @RunWith(SpringRunner.class) 13 | @SpringBootTest 14 | public class IdgeneratorsApplicationTests { 15 | 16 | @Autowired 17 | EmployeeRepository er; 18 | 19 | @Test 20 | public void testCreateEployee() { 21 | 22 | Employee employee = new Employee(); 23 | employee.setName("John"); 24 | 25 | er.save(employee); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /jpqlandnativesql/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/jpqlandnativesql/.DS_Store -------------------------------------------------------------------------------- /jpqlandnativesql/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /jpqlandnativesql/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/jpqlandnativesql/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /jpqlandnativesql/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /jpqlandnativesql/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.jpqlandnativesql 7 | jpqlandnativesql 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | jpqlandnativesql 12 | jpql and native sql 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.5.8.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /jpqlandnativesql/src/main/java/com/bharath/springdata/jpqlandnativesql/JpqlandnativesqlApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.jpqlandnativesql; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class JpqlandnativesqlApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(JpqlandnativesqlApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /jpqlandnativesql/src/main/java/com/bharath/springdata/jpqlandnativesql/entities/Student.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.jpqlandnativesql.entities; 2 | 3 | import javax.persistence.Column; 4 | import javax.persistence.Entity; 5 | import javax.persistence.GeneratedValue; 6 | import javax.persistence.GenerationType; 7 | import javax.persistence.Id; 8 | 9 | @Entity 10 | public class Student { 11 | 12 | @Id 13 | @GeneratedValue(strategy=GenerationType.AUTO) 14 | private Long id; 15 | @Column(name="fname") 16 | private String firstName; 17 | @Column(name="lname") 18 | private String lastName; 19 | private int score; 20 | 21 | public Long getId() { 22 | return id; 23 | } 24 | 25 | public void setId(Long id) { 26 | this.id = id; 27 | } 28 | 29 | public String getFirstName() { 30 | return firstName; 31 | } 32 | 33 | public void setFirstName(String firstName) { 34 | this.firstName = firstName; 35 | } 36 | 37 | public String getLastName() { 38 | return lastName; 39 | } 40 | 41 | public void setLastName(String lastName) { 42 | this.lastName = lastName; 43 | } 44 | 45 | public int getScore() { 46 | return score; 47 | } 48 | 49 | public void setScore(int score) { 50 | this.score = score; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", score=" + score + "]"; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /jpqlandnativesql/src/main/java/com/bharath/springdata/jpqlandnativesql/repos/StudentRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.jpqlandnativesql.repos; 2 | 3 | import java.util.List; 4 | 5 | import org.springframework.data.domain.Pageable; 6 | import org.springframework.data.jpa.repository.Modifying; 7 | import org.springframework.data.jpa.repository.Query; 8 | import org.springframework.data.repository.CrudRepository; 9 | import org.springframework.data.repository.query.Param; 10 | 11 | import com.bharath.springdata.jpqlandnativesql.entities.Student; 12 | 13 | public interface StudentRepository extends CrudRepository { 14 | 15 | @Query("from Student") 16 | List findAllStudents(Pageable pageable); 17 | 18 | @Query("select st.firstName,st.lastName from Student st") 19 | List findAllStudentsPartialData(); 20 | 21 | @Query("from Student where firstName=:firstName") 22 | List findAllStudentsByFirstName(@Param("firstName") String firstName); 23 | 24 | @Query("from Student where score>:min and score<:max") 25 | List findStudentsForGivenScores(@Param("min") int min, @Param("max") int max); 26 | 27 | @Modifying 28 | @Query("delete from Student where firstName = :firstName") 29 | void deleteStudentsByFirstName(@Param("firstName") String firstName); 30 | 31 | @Query(value = "select * from student", nativeQuery = true) 32 | List findAllStudentNQ(); 33 | 34 | @Query(value = "select * from student where fname=:firstName", nativeQuery = true) 35 | List findByFirstNQ(@Param("firstName")String firstName); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /jpqlandnativesql/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /jpqlandnativesql/src/test/java/com/bharath/springdata/jpqlandnativesql/JpqlandnativesqlApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.jpqlandnativesql; 2 | 3 | import java.util.List; 4 | 5 | import org.junit.Test; 6 | import org.junit.runner.RunWith; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.boot.test.context.SpringBootTest; 9 | import org.springframework.data.domain.PageRequest; 10 | import org.springframework.data.domain.Sort.Direction; 11 | import org.springframework.test.annotation.Rollback; 12 | import org.springframework.test.context.junit4.SpringRunner; 13 | import org.springframework.transaction.annotation.Transactional; 14 | 15 | import com.bharath.springdata.jpqlandnativesql.entities.Student; 16 | import com.bharath.springdata.jpqlandnativesql.repos.StudentRepository; 17 | 18 | @RunWith(SpringRunner.class) 19 | @SpringBootTest 20 | public class JpqlandnativesqlApplicationTests { 21 | 22 | @Autowired 23 | StudentRepository repository; 24 | 25 | @Test 26 | public void testStudentCreate() { 27 | Student student = new Student(); 28 | student.setFirstName("John"); 29 | student.setLastName("Ferguson"); 30 | student.setScore(88); 31 | 32 | Student student2 = new Student(); 33 | student2.setFirstName("Bill"); 34 | student2.setLastName("Gates"); 35 | student2.setScore(75); 36 | 37 | repository.save(student); 38 | repository.save(student2); 39 | } 40 | 41 | @Test 42 | public void testFindAllStudents() { 43 | System.out.println(repository.findAllStudents(new PageRequest(0, 5, Direction.DESC, "id"))); 44 | } 45 | 46 | @Test 47 | public void testFindAllStudentsPartial() { 48 | List partialData = repository.findAllStudentsPartialData(); 49 | for (Object[] objects : partialData) { 50 | System.out.println(objects[0]); 51 | System.out.println(objects[1]); 52 | } 53 | } 54 | 55 | @Test 56 | public void testFindAllStudentsByFirstName() { 57 | System.out.println(repository.findAllStudentsByFirstName("Bill")); 58 | } 59 | 60 | @Test 61 | public void testFindAllStudentsByScores() { 62 | System.out.println(repository.findStudentsForGivenScores(80, 90)); 63 | } 64 | 65 | @Test 66 | @Transactional 67 | @Rollback(false) 68 | public void testDeleteStudentsByFirstName() { 69 | repository.deleteStudentsByFirstName("Bill"); 70 | } 71 | 72 | @Test 73 | public void testFindAllStudentNQ() { 74 | System.out.println(repository.findAllStudentNQ()); 75 | } 76 | 77 | @Test 78 | public void testFindByFirstNameNQ() { 79 | System.out.println(repository.findByFirstNQ("Bill")); 80 | } 81 | 82 | } 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /patientscheduling/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/patientscheduling/.DS_Store -------------------------------------------------------------------------------- /patientscheduling/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /patientscheduling/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/patientscheduling/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /patientscheduling/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /patientscheduling/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.patientscheduling 7 | patientscheduling 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | patientscheduling 12 | Patient Appointment Scheduling Application 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/PatientschedulingApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class PatientschedulingApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(PatientschedulingApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/entities/Appointment.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.entities; 2 | 3 | import java.sql.Timestamp; 4 | 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.GenerationType; 8 | import javax.persistence.Id; 9 | import javax.persistence.JoinColumn; 10 | import javax.persistence.ManyToOne; 11 | 12 | @Entity 13 | public class Appointment { 14 | 15 | @Id 16 | @GeneratedValue(strategy = GenerationType.IDENTITY) 17 | private Long id; 18 | private Timestamp appointmentTime; 19 | private boolean started; 20 | private boolean ended; 21 | private String reason; 22 | 23 | @ManyToOne 24 | @JoinColumn(name = "patient_id") 25 | private Patient patient; 26 | 27 | @ManyToOne 28 | @JoinColumn(name = "doctor_id") 29 | private Doctor doctor; 30 | 31 | public Long getId() { 32 | return id; 33 | } 34 | 35 | public void setId(Long id) { 36 | this.id = id; 37 | } 38 | 39 | public Timestamp getAppointmentTime() { 40 | return appointmentTime; 41 | } 42 | 43 | public void setAppointmentTime(Timestamp appointmentTime) { 44 | this.appointmentTime = appointmentTime; 45 | } 46 | 47 | public boolean isStarted() { 48 | return started; 49 | } 50 | 51 | public void setStarted(boolean started) { 52 | this.started = started; 53 | } 54 | 55 | public boolean isEnded() { 56 | return ended; 57 | } 58 | 59 | public void setEnded(boolean ended) { 60 | this.ended = ended; 61 | } 62 | 63 | public String getReason() { 64 | return reason; 65 | } 66 | 67 | public void setReason(String reason) { 68 | this.reason = reason; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Appointment [id=" + id + ", appointmentTime=" + appointmentTime + ", started=" + started + ", ended=" 74 | + ended + ", reason=" + reason + "]"; 75 | } 76 | 77 | public Patient getPatient() { 78 | return patient; 79 | } 80 | 81 | public void setPatient(Patient patient) { 82 | this.patient = patient; 83 | } 84 | 85 | public Doctor getDoctor() { 86 | return doctor; 87 | } 88 | 89 | public void setDoctor(Doctor doctor) { 90 | this.doctor = doctor; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/entities/Doctor.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.entities; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Entity; 7 | import javax.persistence.GeneratedValue; 8 | import javax.persistence.GenerationType; 9 | import javax.persistence.Id; 10 | import javax.persistence.ManyToMany; 11 | import javax.persistence.OneToMany; 12 | 13 | @Entity 14 | public class Doctor { 15 | 16 | @Id 17 | @GeneratedValue(strategy = GenerationType.IDENTITY) 18 | private Long id; 19 | private String firstName; 20 | private String lastName; 21 | private String speciality; 22 | 23 | @ManyToMany(mappedBy = "doctors") 24 | private List patients; 25 | 26 | @OneToMany(mappedBy = "doctor", cascade = CascadeType.ALL) 27 | private List appointments; 28 | 29 | public Long getId() { 30 | return id; 31 | } 32 | 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | 37 | public String getFirstName() { 38 | return firstName; 39 | } 40 | 41 | public void setFirstName(String firstName) { 42 | this.firstName = firstName; 43 | } 44 | 45 | public String getLastName() { 46 | return lastName; 47 | } 48 | 49 | public void setLastName(String lastName) { 50 | this.lastName = lastName; 51 | } 52 | 53 | public String getSpeciality() { 54 | return speciality; 55 | } 56 | 57 | public void setSpeciality(String speciality) { 58 | this.speciality = speciality; 59 | } 60 | 61 | @Override 62 | public String toString() { 63 | return "Doctor [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", speciality=" + speciality 64 | + "]"; 65 | } 66 | 67 | public List getPatients() { 68 | return patients; 69 | } 70 | 71 | public void setPatients(List patients) { 72 | this.patients = patients; 73 | } 74 | 75 | public List getAppointments() { 76 | return appointments; 77 | } 78 | 79 | public void setAppointments(List appointments) { 80 | this.appointments = appointments; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/entities/Insurance.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.entities; 2 | 3 | import javax.persistence.Embeddable; 4 | 5 | @Embeddable 6 | public class Insurance { 7 | 8 | private String providerName; 9 | private double copay; 10 | 11 | public String getProviderName() { 12 | return providerName; 13 | } 14 | 15 | public void setProviderName(String providerName) { 16 | this.providerName = providerName; 17 | } 18 | 19 | public double getCopay() { 20 | return copay; 21 | } 22 | 23 | public void setCopay(double copay) { 24 | this.copay = copay; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "Insurance [providerName=" + providerName + ", copay=" + copay + "]"; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/entities/Patient.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.entities; 2 | 3 | import java.util.List; 4 | 5 | import javax.persistence.CascadeType; 6 | import javax.persistence.Embedded; 7 | import javax.persistence.Entity; 8 | import javax.persistence.FetchType; 9 | import javax.persistence.GeneratedValue; 10 | import javax.persistence.GenerationType; 11 | import javax.persistence.Id; 12 | import javax.persistence.JoinColumn; 13 | import javax.persistence.JoinTable; 14 | import javax.persistence.ManyToMany; 15 | import javax.persistence.OneToMany; 16 | 17 | @Entity 18 | public class Patient { 19 | 20 | @Id 21 | @GeneratedValue(strategy = GenerationType.IDENTITY) 22 | private Long id; 23 | private String firstName; 24 | private String lastName; 25 | private String phone; 26 | @Embedded 27 | private Insurance insurance; 28 | 29 | @ManyToMany(fetch = FetchType.EAGER) 30 | @JoinTable(name = "patients_doctors", joinColumns = @JoinColumn(name = "patient_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "doctor_id", referencedColumnName = "id")) 31 | private List doctors; 32 | 33 | @OneToMany(mappedBy = "patient", cascade = CascadeType.ALL) 34 | private List appointments; 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) { 41 | this.id = id; 42 | } 43 | 44 | public String getFirstName() { 45 | return firstName; 46 | } 47 | 48 | public void setFirstName(String firstName) { 49 | this.firstName = firstName; 50 | } 51 | 52 | public String getLastName() { 53 | return lastName; 54 | } 55 | 56 | public void setLastName(String lastName) { 57 | this.lastName = lastName; 58 | } 59 | 60 | public String getPhone() { 61 | return phone; 62 | } 63 | 64 | public void setPhone(String phone) { 65 | this.phone = phone; 66 | } 67 | 68 | public Insurance getInsurance() { 69 | return insurance; 70 | } 71 | 72 | public void setInsurance(Insurance insurance) { 73 | this.insurance = insurance; 74 | } 75 | 76 | @Override 77 | public String toString() { 78 | return "Patient [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", phone=" + phone 79 | + ", insurance=" + insurance + "]"; 80 | } 81 | 82 | public List getDoctors() { 83 | return doctors; 84 | } 85 | 86 | public void setDoctors(List doctors) { 87 | this.doctors = doctors; 88 | } 89 | 90 | public List getAppointments() { 91 | return appointments; 92 | } 93 | 94 | public void setAppointments(List appointments) { 95 | this.appointments = appointments; 96 | } 97 | 98 | } 99 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/repos/AppointmentRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.patientscheduling.entities.Appointment; 6 | 7 | public interface AppointmentRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/repos/DoctorRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.patientscheduling.entities.Doctor; 6 | 7 | public interface DoctorRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /patientscheduling/src/main/java/com/bharath/springdata/patientscheduling/repos/PatientRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling.repos; 2 | 3 | import org.springframework.data.repository.CrudRepository; 4 | 5 | import com.bharath.springdata.patientscheduling.entities.Patient; 6 | 7 | public interface PatientRepository extends CrudRepository { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /patientscheduling/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true 6 | spring.jpa.properties.hibernate.jdbc.batch_size=20 7 | spring.jpa.properties.hibernate.order_inserts=true 8 | spring.jpa.properties.hibernate.order_updates=true -------------------------------------------------------------------------------- /patientscheduling/src/test/java/com/bharath/springdata/patientscheduling/PatientschedulingApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.patientscheduling; 2 | 3 | import java.sql.Timestamp; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | import org.junit.Test; 10 | import org.junit.runner.RunWith; 11 | import org.springframework.beans.factory.annotation.Autowired; 12 | import org.springframework.boot.test.context.SpringBootTest; 13 | import org.springframework.test.context.junit4.SpringRunner; 14 | 15 | import com.bharath.springdata.patientscheduling.entities.Appointment; 16 | import com.bharath.springdata.patientscheduling.entities.Doctor; 17 | import com.bharath.springdata.patientscheduling.entities.Insurance; 18 | import com.bharath.springdata.patientscheduling.entities.Patient; 19 | import com.bharath.springdata.patientscheduling.repos.AppointmentRepository; 20 | import com.bharath.springdata.patientscheduling.repos.DoctorRepository; 21 | import com.bharath.springdata.patientscheduling.repos.PatientRepository; 22 | 23 | @RunWith(SpringRunner.class) 24 | @SpringBootTest 25 | public class PatientschedulingApplicationTests { 26 | 27 | @Autowired 28 | DoctorRepository doctorRepository; 29 | 30 | @Autowired 31 | PatientRepository patientRepository; 32 | 33 | @Autowired 34 | AppointmentRepository appointmentRepository; 35 | 36 | @Test 37 | public void testCreateDoctor() { 38 | 39 | List list = new ArrayList<>(); 40 | for (int i = 0; i < 50; i++) { 41 | Doctor doctor2 = new Doctor(); 42 | // doctor2.setId(4L); 43 | doctor2.setFirstName("Bharath2"); 44 | doctor2.setLastName("Thippireddy2"); 45 | doctor2.setSpeciality("All2"); 46 | 47 | list.add(doctor2); 48 | } 49 | 50 | doctorRepository.saveAll(list); 51 | } 52 | 53 | @Test 54 | public void testCreatePatient() { 55 | 56 | Patient patient = new Patient(); 57 | patient.setFirstName("Doug"); 58 | patient.setLastName("Bailey"); 59 | patient.setPhone("123456"); 60 | 61 | Insurance insurance = new Insurance(); 62 | insurance.setProviderName("Blue Cross Blue Shield"); 63 | insurance.setCopay(20d); 64 | 65 | patient.setInsurance(insurance); 66 | 67 | Doctor doctor = doctorRepository.findById(1L).get(); 68 | List doctors = Arrays.asList(doctor); 69 | patient.setDoctors(doctors); 70 | 71 | patientRepository.save(patient); 72 | 73 | } 74 | 75 | @Test 76 | public void testCreateAppointment() { 77 | 78 | Appointment appointment = new Appointment(); 79 | Timestamp appointmentTime = new Timestamp(new Date().getTime()); 80 | appointment.setAppointmentTime(appointmentTime); 81 | appointment.setReason("I have a problem"); 82 | appointment.setStarted(true); 83 | 84 | appointment.setPatient(patientRepository.findById(1l).get()); 85 | appointment.setDoctor(doctorRepository.findById(1L).get()); 86 | 87 | appointmentRepository.save(appointment); 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /productdata/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/productdata/.DS_Store -------------------------------------------------------------------------------- /productdata/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /productdata/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | productdata 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.springframework.ide.eclipse.core.springbuilder 15 | 16 | 17 | 18 | 19 | org.springframework.ide.eclipse.boot.validation.springbootbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.springframework.ide.eclipse.core.springnature 31 | org.eclipse.jdt.core.javanature 32 | org.eclipse.m2e.core.maven2Nature 33 | 34 | 35 | -------------------------------------------------------------------------------- /productdata/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /productdata/.settings/org.eclipse.jdt.apt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.apt.aptEnabled=false 3 | -------------------------------------------------------------------------------- /productdata/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.methodParameters=generate 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 6 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 7 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 8 | org.eclipse.jdt.core.compiler.processAnnotations=disabled 9 | org.eclipse.jdt.core.compiler.release=disabled 10 | org.eclipse.jdt.core.compiler.source=1.8 11 | -------------------------------------------------------------------------------- /productdata/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /productdata/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata 7 | productdata 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | productdata 12 | Product Repos 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | org.hibernate 35 | hibernate-ehcache 36 | 37 | 38 | 39 | mysql 40 | mysql-connector-java 41 | runtime 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-test 46 | test 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.springframework.boot 54 | spring-boot-maven-plugin 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /productdata/src/main/java/com/bharath/springdata/product/ProductdataApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.product; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class ProductdataApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(ProductdataApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /productdata/src/main/java/com/bharath/springdata/product/entities/Product.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.product.entities; 2 | 3 | import java.io.Serializable; 4 | 5 | import javax.persistence.Column; 6 | import javax.persistence.Entity; 7 | import javax.persistence.Id; 8 | import javax.persistence.Table; 9 | 10 | @Entity 11 | @Table 12 | public class Product implements Serializable { 13 | 14 | private static final long serialVersionUID = 1L; 15 | @Id 16 | private int id; 17 | private String name; 18 | @Column(name = "description") 19 | private String desc; 20 | private Double price; 21 | 22 | public int getId() { 23 | return id; 24 | } 25 | 26 | public void setId(int id) { 27 | this.id = id; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public void setName(String name) { 35 | this.name = name; 36 | } 37 | 38 | public String getDesc() { 39 | return desc; 40 | } 41 | 42 | public void setDesc(String desc) { 43 | this.desc = desc; 44 | } 45 | 46 | public Double getPrice() { 47 | return price; 48 | } 49 | 50 | public void setPrice(Double price) { 51 | this.price = price; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /productdata/src/main/java/com/bharath/springdata/product/repos/ProductRepository.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.product.repos; 2 | 3 | import org.springframework.data.domain.Pageable; 4 | import org.springframework.data.repository.PagingAndSortingRepository; 5 | 6 | import com.bharath.springdata.product.entities.Product; 7 | import java.lang.String; 8 | import java.util.List; 9 | 10 | public interface ProductRepository extends PagingAndSortingRepository { 11 | 12 | List findByName(String name); 13 | 14 | List findByNameAndDesc(String name, String desc); 15 | 16 | List findByPriceGreaterThan(Double price); 17 | 18 | List findByDescContains(String desc); 19 | 20 | List findByPriceBetween(Double price1, Double price2); 21 | 22 | List findByDescLike(String desc); 23 | 24 | List findByIdIn(List ids,Pageable pageable); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /productdata/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test1234 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /productdata/src/test/java/com/bharath/springdata/product/ProductdataApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.product; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | 6 | import java.util.Arrays; 7 | import java.util.List; 8 | 9 | import javax.persistence.EntityManager; 10 | 11 | import org.hibernate.Session; 12 | import org.junit.Test; 13 | import org.junit.runner.RunWith; 14 | import org.springframework.beans.factory.annotation.Autowired; 15 | import org.springframework.boot.test.context.SpringBootTest; 16 | import org.springframework.data.domain.PageRequest; 17 | import org.springframework.data.domain.Pageable; 18 | import org.springframework.data.domain.Sort; 19 | import org.springframework.data.domain.Sort.Direction; 20 | import org.springframework.test.context.junit4.SpringRunner; 21 | import org.springframework.transaction.annotation.Transactional; 22 | 23 | import com.bharath.springdata.product.entities.Product; 24 | import com.bharath.springdata.product.repos.ProductRepository; 25 | 26 | @RunWith(SpringRunner.class) 27 | @SpringBootTest 28 | public class ProductdataApplicationTests { 29 | 30 | @Autowired 31 | ProductRepository repository; 32 | 33 | @Autowired 34 | EntityManager entityManager; 35 | 36 | @Test 37 | public void contextLoads() { 38 | } 39 | 40 | @Test 41 | public void testCreate() { 42 | Product product = new Product(); 43 | product.setId(1); 44 | product.setName("Iphone"); 45 | product.setDesc("Awesome"); 46 | product.setPrice(1000d); 47 | 48 | repository.save(product); 49 | } 50 | 51 | @Test 52 | public void testRead() { 53 | Product product = repository.findById(1).get(); 54 | assertNotNull(product); 55 | assertEquals("Iphone", product.getName()); 56 | System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + product.getDesc()); 57 | } 58 | 59 | @Test 60 | public void testUpdate() { 61 | Product product = repository.findById(1).get(); 62 | product.setPrice(1200d); 63 | repository.save(product); 64 | 65 | } 66 | 67 | @Test 68 | public void testDelete() { 69 | if (repository.existsById(1)) { 70 | System.out.println("Deleting a product"); 71 | repository.deleteById(1); 72 | } 73 | } 74 | 75 | @Test 76 | public void testCount() { 77 | System.out.println("Total Records===============>>>>>>>>>>>>>>>" + repository.count()); 78 | 79 | } 80 | 81 | @Test 82 | public void testFindByName() { 83 | List products = repository.findByName("IWatch"); 84 | products.forEach(p -> System.out.println(p.getPrice())); 85 | 86 | List products1 = repository.findByName("IWatch"); 87 | products1.forEach(p -> System.out.println(p.getPrice())); 88 | } 89 | 90 | @Test 91 | public void testFindByNameAndDesc() { 92 | List products = repository.findByNameAndDesc("TV", "From Samsung Inc"); 93 | products.forEach(p -> System.out.println(p.getPrice())); 94 | } 95 | 96 | @Test 97 | public void testFindByPriceGreaterThan() { 98 | List products = repository.findByPriceGreaterThan(1000d); 99 | products.forEach(p -> System.out.println(p.getName())); 100 | } 101 | 102 | @Test 103 | public void testFindByDescContains() { 104 | List products = repository.findByDescContains("Apple"); 105 | products.forEach(p -> System.out.println(p.getName())); 106 | } 107 | 108 | @Test 109 | public void testFindByPriceBetween() { 110 | List products = repository.findByPriceBetween(500d, 2500d); 111 | products.forEach(p -> System.out.println(p.getName())); 112 | } 113 | 114 | @Test 115 | public void testFindByDescLike() { 116 | List products = repository.findByDescLike("%LG%"); 117 | products.forEach(p -> System.out.println(p.getName())); 118 | } 119 | 120 | @Test 121 | public void testFindByIdsIn() { 122 | // Pageable pageable = new PageRequest(0, 2); 123 | Pageable pageable = PageRequest.of(0, 2); 124 | List products = repository.findByIdIn(Arrays.asList(1, 2, 3), pageable); 125 | products.forEach(p -> System.out.println(p.getName())); 126 | } 127 | 128 | @Test 129 | public void testFindAllPaging() { 130 | Pageable pageable = PageRequest.of(0, 2); 131 | Iterable results = repository.findAll(pageable); 132 | results.forEach(p -> System.out.println(p.getName())); 133 | 134 | } 135 | 136 | @Test 137 | public void testFindAllSorting() { 138 | repository.findAll(Sort.by(new Sort.Order(Direction.DESC, "name"), new Sort.Order(null, "price"))) 139 | .forEach(p -> System.out.println(p.getName())); 140 | 141 | // repository.findAll(Sort.by("name", "price")).forEach(p -> 142 | // System.out.println(p.getName())); 143 | 144 | } 145 | 146 | @Test 147 | public void testFindAllPagingAndSorting() { 148 | Pageable pageable = PageRequest.of(0, 2, Direction.DESC, "name"); 149 | repository.findAll(pageable).forEach(p -> System.out.println(p.getName())); 150 | 151 | } 152 | 153 | @Test 154 | @Transactional 155 | public void testCaching() { 156 | Session session = entityManager.unwrap(Session.class); 157 | Product product = repository.findById(1).get(); 158 | 159 | repository.findById(1).get(); 160 | 161 | session.evict(product); 162 | 163 | repository.findById(1).get(); 164 | 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /transactionmanagement/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/transactionmanagement/.DS_Store -------------------------------------------------------------------------------- /transactionmanagement/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | 12 | ### IntelliJ IDEA ### 13 | .idea 14 | *.iws 15 | *.iml 16 | *.ipr 17 | 18 | ### NetBeans ### 19 | nbproject/private/ 20 | build/ 21 | nbbuild/ 22 | dist/ 23 | nbdist/ 24 | .nb-gradle/ -------------------------------------------------------------------------------- /transactionmanagement/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bharaththippireddy/springdatajpausinghibernate/42dcd5d8345af3ed623b8a28c5b289ccc0bb6ea1/transactionmanagement/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /transactionmanagement/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip 2 | -------------------------------------------------------------------------------- /transactionmanagement/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.bharath.springdata.transactionmanagement 7 | transactionmanagement 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | transactionmanagement 12 | Transaction Management 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.2.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | 26 | 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-data-jpa 31 | 32 | 33 | 34 | mysql 35 | mysql-connector-java 36 | runtime 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.boot 49 | spring-boot-maven-plugin 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /transactionmanagement/src/main/java/com/bharath/springdata/transactionmanagement/TransactionmanagementApplication.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.transactionmanagement; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class TransactionmanagementApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(TransactionmanagementApplication.class, args); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /transactionmanagement/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.datasource.url=jdbc:mysql://localhost:3306/mydb 2 | spring.datasource.username=root 3 | spring.datasource.password=test 4 | 5 | spring.jpa.show-sql=true -------------------------------------------------------------------------------- /transactionmanagement/src/test/java/com/bharath/springdata/transactionmanagement/TransactionmanagementApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.bharath.springdata.transactionmanagement; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class TransactionmanagementApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | --------------------------------------------------------------------------------