committed by
maibin
parent
ea22559064
commit
8a5d9843f6
@@ -1,56 +0,0 @@
|
||||
package com.baeldung.hibernate.proxy;
|
||||
|
||||
import org.hibernate.annotations.BatchSize;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@BatchSize(size = 5)
|
||||
public class BatchEmployee implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue (strategy = GenerationType.SEQUENCE)
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private Boss boss;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "surname")
|
||||
private String surname;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Boss getBoss() {
|
||||
return boss;
|
||||
}
|
||||
|
||||
public void setBoss(Boss boss) {
|
||||
this.boss = boss;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,10 @@ package com.baeldung.hibernate.proxy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
public class Boss implements Serializable {
|
||||
public class Company implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE)
|
||||
@@ -13,14 +14,10 @@ public class Boss implements Serializable {
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
|
||||
@Column(name = "surname")
|
||||
private String surname;
|
||||
public Company() { }
|
||||
|
||||
public Boss() { }
|
||||
|
||||
public Boss(String name, String surname) {
|
||||
public Company(String name) {
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
@@ -39,11 +36,17 @@ public class Boss implements Serializable {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Company company = (Company) o;
|
||||
return Objects.equals(id, company.id) &&
|
||||
Objects.equals(name, company.name);
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.baeldung.hibernate.proxy;
|
||||
|
||||
import org.hibernate.annotations.BatchSize;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@BatchSize(size = 5)
|
||||
public class Employee implements Serializable {
|
||||
|
||||
@Id
|
||||
@@ -11,13 +15,17 @@ public class Employee implements Serializable {
|
||||
private Long id;
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private Boss boss;
|
||||
private Company workplace;
|
||||
|
||||
@Column(name = "name")
|
||||
private String name;
|
||||
@Column(name = "first_name")
|
||||
private String firstName;
|
||||
|
||||
@Column(name = "surname")
|
||||
private String surname;
|
||||
public Employee() { }
|
||||
|
||||
public Employee(Company workplace, String firstName) {
|
||||
this.workplace = workplace;
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
@@ -27,27 +35,34 @@ public class Employee implements Serializable {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Boss getBoss() {
|
||||
return boss;
|
||||
public Company getWorkplace() {
|
||||
return workplace;
|
||||
}
|
||||
|
||||
public void setBoss(Boss boss) {
|
||||
this.boss = boss;
|
||||
public void setWorkplace(Company workplace) {
|
||||
this.workplace = workplace;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getSurname() {
|
||||
return surname;
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Employee employee = (Employee) o;
|
||||
return Objects.equals(id, employee.id) &&
|
||||
Objects.equals(workplace, employee.workplace) &&
|
||||
Objects.equals(firstName, employee.firstName);
|
||||
}
|
||||
|
||||
public void setSurname(String surname) {
|
||||
this.surname = surname;
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, workplace, firstName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public class HibernateUtil {
|
||||
private static SessionFactoryBuilder getSessionFactoryBuilder(ServiceRegistry serviceRegistry) {
|
||||
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
|
||||
metadataSources.addPackage("com.baeldung.hibernate.proxy");
|
||||
metadataSources.addAnnotatedClass(Boss.class);
|
||||
metadataSources.addAnnotatedClass(Company.class);
|
||||
metadataSources.addAnnotatedClass(Employee.class);
|
||||
|
||||
Metadata metadata = metadataSources.buildMetadata();
|
||||
|
||||
Reference in New Issue
Block a user