├── .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