Skip to content

Commit f55bc5d

Browse files
authored
Merge pull request eugenp#8110 from MajewskiKrzysztof/BAEL-2513
BAEL-2513
2 parents 1acf4e6 + f24db94 commit f55bc5d

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.fetchMode;
2+
3+
import org.hibernate.annotations.Fetch;
4+
import org.hibernate.annotations.FetchMode;
5+
6+
import javax.persistence.Entity;
7+
import javax.persistence.GeneratedValue;
8+
import javax.persistence.Id;
9+
import javax.persistence.OneToMany;
10+
import java.util.HashSet;
11+
import java.util.Set;
12+
13+
@Entity
14+
public class Customer {
15+
16+
@Id
17+
@GeneratedValue
18+
private Long id;
19+
20+
@OneToMany(mappedBy = "customer")
21+
@Fetch(value = FetchMode.SELECT)
22+
private Set<Order> orders = new HashSet<>();
23+
24+
public Long getId() {
25+
return id;
26+
}
27+
28+
public void setId(Long id) {
29+
this.id = id;
30+
}
31+
32+
public Set<Order> getOrders() {
33+
return orders;
34+
}
35+
36+
public void setOrders(Set<Order> orders) {
37+
this.orders = orders;
38+
}
39+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.baeldung.fetchMode;
2+
3+
import javax.persistence.*;
4+
5+
@Entity
6+
public class Order {
7+
8+
@Id
9+
@GeneratedValue
10+
private Long id;
11+
12+
private String name;
13+
14+
@ManyToOne
15+
@JoinColumn(name = "customer_id")
16+
private Customer customer;
17+
18+
public Order() {
19+
20+
}
21+
22+
public Order(String name, Customer customer) {
23+
this.name = name;
24+
this.customer = customer;
25+
}
26+
27+
public Long getId() {
28+
return id;
29+
}
30+
31+
public void setId(Long id) {
32+
this.id = id;
33+
}
34+
35+
public Customer getCustomer() {
36+
return customer;
37+
}
38+
39+
public void setCustomer(Customer customer) {
40+
this.customer = customer;
41+
}
42+
43+
public String getName() {
44+
return name;
45+
}
46+
47+
public void setName(String name) {
48+
this.name = name;
49+
}
50+
}

0 commit comments

Comments
 (0)