JAVA-66: New module spring-data-jpa-query
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package com.baeldung.aggregation.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Comment {
|
||||
@Id
|
||||
private Integer id;
|
||||
private Integer year;
|
||||
private boolean approved;
|
||||
private String content;
|
||||
@ManyToOne
|
||||
private Post post;
|
||||
|
||||
public Comment() {
|
||||
}
|
||||
|
||||
public Comment(int id, int year, boolean approved, String content, Post post) {
|
||||
this.id = id;
|
||||
this.year = year;
|
||||
this.approved = approved;
|
||||
this.content = content;
|
||||
this.post = post;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(Integer year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public boolean isApproved() {
|
||||
return approved;
|
||||
}
|
||||
|
||||
public void setApproved(boolean approved) {
|
||||
this.approved = approved;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Post getPost() {
|
||||
return post;
|
||||
}
|
||||
|
||||
public void setPost(Post post) {
|
||||
this.post = post;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Comment)) {
|
||||
return false;
|
||||
}
|
||||
Comment comment = (Comment) o;
|
||||
return getId().equals(comment.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId());
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package com.baeldung.aggregation.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Post {
|
||||
@Id
|
||||
private Integer id;
|
||||
private String title;
|
||||
private String content;
|
||||
@OneToMany(mappedBy = "post")
|
||||
private List<Comment> comments;
|
||||
|
||||
public Post() {
|
||||
}
|
||||
|
||||
public Post(Integer id, String title, String content) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public List<Comment> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
public void setComments(List<Comment> comments) {
|
||||
this.comments = comments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (!(o instanceof Post)) {
|
||||
return false;
|
||||
}
|
||||
Post post = (Post) o;
|
||||
return getId().equals(post.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getId());
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.aggregation.model.custom;
|
||||
|
||||
public class CommentCount {
|
||||
private Integer year;
|
||||
private Long total;
|
||||
|
||||
public CommentCount(Integer year, Long total) {
|
||||
this.year = year;
|
||||
this.total = total;
|
||||
}
|
||||
|
||||
public Integer getYear() {
|
||||
return year;
|
||||
}
|
||||
|
||||
public void setYear(Integer year) {
|
||||
this.year = year;
|
||||
}
|
||||
|
||||
public Long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public void setTotal(Long total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.aggregation.model.custom;
|
||||
|
||||
public interface ICommentCount {
|
||||
|
||||
Integer getYearComment();
|
||||
|
||||
Long getTotalComment();
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package com.baeldung.aggregation.repository;
|
||||
|
||||
import com.baeldung.aggregation.model.Comment;
|
||||
import com.baeldung.aggregation.model.custom.CommentCount;
|
||||
import com.baeldung.aggregation.model.custom.ICommentCount;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
public interface CommentRepository extends JpaRepository<Comment, Integer> {
|
||||
|
||||
@Query("SELECT c.year, COUNT(c.year) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")
|
||||
List<Object[]> countTotalCommentsByYear();
|
||||
|
||||
@Query("SELECT new com.baeldung.aggregation.model.custom.CommentCount(c.year, COUNT(c.year)) FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")
|
||||
List<CommentCount> countTotalCommentsByYearClass();
|
||||
|
||||
@Query("SELECT c.year AS yearComment, COUNT(c.year) AS totalComment FROM Comment AS c GROUP BY c.year ORDER BY c.year DESC")
|
||||
List<ICommentCount> countTotalCommentsByYearInterface();
|
||||
|
||||
@Query(value = "SELECT c.year AS yearComment, COUNT(c.*) AS totalComment FROM comment AS c GROUP BY c.year ORDER BY c.year DESC", nativeQuery = true)
|
||||
List<ICommentCount> countTotalCommentsByYearNative();
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.boot.daos;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import com.baeldung.boot.domain.Article;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public interface ArticleRepository extends JpaRepository<Article, Integer> {
|
||||
|
||||
List<Article> findAllByPublicationDate(Date publicationDate);
|
||||
|
||||
List<Article> findAllByPublicationTimeBetween(Date publicationTimeStart,
|
||||
Date publicationTimeEnd);
|
||||
|
||||
@Query("select a from Article a where a.creationDateTime <= :creationDateTime")
|
||||
List<Article> findAllWithCreationDateTimeBefore(
|
||||
@Param("creationDateTime") Date creationDateTime);
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.boot.domain;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Entity
|
||||
public class Article {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
@Temporal(TemporalType.DATE)
|
||||
private Date publicationDate;
|
||||
@Temporal(TemporalType.TIME)
|
||||
private Date publicationTime;
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
private Date creationDateTime;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.baeldung.boot.passenger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
interface CustomPassengerRepository {
|
||||
|
||||
List<Passenger> findOrderedBySeatNumberLimitedTo(int limit);
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package com.baeldung.boot.passenger;
|
||||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
class Passenger {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
@Column(nullable = false)
|
||||
private Long id;
|
||||
|
||||
@Basic(optional = false)
|
||||
@Column(nullable = false)
|
||||
private String firstName;
|
||||
|
||||
@Basic(optional = false)
|
||||
@Column(nullable = false)
|
||||
private String lastName;
|
||||
|
||||
@Basic(optional = false)
|
||||
@Column(nullable = false)
|
||||
private Integer seatNumber;
|
||||
|
||||
private Passenger(String firstName, String lastName, Integer seatNumber) {
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
this.seatNumber = seatNumber;
|
||||
}
|
||||
|
||||
static Passenger from(String firstName, String lastName, Integer seatNumber) {
|
||||
return new Passenger(firstName, lastName, seatNumber);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object object) {
|
||||
if (this == object)
|
||||
return true;
|
||||
if (object == null || getClass() != object.getClass())
|
||||
return false;
|
||||
Passenger passenger = (Passenger) object;
|
||||
return getSeatNumber() == passenger.getSeatNumber() && Objects.equals(getFirstName(), passenger.getFirstName())
|
||||
&& Objects.equals(getLastName(), passenger.getLastName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(getFirstName(), getLastName(), getSeatNumber());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder toStringBuilder = new StringBuilder(getClass().getSimpleName());
|
||||
toStringBuilder.append("{ id=").append(id);
|
||||
toStringBuilder.append(", firstName='").append(firstName).append('\'');
|
||||
toStringBuilder.append(", lastName='").append(lastName).append('\'');
|
||||
toStringBuilder.append(", seatNumber=").append(seatNumber);
|
||||
toStringBuilder.append('}');
|
||||
return toStringBuilder.toString();
|
||||
}
|
||||
|
||||
Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
Integer getSeatNumber() {
|
||||
return seatNumber;
|
||||
}
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.boot.passenger;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
interface PassengerRepository extends JpaRepository<Passenger, Long>, CustomPassengerRepository {
|
||||
|
||||
Passenger findFirstByOrderBySeatNumberAsc();
|
||||
|
||||
Passenger findTopByOrderBySeatNumberAsc();
|
||||
|
||||
List<Passenger> findByOrderBySeatNumberAsc();
|
||||
|
||||
List<Passenger> findByFirstNameIgnoreCase(String firstName);
|
||||
|
||||
List<Passenger> findByLastNameOrderBySeatNumberAsc(String lastName);
|
||||
|
||||
List<Passenger> findByLastName(String lastName, Sort sort);
|
||||
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.boot.passenger;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
|
||||
@Repository
|
||||
class PassengerRepositoryImpl implements CustomPassengerRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Override
|
||||
public List<Passenger> findOrderedBySeatNumberLimitedTo(int limit) {
|
||||
return entityManager.createQuery("SELECT p FROM Passenger p ORDER BY p.seatNumber",
|
||||
Passenger.class).setMaxResults(limit).getResultList();
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package com.baeldung.entitygraph.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Characteristic {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String type;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn
|
||||
private Item item;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return item;
|
||||
}
|
||||
|
||||
public void setItem(Item item) {
|
||||
this.item = item;
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.baeldung.entitygraph.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
@NamedEntityGraph(name = "Item.characteristics",
|
||||
attributeNodes = @NamedAttributeNode("characteristics")
|
||||
)
|
||||
public class Item {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
private String name;
|
||||
|
||||
@OneToMany(mappedBy = "item")
|
||||
private List<Characteristic> characteristics = new ArrayList<>();
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Characteristic> getCharacteristics() {
|
||||
return characteristics;
|
||||
}
|
||||
|
||||
public void setCharacteristics(List<Characteristic> characteristics) {
|
||||
this.characteristics = characteristics;
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.entitygraph.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.baeldung.entitygraph.model.Characteristic;
|
||||
|
||||
public interface CharacteristicsRepository extends JpaRepository<Characteristic, Long> {
|
||||
|
||||
@EntityGraph(attributePaths = {"item"})
|
||||
Characteristic findByType(String type);
|
||||
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.entitygraph.repository;
|
||||
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.data.jpa.repository.EntityGraph.EntityGraphType;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import com.baeldung.entitygraph.model.Item;
|
||||
|
||||
public interface ItemRepository extends JpaRepository<Item, Long> {
|
||||
|
||||
@EntityGraph(value = "Item.characteristics", type = EntityGraphType.FETCH)
|
||||
Item findByName(String name);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.baeldung.exists;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author paullatzelsperger
|
||||
* @since 2019-03-20
|
||||
*/
|
||||
@Entity
|
||||
public class Car {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private int id;
|
||||
private Integer power;
|
||||
private String model;
|
||||
|
||||
Car() {
|
||||
|
||||
}
|
||||
|
||||
public Car(int power, String model) {
|
||||
this.power = power;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public Integer getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Integer power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public String getModel() {
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(String model) {
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package com.baeldung.exists;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @author paullatzelsperger
|
||||
* @since 2019-03-20
|
||||
*/
|
||||
@Repository
|
||||
public interface CarRepository extends JpaRepository<Car, Integer> {
|
||||
|
||||
boolean existsCarByPower(int power);
|
||||
|
||||
boolean existsCarByModel(String model);
|
||||
|
||||
@Query("select case when count(c)> 0 then true else false end from Car c where c.model = :model")
|
||||
boolean existsCarExactCustomQuery(@Param("model") String model);
|
||||
|
||||
@Query("select case when count(c)> 0 then true else false end from Car c where lower(c.model) like lower(:model)")
|
||||
boolean existsCarLikeCustomQuery(@Param("model") String model);
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.baeldung.joins.model;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity
|
||||
public class Department {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToMany(mappedBy = "department")
|
||||
private List<Employee> employees;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public List<Employee> getEmployees() {
|
||||
return employees;
|
||||
}
|
||||
|
||||
public void setEmployees(List<Employee> employees) {
|
||||
this.employees = employees;
|
||||
}
|
||||
}
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.baeldung.joins.model;
|
||||
|
||||
import java.util.List;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "joins_employee")
|
||||
public class Employee {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
|
||||
@ManyToOne
|
||||
private Department department;
|
||||
|
||||
@OneToMany(mappedBy = "employee")
|
||||
private List<Phone> phones;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Department getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(Department department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public List<Phone> getPhones() {
|
||||
return phones;
|
||||
}
|
||||
|
||||
public void setPhones(List<Phone> phones) {
|
||||
this.phones = phones;
|
||||
}
|
||||
}
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
package com.baeldung.joins.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity
|
||||
public class Phone {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private long id;
|
||||
|
||||
private String number;
|
||||
|
||||
@ManyToOne
|
||||
private Employee employee;
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(String number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public Employee getEmployee() {
|
||||
return employee;
|
||||
}
|
||||
|
||||
public void setEmployee(Employee employee) {
|
||||
this.employee = employee;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fruit>
|
||||
<id>1</id>
|
||||
<name>apple</name>
|
||||
<color>red</color>
|
||||
</fruit>
|
||||
+1
@@ -0,0 +1 @@
|
||||
spring.datasource.data=classpath:db/import_joins.sql
|
||||
@@ -0,0 +1 @@
|
||||
spring.jpa.show-sql=true
|
||||
@@ -0,0 +1,13 @@
|
||||
INSERT INTO department (id, name) VALUES (1, 'Infra');
|
||||
INSERT INTO department (id, name) VALUES (2, 'Accounting');
|
||||
INSERT INTO department (id, name) VALUES (3, 'Management');
|
||||
|
||||
INSERT INTO joins_employee (id, name, age, department_id) VALUES (1, 'Baeldung', '35', 1);
|
||||
INSERT INTO joins_employee (id, name, age, department_id) VALUES (2, 'John', '35', 2);
|
||||
INSERT INTO joins_employee (id, name, age, department_id) VALUES (3, 'Jane', '35', 2);
|
||||
|
||||
INSERT INTO phone (id, number, employee_id) VALUES (1, '111', 1);
|
||||
INSERT INTO phone (id, number, employee_id) VALUES (2, '222', 1);
|
||||
INSERT INTO phone (id, number, employee_id) VALUES (3, '333', 1);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"_class": "com.baeldung.entity.Fruit",
|
||||
"name": "apple",
|
||||
"color": "red",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"_class": "com.baeldung.entity.Fruit",
|
||||
"name": "guava",
|
||||
"color": "green",
|
||||
"id": 2
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<fruit>
|
||||
<id>2</id>
|
||||
<name>guava</name>
|
||||
<color>green</color>
|
||||
</fruit>
|
||||
@@ -0,0 +1,3 @@
|
||||
insert into Article(id, publication_date, publication_time, creation_date_time) values(1, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:00', 'HH24:MI'), TO_DATE('31/12/2017 07:30', 'DD/MM/YYYY HH24:MI'));
|
||||
insert into Article(id, publication_date, publication_time, creation_date_time) values(2, TO_DATE('01/01/2018', 'DD/MM/YYYY'), TO_DATE('15:30', 'HH24:MI'), TO_DATE('15/12/2017 08:00', 'DD/MM/YYYY HH24:MI'));
|
||||
insert into Article(id, publication_date, publication_time, creation_date_time) values(3, TO_DATE('15/12/2017', 'DD/MM/YYYY'), TO_DATE('16:00', 'HH24:MI'), TO_DATE('01/12/2017 13:45', 'DD/MM/YYYY HH24:MI'));
|
||||
Reference in New Issue
Block a user