Embeddable samples has been edited by Rick Curtis (Jun 11, 2009).

(View changes)

Content:

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 number;
//...
}

@Embeddable
public class ContactInfo {
	public ContactInfo(){	
	}
	
	@Embedded
	Address homeAddress;
	
	@Embedded
	Phone homePhone;
//...
}

@Entity
public class User {
	@Id
	private int id;
	@Embedded
	ContactInfo contactInfo;
	
	public User(){
	}
//...
}

Collections Embeddables

Relationships Embeddables

Reply via email to