...
// Embedded -> relationship traversal
Query q = em.createQuery("SELECT u FROM User u , in (u.addresses) a WHERE a.coordinates.longitude=xxx");
// TODO -- add more!
...
## Nested Embeddables
In the code snippet below, there is a User Entity which has an embedded
ContactInfo. ContactInfo contains two other embeddeded embeddables, Address
and Phone.
@Embeddable
public class Address {
@Basic
private String street;
@Basic
private String city;
@Basic
private String state;
@Basic
private Integer zip;
public Address(){
}
//...
}
@Embeddable
public class Phone {
@Basic
private String phone_number;
@Basic
private String phone_type;
//...
}
@Embeddable
public class ContactInfo {
public ContactInfo(){
}
@Embedded
Address homeAddress;
@Embedded
Phone homePhone;
//...
}
@Entity
public class User {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@Embedded
ContactInfo contactInfo;
public User(){
}
//...
}
...
// Nested embeddables traversal
Query q = em.createQuery("SELECT u FROM User u WHERE u.contactInfo.homePhone.number='507-555-5555' " +
"AND u.contactInfo.homePhone.type='cell'");
// TODO -- add more!
...