Hibernate JPA @Parent Example
The @Parent annotation is used to specify that the currently annotated embeddable attribute references back the owning entity.
Parent Reference the property as a pointer back to the owner (generally the owning entity).
@Parent mapping
The Hibernate-specific @Parent annotation allows you to reference the owner entity from within an embeddable.
Example 93. @Parent mapping usage
@Embeddable
public static class GPS {
private double latitude;
private double longitude;
@Parent
private City city;
//Getters and setters omitted for brevity
}
@Entity(name = "City")
public static class City {
@Id
@GeneratedValue
private Long id;
private String name;
@Embedded
@Target( GPS.class )
private GPS coordinates;
//Getters and setters omitted for brevity
}
Parent Reference the property as a pointer back to the owner (generally the owning entity).
@Parent mapping
The Hibernate-specific @Parent annotation allows you to reference the owner entity from within an embeddable.
Example 93. @Parent mapping usage
@Embeddable
public static class GPS {
private double latitude;
private double longitude;
@Parent
private City city;
//Getters and setters omitted for brevity
}
@Entity(name = "City")
public static class City {
@Id
@GeneratedValue
private Long id;
private String name;
@Embedded
@Target( GPS.class )
private GPS coordinates;
//Getters and setters omitted for brevity
}
Comments
Post a Comment