-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HHH-16766: Load lazy hierarchical IdClass entities
- Loading branch information
Showing
10 changed files
with
637 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cid/Flight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import jakarta.persistence.*; | ||
|
||
import java.util.List; | ||
|
||
@Entity | ||
@Table(name = "flight") | ||
public class Flight { | ||
|
||
@Id | ||
@Column(name = "id") | ||
private Integer id; | ||
|
||
@OneToMany(mappedBy = "flight", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private List<FlightSegment> segments; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public List<FlightSegment> getSegments() { | ||
return segments; | ||
} | ||
|
||
public void setSegments(List<FlightSegment> segments) { | ||
this.segments = segments; | ||
} | ||
|
||
public void addSegment(FlightSegment segment) { | ||
segment.setFlight(this); | ||
segments.add(segment); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cid/FlightSegment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@IdClass(FlightSegmentId.class) | ||
@Table(name = "flight_segment") | ||
public class FlightSegment { | ||
|
||
@Id | ||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "flight_id", nullable = false) | ||
private Flight flight; | ||
|
||
@Id | ||
@Column(name = "segment_number") | ||
private Integer segmentNumber; | ||
|
||
@OneToOne(mappedBy = "segment", cascade = CascadeType.ALL, fetch = FetchType.LAZY) | ||
private FlightSegmentConfiguration configuration; | ||
|
||
public Flight getFlight() { | ||
return flight; | ||
} | ||
|
||
public void setFlight(Flight flight) { | ||
this.flight = flight; | ||
} | ||
|
||
public Integer getSegmentNumber() { | ||
return segmentNumber; | ||
} | ||
|
||
public void setSegmentNumber(Integer segmentNumber) { | ||
this.segmentNumber = segmentNumber; | ||
} | ||
|
||
public FlightSegmentConfiguration getConfiguration() { | ||
return configuration; | ||
} | ||
|
||
public void setConfiguration(FlightSegmentConfiguration configuration) { | ||
configuration.setSegment(this); | ||
this.configuration = configuration; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...core/src/test/java/org/hibernate/orm/test/annotations/cid/FlightSegmentConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@IdClass(FlightSegmentConfigurationId.class) | ||
@Table(name = "flight_segment_configuration") | ||
public class FlightSegmentConfiguration { | ||
|
||
@Id | ||
@OneToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "flight_id", referencedColumnName = "flight_id", nullable = false) | ||
@JoinColumn(name = "segment_number", referencedColumnName = "segment_number", nullable = false) | ||
private FlightSegment segment; | ||
|
||
public FlightSegment getSegment() { | ||
return segment; | ||
} | ||
|
||
public void setSegment(FlightSegment segment) { | ||
this.segment = segment; | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...re/src/test/java/org/hibernate/orm/test/annotations/cid/FlightSegmentConfigurationId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
public class FlightSegmentConfigurationId implements Serializable { | ||
|
||
private FlightSegmentId segment; | ||
|
||
public FlightSegmentConfigurationId() { | ||
} | ||
|
||
public FlightSegmentConfigurationId(FlightSegmentId segment) { | ||
this.segment = segment; | ||
} | ||
|
||
public FlightSegmentId getSegment() { | ||
return segment; | ||
} | ||
|
||
public void setSegment(FlightSegmentId segment) { | ||
this.segment = segment; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
FlightSegmentConfigurationId that = (FlightSegmentConfigurationId) o; | ||
return Objects.equals(segment, that.segment); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(segment); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", FlightSegmentConfigurationId.class.getSimpleName() + "[", "]") | ||
.add("segment=" + segment) | ||
.toString(); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cid/FlightSegmentId.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import java.io.Serializable; | ||
import java.util.Objects; | ||
import java.util.StringJoiner; | ||
|
||
public class FlightSegmentId implements Serializable { | ||
|
||
private Integer flight; | ||
private Integer segmentNumber; | ||
|
||
public FlightSegmentId() { | ||
} | ||
|
||
public FlightSegmentId(Integer flight, Integer segmentNumber) { | ||
this.flight = flight; | ||
this.segmentNumber = segmentNumber; | ||
} | ||
|
||
public Integer getFlight() { | ||
return flight; | ||
} | ||
|
||
public void setFlight(Integer flight) { | ||
this.flight = flight; | ||
} | ||
|
||
public Integer getSegmentNumber() { | ||
return segmentNumber; | ||
} | ||
|
||
public void setSegmentNumber(Integer segmentNumber) { | ||
this.segmentNumber = segmentNumber; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
FlightSegmentId that = (FlightSegmentId) o; | ||
return Objects.equals(flight, that.flight) && Objects.equals(segmentNumber, that.segmentNumber); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(flight, segmentNumber); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return new StringJoiner(", ", FlightSegmentId.class.getSimpleName() + "[", "]") | ||
.add("flight=" + flight) | ||
.add("segmentNumber=" + segmentNumber) | ||
.toString(); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
hibernate-core/src/test/java/org/hibernate/orm/test/annotations/cid/Freight.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.hibernate.orm.test.annotations.cid; | ||
|
||
import jakarta.persistence.*; | ||
|
||
@Entity | ||
@Table(name = "freight") | ||
public class Freight { | ||
|
||
@Id | ||
@Column(name = "freight_number") | ||
private Integer freightNumber; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "flight_id", referencedColumnName = "flight_id") | ||
@JoinColumn(name = "segment_number", referencedColumnName = "segment_number") | ||
private FlightSegment flightSegment; | ||
|
||
public Integer getFreightNumber() { | ||
return freightNumber; | ||
} | ||
|
||
public void setFreightNumber(Integer freightNumber) { | ||
this.freightNumber = freightNumber; | ||
} | ||
|
||
public FlightSegment getFlightSegment() { | ||
return flightSegment; | ||
} | ||
|
||
public void setFlightSegment(FlightSegment flightSegment) { | ||
this.flightSegment = flightSegment; | ||
} | ||
|
||
} |
Oops, something went wrong.