Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

An entity may use other fine-grained classes to represent entity state. Instances of these classes, unlike
entity instances, do not have persistent identity of their own. Instead, they exist only as part of the state
of the entity to which they belong. (From 2.0 Proposed Final Draft March 13, 2009 – do I need to provide footnote or something?)

In short, an embeddable is <fill me in!>...

Samples

\< IMAGE \\\>

...

Panel
indent20px
titleDomain model

Image Added

#Collections of Embeddables
#Relationships from Embeddables
#Nested Embeddables

Collections of Embeddables

In the code snippet below, there is a User2 User Entity which has a collection of ordered Embedded address.

Code Block
titleAddress.java
borderStylesolid
@Embeddable
public class Address {
	@Basic
	private String street;
	@Basic
	private String city;
	@Basic
	private String state;
	@Basic
	private Integer zip;

	public Address(){
	}
//...
}
Code Block
titleUser2User.java
borderStylesolid
@Entity
public class User2User {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	@ElementCollection
	@CollectionTable(name="user_addressesaddress")
	@OrderColumn
	private Set<Address> addresses = new HashSet<Address>();
	
	public User2User(){
	}
//...
}

Relationships from Embeddables

...

Code Block
titlePhone.java
borderStylesolid
@Embeddable
public class Phone {
	@Basic
	private String phone_number;
	@Basic
	private String phone_type;
//...
}
Code Block
titleContactInfo.java
borderStylesolid
@Embeddable
public class ContactInfo {
	public ContactInfo(){	
	}
	
	@Embedded
	Address homeAddress;
	
	@Embedded
	Phone homePhone;
//...
}

...