HHH-12361 - In the User Guide, omit constructors and equals/hashCode for brevity

This commit is contained in:
Vlad Mihalcea 2018-07-30 15:11:46 +03:00
parent 8bd79b29cf
commit 870a033a52
66 changed files with 692 additions and 169 deletions

View File

@ -829,7 +829,12 @@ as illustrated by the following example.
==== ====
[source, JAVA, indent=0] [source, JAVA, indent=0]
---- ----
include::{sourcedir}/CascadeOnDeleteTest.java[tags=pc-cascade-on-delete-mapping-example] include::{sourcedir}/CascadeOnDeleteTest.java[tags=pc-cascade-on-delete-mapping-Person-example]
----
[source, JAVA, indent=0]
----
include::{sourcedir}/CascadeOnDeleteTest.java[tags=pc-cascade-on-delete-mapping-Phone-example]
---- ----
[source, SQL, indent=0] [source, SQL, indent=0]

View File

@ -71,9 +71,14 @@ public class ManyToManyBidirectionalTest extends BaseEntityManagerFunctionalTest
@NaturalId @NaturalId
private String registrationNumber; private String registrationNumber;
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<Address> addresses = new ArrayList<>(); private List<Address> addresses = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-many-to-many-bidirectional-example[]
public Person() { public Person() {
} }
@ -85,6 +90,7 @@ public class ManyToManyBidirectionalTest extends BaseEntityManagerFunctionalTest
return addresses; return addresses;
} }
//tag::associations-many-to-many-bidirectional-example[]
public void addAddress(Address address) { public void addAddress(Address address) {
addresses.add( address ); addresses.add( address );
address.getOwners().add( this ); address.getOwners().add( this );
@ -130,6 +136,10 @@ public class ManyToManyBidirectionalTest extends BaseEntityManagerFunctionalTest
@ManyToMany(mappedBy = "addresses") @ManyToMany(mappedBy = "addresses")
private List<Person> owners = new ArrayList<>(); private List<Person> owners = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-many-to-many-bidirectional-example[]
public Address() { public Address() {
} }
@ -159,6 +169,7 @@ public class ManyToManyBidirectionalTest extends BaseEntityManagerFunctionalTest
return owners; return owners;
} }
//tag::associations-many-to-many-bidirectional-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -81,9 +81,17 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
@NaturalId @NaturalId
private String registrationNumber; private String registrationNumber;
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(
mappedBy = "person",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<PersonAddress> addresses = new ArrayList<>(); private List<PersonAddress> addresses = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-many-to-many-bidirectional-with-link-entity-example[]
public Person() { public Person() {
} }
@ -99,6 +107,7 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
return addresses; return addresses;
} }
//tag::associations-many-to-many-bidirectional-with-link-entity-example[]
public void addAddress(Address address) { public void addAddress(Address address) {
PersonAddress personAddress = new PersonAddress( this, address ); PersonAddress personAddress = new PersonAddress( this, address );
addresses.add( personAddress ); addresses.add( personAddress );
@ -142,6 +151,10 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
@ManyToOne @ManyToOne
private Address address; private Address address;
//Getters and setters are omitted for brevity
//end::associations-many-to-many-bidirectional-with-link-entity-example[]
public PersonAddress() { public PersonAddress() {
} }
@ -166,6 +179,7 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
this.address = address; this.address = address;
} }
//tag::associations-many-to-many-bidirectional-with-link-entity-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {
@ -199,9 +213,17 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
private String postalCode; private String postalCode;
@OneToMany(mappedBy = "address", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(
mappedBy = "address",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<PersonAddress> owners = new ArrayList<>(); private List<PersonAddress> owners = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-many-to-many-bidirectional-with-link-entity-example[]
public Address() { public Address() {
} }
@ -231,6 +253,7 @@ public class ManyToManyBidirectionalWithLinkEntityTest extends BaseEntityManager
return owners; return owners;
} }
//tag::associations-many-to-many-bidirectional-with-link-entity-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -100,12 +100,17 @@ public class ManyToManyUnidirectionalTest extends BaseEntityManagerFunctionalTes
@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE}) @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
private List<Address> addresses = new ArrayList<>(); private List<Address> addresses = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-many-to-many-unidirectional-example[]
public Person() { public Person() {
} }
public List<Address> getAddresses() { public List<Address> getAddresses() {
return addresses; return addresses;
} }
//tag::associations-many-to-many-unidirectional-example[]
} }
@Entity(name = "Address") @Entity(name = "Address")
@ -120,6 +125,10 @@ public class ManyToManyUnidirectionalTest extends BaseEntityManagerFunctionalTes
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::associations-many-to-many-unidirectional-example[]
public Address() { public Address() {
} }
@ -139,6 +148,7 @@ public class ManyToManyUnidirectionalTest extends BaseEntityManagerFunctionalTes
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::associations-many-to-many-unidirectional-example[]
} }
//end::associations-many-to-many-unidirectional-example[] //end::associations-many-to-many-unidirectional-example[]
} }

View File

@ -58,8 +58,8 @@ public class ManyToOneTest extends BaseEntityManagerFunctionalTestCase {
@GeneratedValue @GeneratedValue
private Long id; private Long id;
public Person() { //Getters and setters are omitted for brevity
}
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -78,6 +78,10 @@ public class ManyToOneTest extends BaseEntityManagerFunctionalTestCase {
) )
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::associations-many-to-one-example[]
public Phone() { public Phone() {
} }
@ -100,6 +104,7 @@ public class ManyToOneTest extends BaseEntityManagerFunctionalTestCase {
public void setPerson(Person person) { public void setPerson(Person person) {
this.person = person; this.person = person;
} }
//tag::associations-many-to-one-example[]
} }
//end::associations-many-to-one-example[] //end::associations-many-to-one-example[]
} }

View File

@ -62,9 +62,14 @@ public class OneToManyBidirectionalTest extends BaseEntityManagerFunctionalTestC
@Id @Id
@GeneratedValue @GeneratedValue
private Long id; private Long id;
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-one-to-many-bidirectional-example[]
public Person() { public Person() {
} }
@ -76,6 +81,7 @@ public class OneToManyBidirectionalTest extends BaseEntityManagerFunctionalTestC
return phones; return phones;
} }
//tag::associations-one-to-many-bidirectional-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
phones.add( phone ); phones.add( phone );
phone.setPerson( this ); phone.setPerson( this );
@ -101,6 +107,10 @@ public class OneToManyBidirectionalTest extends BaseEntityManagerFunctionalTestC
@ManyToOne @ManyToOne
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::associations-one-to-many-bidirectional-example[]
public Phone() { public Phone() {
} }
@ -124,6 +134,7 @@ public class OneToManyBidirectionalTest extends BaseEntityManagerFunctionalTestC
this.person = person; this.person = person;
} }
//tag::associations-one-to-many-bidirectional-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -59,15 +59,22 @@ public class OneToManyUnidirectionalTest extends BaseEntityManagerFunctionalTest
@Id @Id
@GeneratedValue @GeneratedValue
private Long id; private Long id;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::associations-one-to-many-unidirectional-example[]
public Person() { public Person() {
} }
public List<Phone> getPhones() { public List<Phone> getPhones() {
return phones; return phones;
} }
//tag::associations-one-to-many-unidirectional-example[]
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -80,6 +87,10 @@ public class OneToManyUnidirectionalTest extends BaseEntityManagerFunctionalTest
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::associations-one-to-many-unidirectional-example[]
public Phone() { public Phone() {
} }
@ -94,6 +105,7 @@ public class OneToManyUnidirectionalTest extends BaseEntityManagerFunctionalTest
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::associations-one-to-many-unidirectional-example[]
} }
//end::associations-one-to-many-unidirectional-example[] //end::associations-one-to-many-unidirectional-example[]
} }

View File

@ -64,15 +64,16 @@ public class OneToOneBidirectionalLazyTest extends BaseEntityManagerFunctionalTe
@LazyToOne( LazyToOneOption.NO_PROXY ) @LazyToOne( LazyToOneOption.NO_PROXY )
private PhoneDetails details; private PhoneDetails details;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-lazy-example[]
public Phone() { public Phone() {
} }
public Phone(String number) { public Phone(String number) {
this.number = number; this.number = number;
} }
//Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-lazy-example[]
public Long getId() { public Long getId() {
return id; return id;
@ -86,6 +87,7 @@ public class OneToOneBidirectionalLazyTest extends BaseEntityManagerFunctionalTe
return details; return details;
} }
//tag::associations-one-to-one-bidirectional-lazy-example[]
public void addDetails(PhoneDetails details) { public void addDetails(PhoneDetails details) {
details.setPhone( this ); details.setPhone( this );
this.details = details; this.details = details;
@ -97,7 +99,6 @@ public class OneToOneBidirectionalLazyTest extends BaseEntityManagerFunctionalTe
this.details = null; this.details = null;
} }
} }
//tag::associations-one-to-one-bidirectional-lazy-example[]
} }
@Entity(name = "PhoneDetails") @Entity(name = "PhoneDetails")
@ -115,6 +116,10 @@ public class OneToOneBidirectionalLazyTest extends BaseEntityManagerFunctionalTe
@JoinColumn(name = "phone_id") @JoinColumn(name = "phone_id")
private Phone phone; private Phone phone;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-lazy-example[]
public PhoneDetails() { public PhoneDetails() {
} }
@ -124,8 +129,6 @@ public class OneToOneBidirectionalLazyTest extends BaseEntityManagerFunctionalTe
} }
//Getters and setters are omitted for brevity //Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-lazy-example[]
public String getProvider() { public String getProvider() {
return provider; return provider;
} }

View File

@ -94,9 +94,18 @@ public class OneToOneBidirectionalTest extends BaseEntityManagerFunctionalTestCa
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
@OneToOne(mappedBy = "phone", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY) @OneToOne(
mappedBy = "phone",
cascade = CascadeType.ALL,
orphanRemoval = true,
fetch = FetchType.LAZY
)
private PhoneDetails details; private PhoneDetails details;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-example[]
public Phone() { public Phone() {
} }
@ -116,6 +125,7 @@ public class OneToOneBidirectionalTest extends BaseEntityManagerFunctionalTestCa
return details; return details;
} }
//tag::associations-one-to-one-bidirectional-example[]
public void addDetails(PhoneDetails details) { public void addDetails(PhoneDetails details) {
details.setPhone( this ); details.setPhone( this );
this.details = details; this.details = details;
@ -144,6 +154,10 @@ public class OneToOneBidirectionalTest extends BaseEntityManagerFunctionalTestCa
@JoinColumn(name = "phone_id") @JoinColumn(name = "phone_id")
private Phone phone; private Phone phone;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-bidirectional-example[]
public PhoneDetails() { public PhoneDetails() {
} }
@ -171,6 +185,7 @@ public class OneToOneBidirectionalTest extends BaseEntityManagerFunctionalTestCa
public void setPhone(Phone phone) { public void setPhone(Phone phone) {
this.phone = phone; this.phone = phone;
} }
//tag::associations-one-to-one-bidirectional-example[]
} }
//end::associations-one-to-one-bidirectional-example[] //end::associations-one-to-one-bidirectional-example[]
} }

View File

@ -59,6 +59,10 @@ public class OneToOneUnidirectionalTest extends BaseEntityManagerFunctionalTestC
@JoinColumn(name = "details_id") @JoinColumn(name = "details_id")
private PhoneDetails details; private PhoneDetails details;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-unidirectional-example[]
public Phone() { public Phone() {
} }
@ -81,6 +85,7 @@ public class OneToOneUnidirectionalTest extends BaseEntityManagerFunctionalTestC
public void setDetails(PhoneDetails details) { public void setDetails(PhoneDetails details) {
this.details = details; this.details = details;
} }
//tag::associations-one-to-one-unidirectional-example[]
} }
@Entity(name = "PhoneDetails") @Entity(name = "PhoneDetails")
@ -94,6 +99,10 @@ public class OneToOneUnidirectionalTest extends BaseEntityManagerFunctionalTestC
private String technology; private String technology;
//Getters and setters are omitted for brevity
//end::associations-one-to-one-unidirectional-example[]
public PhoneDetails() { public PhoneDetails() {
} }
@ -113,6 +122,7 @@ public class OneToOneUnidirectionalTest extends BaseEntityManagerFunctionalTestC
public void setTechnology(String technology) { public void setTechnology(String technology) {
this.technology = technology; this.technology = technology;
} }
//tag::associations-one-to-one-unidirectional-example[]
} }
//end::associations-one-to-one-unidirectional-example[] //end::associations-one-to-one-unidirectional-example[]
} }

View File

@ -164,6 +164,10 @@ public class NonStrictReadWriteCacheTest extends BaseEntityManagerFunctionalTest
@Version @Version
private int version; private int version;
//Getters and setters are omitted for brevity
//end::caching-entity-mapping-example[]
public Phone() {} public Phone() {}
public Phone(String mobile) { public Phone(String mobile) {
@ -185,6 +189,7 @@ public class NonStrictReadWriteCacheTest extends BaseEntityManagerFunctionalTest
public void setPerson(Person person) { public void setPerson(Person person) {
this.person = person; this.person = person;
} }
//tag::caching-entity-mapping-example[]
} }
//end::caching-entity-mapping-example[] //end::caching-entity-mapping-example[]
} }

View File

@ -267,7 +267,11 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
@Column(name = "code", unique = true) @Column(name = "code", unique = true)
private String code; private String code;
public Person() {} //Getters and setters are omitted for brevity
//end::caching-entity-natural-id-mapping-example[]
public Person() {}
public Person(String name) { public Person(String name) {
this.name = name; this.name = name;
@ -292,6 +296,7 @@ public class SecondLevelCacheTest extends BaseEntityManagerFunctionalTestCase {
public void setCode(String code) { public void setCode(String code) {
this.code = code; this.code = code;
} }
//tag::caching-entity-natural-id-mapping-example[]
} }
//end::caching-entity-natural-id-mapping-example[] //end::caching-entity-natural-id-mapping-example[]
} }

View File

@ -51,8 +51,13 @@ public class ArrayTest extends BaseEntityManagerFunctionalTestCase {
@Id @Id
private Long id; private Long id;
private String[] phones; private String[] phones;
//Getters and setters are omitted for brevity
//end::collections-array-binary-example[]
public Person() { public Person() {
} }
@ -67,6 +72,7 @@ public class ArrayTest extends BaseEntityManagerFunctionalTestCase {
public void setPhones(String[] phones) { public void setPhones(String[] phones) {
this.phones = phones; this.phones = phones;
} }
//tag::collections-array-binary-example[]
} }
//end::collections-array-binary-example[] //end::collections-array-binary-example[]
} }

View File

@ -90,9 +90,14 @@ public class BasicTypeElementCollectionTest extends BaseEntityManagerFunctionalT
@ElementCollection @ElementCollection
private List<String> phones = new ArrayList<>(); private List<String> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::collections-collection-proxy-entity-example[]
public List<String> getPhones() { public List<String> getPhones() {
return phones; return phones;
} }
//tag::collections-collection-proxy-entity-example[]
} }
//end::collections-collection-proxy-entity-example[] //end::collections-collection-proxy-entity-example[]
} }

View File

@ -56,9 +56,14 @@ public class BidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@Id @Id
private Long id; private Long id;
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::collections-bidirectional-bag-example[]
public Person() { public Person() {
} }
@ -70,6 +75,7 @@ public class BidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
return phones; return phones;
} }
//tag::collections-bidirectional-bag-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
phones.add( phone ); phones.add( phone );
phone.setPerson( this ); phone.setPerson( this );
@ -96,6 +102,10 @@ public class BidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@ManyToOne @ManyToOne
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::collections-bidirectional-bag-example[]
public Phone() { public Phone() {
} }
@ -125,6 +135,7 @@ public class BidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
this.person = person; this.person = person;
} }
//tag::collections-bidirectional-bag-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -74,6 +74,10 @@ public class BidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
@MapKeyEnumerated @MapKeyEnumerated
private Map<PhoneType, Phone> phoneRegister = new HashMap<>(); private Map<PhoneType, Phone> phoneRegister = new HashMap<>();
//Getters and setters are omitted for brevity
//end::collections-map-bidirectional-example[]
public Person() { public Person() {
} }
@ -85,6 +89,7 @@ public class BidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
return phoneRegister; return phoneRegister;
} }
//tag::collections-map-bidirectional-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
phone.setPerson( this ); phone.setPerson( this );
phoneRegister.put( phone.getType(), phone ); phoneRegister.put( phone.getType(), phone );
@ -108,6 +113,10 @@ public class BidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
@ManyToOne @ManyToOne
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::collections-map-bidirectional-example[]
public Phone() { public Phone() {
} }
@ -136,6 +145,7 @@ public class BidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
public void setPerson(Person person) { public void setPerson(Person person) {
this.person = person; this.person = person;
} }
//tag::collections-map-bidirectional-example[]
} }
//end::collections-map-bidirectional-example[] //end::collections-map-bidirectional-example[]
} }

View File

@ -69,6 +69,10 @@ public class BidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OneToMany(mappedBy = "person", cascade = CascadeType.ALL)
private Set<Phone> phones = new HashSet<>(); private Set<Phone> phones = new HashSet<>();
//Getters and setters are omitted for brevity
//end::collections-bidirectional-set-example[]
public Person() { public Person() {
} }
@ -80,6 +84,7 @@ public class BidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
return phones; return phones;
} }
//tag::collections-bidirectional-set-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
phones.add( phone ); phones.add( phone );
phone.setPerson( this ); phone.setPerson( this );
@ -106,6 +111,10 @@ public class BidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
@ManyToOne @ManyToOne
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::collections-bidirectional-set-example[]
public Phone() { public Phone() {
} }
@ -135,6 +144,7 @@ public class BidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
this.person = person; this.person = person;
} }
//tag::collections-bidirectional-set-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -78,6 +78,10 @@ public class ElementCollectionMapTest extends BaseEntityManagerFunctionalTestCas
@Column(name = "since") @Column(name = "since")
private Map<Phone, Date> phoneRegister = new HashMap<>(); private Map<Phone, Date> phoneRegister = new HashMap<>();
//Getters and setters are omitted for brevity
//end::collections-map-value-type-entity-key-example[]
public Person() {} public Person() {}
public Person(Long id) { public Person(Long id) {
@ -87,6 +91,7 @@ public class ElementCollectionMapTest extends BaseEntityManagerFunctionalTestCas
public Map<Phone, Date> getPhoneRegister() { public Map<Phone, Date> getPhoneRegister() {
return phoneRegister; return phoneRegister;
} }
//tag::collections-map-value-type-entity-key-example[]
} }
@Embeddable @Embeddable
@ -97,6 +102,10 @@ public class ElementCollectionMapTest extends BaseEntityManagerFunctionalTestCas
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-map-value-type-entity-key-example[]
public Phone() { public Phone() {
} }
@ -112,6 +121,7 @@ public class ElementCollectionMapTest extends BaseEntityManagerFunctionalTestCas
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::collections-map-value-type-entity-key-example[]
} }
//end::collections-map-value-type-entity-key-example[] //end::collections-map-value-type-entity-key-example[]
} }

View File

@ -55,9 +55,14 @@ public class EmbeddableTypeElementCollectionTest extends BaseEntityManagerFuncti
@ElementCollection @ElementCollection
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::collections-embeddable-type-collection-lifecycle-entity-example[]
public List<Phone> getPhones() { public List<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-embeddable-type-collection-lifecycle-entity-example[]
} }
@Embeddable @Embeddable
@ -68,6 +73,10 @@ public class EmbeddableTypeElementCollectionTest extends BaseEntityManagerFuncti
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-embeddable-type-collection-lifecycle-entity-example[]
public Phone() { public Phone() {
} }
@ -83,6 +92,7 @@ public class EmbeddableTypeElementCollectionTest extends BaseEntityManagerFuncti
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::collections-embeddable-type-collection-lifecycle-entity-example[]
} }
//end::collections-embeddable-type-collection-lifecycle-entity-example[] //end::collections-embeddable-type-collection-lifecycle-entity-example[]
} }

View File

@ -147,6 +147,10 @@ public class MapKeyTypeTest extends BaseEntityManagerFunctionalTestCase {
@Column(name = "phone_number") @Column(name = "phone_number")
private Map<Date, Integer> callRegister = new HashMap<>(); private Map<Date, Integer> callRegister = new HashMap<>();
//Getters and setters are omitted for brevity
//end::collections-map-custom-key-type-mapping-example[]
public void setId(Long id) { public void setId(Long id) {
this.id = id; this.id = id;
} }
@ -154,7 +158,7 @@ public class MapKeyTypeTest extends BaseEntityManagerFunctionalTestCase {
public Map<Date, Integer> getCallRegister() { public Map<Date, Integer> getCallRegister() {
return callRegister; return callRegister;
} }
//tag::collections-map-custom-key-type-mapping-example[]
} }
//end::collections-map-custom-key-type-mapping-example[] //end::collections-map-custom-key-type-mapping-example[]
} }

View File

@ -80,8 +80,13 @@ public class OrderedBySQLTest extends BaseEntityManagerFunctionalTestCase {
private String name; private String name;
@OneToMany(mappedBy = "person", cascade = CascadeType.ALL) @OneToMany(
@org.hibernate.annotations.OrderBy(clause = "CHAR_LENGTH(name) DESC") mappedBy = "person",
cascade = CascadeType.ALL
)
@org.hibernate.annotations.OrderBy(
clause = "CHAR_LENGTH(name) DESC"
)
private List<Article> articles = new ArrayList<>(); private List<Article> articles = new ArrayList<>();
//Getters and setters are omitted for brevity //Getters and setters are omitted for brevity
@ -128,6 +133,9 @@ public class OrderedBySQLTest extends BaseEntityManagerFunctionalTestCase {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private Person person; private Person person;
//Getters and setters are omitted for brevity
//end::collections-customizing-ordered-by-sql-clause-mapping-example[]
private Article() { private Article() {
} }
@ -136,9 +144,6 @@ public class OrderedBySQLTest extends BaseEntityManagerFunctionalTestCase {
this.content = content; this.content = content;
} }
//Getters and setters are omitted for brevity
//end::collections-customizing-ordered-by-sql-clause-mapping-example[]
public Long getId() { public Long getId() {
return id; return id;
} }

View File

@ -55,9 +55,14 @@ public class UnidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@Id @Id
private Long id; private Long id;
@OneToMany(cascade = CascadeType.ALL) @OneToMany(cascade = CascadeType.ALL)
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::collections-unidirectional-bag-example[]
public Person() { public Person() {
} }
@ -68,6 +73,7 @@ public class UnidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
public List<Phone> getPhones() { public List<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-unidirectional-bag-example[]
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -81,6 +87,10 @@ public class UnidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-unidirectional-bag-example[]
public Phone() { public Phone() {
} }
@ -101,6 +111,7 @@ public class UnidirectionalBagTest extends BaseEntityManagerFunctionalTestCase {
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::collections-unidirectional-bag-example[]
} }
//end::collections-unidirectional-bag-example[] //end::collections-unidirectional-bag-example[]
} }

View File

@ -75,6 +75,10 @@ public class UnidirectionalComparatorSortedSetTest extends BaseEntityManagerFunc
@SortComparator(ReverseComparator.class) @SortComparator(ReverseComparator.class)
private SortedSet<Phone> phones = new TreeSet<>(); private SortedSet<Phone> phones = new TreeSet<>();
//Getters and setters are omitted for brevity
//end::collections-unidirectional-sorted-set-custom-comparator-example[]
public Person() { public Person() {
} }
@ -85,9 +89,11 @@ public class UnidirectionalComparatorSortedSetTest extends BaseEntityManagerFunc
public Set<Phone> getPhones() { public Set<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-unidirectional-sorted-set-custom-comparator-example[]
} }
public static class ReverseComparator implements Comparator<Phone> { public static class ReverseComparator implements Comparator<Phone> {
@Override @Override
public int compare(Phone o1, Phone o2) { public int compare(Phone o1, Phone o2) {
return o2.compareTo( o1 ); return o2.compareTo( o1 );
@ -106,6 +112,10 @@ public class UnidirectionalComparatorSortedSetTest extends BaseEntityManagerFunc
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-unidirectional-sorted-set-custom-comparator-example[]
public Phone() { public Phone() {
} }
@ -127,6 +137,7 @@ public class UnidirectionalComparatorSortedSetTest extends BaseEntityManagerFunc
return number; return number;
} }
//tag::collections-unidirectional-sorted-set-custom-comparator-example[]
@Override @Override
public int compareTo(Phone o) { public int compareTo(Phone o) {
return number.compareTo( o.getNumber() ); return number.compareTo( o.getNumber() );

View File

@ -77,13 +77,17 @@ public class UnidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
@JoinTable( @JoinTable(
name = "phone_register", name = "phone_register",
joinColumns = @JoinColumn(name = "phone_id"), joinColumns = @JoinColumn(name = "phone_id"),
inverseJoinColumns = @JoinColumn(name = "person_id")) inverseJoinColumns = @JoinColumn(name = "person_id"))
@MapKey(name = "since") @MapKey(name = "since")
@MapKeyTemporal(TemporalType.TIMESTAMP) @MapKeyTemporal(TemporalType.TIMESTAMP)
private Map<Date, Phone> phoneRegister = new HashMap<>(); private Map<Date, Phone> phoneRegister = new HashMap<>();
//Getters and setters are omitted for brevity
//end::collections-map-unidirectional-example[]
public Person() { public Person() {
} }
@ -95,6 +99,7 @@ public class UnidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
return phoneRegister; return phoneRegister;
} }
//tag::collections-map-unidirectional-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
phoneRegister.put( phone.getSince(), phone ); phoneRegister.put( phone.getSince(), phone );
} }
@ -114,6 +119,10 @@ public class UnidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
private Date since; private Date since;
//Getters and setters are omitted for brevity
//end::collections-map-unidirectional-example[]
public Phone() { public Phone() {
} }
@ -134,6 +143,7 @@ public class UnidirectionalMapTest extends BaseEntityManagerFunctionalTestCase {
public Date getSince() { public Date getSince() {
return since; return since;
} }
//tag::collections-map-unidirectional-example[]
} }
//end::collections-map-unidirectional-example[] //end::collections-map-unidirectional-example[]
} }

View File

@ -54,10 +54,15 @@ public class UnidirectionalOrderedByListTest extends BaseEntityManagerFunctional
@Id @Id
private Long id; private Long id;
@OneToMany(cascade = CascadeType.ALL) @OneToMany(cascade = CascadeType.ALL)
@OrderBy("number") @OrderBy("number")
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::collections-unidirectional-ordered-list-order-by-example[]
public Person() { public Person() {
} }
@ -68,6 +73,7 @@ public class UnidirectionalOrderedByListTest extends BaseEntityManagerFunctional
public List<Phone> getPhones() { public List<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-unidirectional-ordered-list-order-by-example[]
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -81,6 +87,10 @@ public class UnidirectionalOrderedByListTest extends BaseEntityManagerFunctional
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-unidirectional-ordered-list-order-by-example[]
public Phone() { public Phone() {
} }
@ -101,6 +111,7 @@ public class UnidirectionalOrderedByListTest extends BaseEntityManagerFunctional
public String getNumber() { public String getNumber() {
return number; return number;
} }
//tag::collections-unidirectional-ordered-list-order-by-example[]
} }
//end::collections-unidirectional-ordered-list-order-by-example[] //end::collections-unidirectional-ordered-list-order-by-example[]
} }

View File

@ -64,9 +64,13 @@ public class UnidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
@Id @Id
private Long id; private Long id;
@OneToMany(cascade = CascadeType.ALL) @OneToMany(cascade = CascadeType.ALL)
private Set<Phone> phones = new HashSet<>(); private Set<Phone> phones = new HashSet<>();
//Getters and setters are omitted for brevity
//end::collections-unidirectional-set-example[]
public Person() { public Person() {
} }
@ -77,6 +81,7 @@ public class UnidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
public Set<Phone> getPhones() { public Set<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-unidirectional-set-example[]
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -91,6 +96,10 @@ public class UnidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-unidirectional-set-example[]
public Phone() { public Phone() {
} }
@ -112,6 +121,7 @@ public class UnidirectionalSetTest extends BaseEntityManagerFunctionalTestCase {
return number; return number;
} }
//tag::collections-unidirectional-set-example[]
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) { if ( this == o ) {

View File

@ -69,10 +69,15 @@ public class UnidirectionalSortedSetTest extends BaseEntityManagerFunctionalTest
@Id @Id
private Long id; private Long id;
@OneToMany(cascade = CascadeType.ALL) @OneToMany(cascade = CascadeType.ALL)
@SortNatural @SortNatural
private SortedSet<Phone> phones = new TreeSet<>(); private SortedSet<Phone> phones = new TreeSet<>();
//Getters and setters are omitted for brevity
//end::collections-unidirectional-sorted-set-natural-comparator-example[]
public Person() { public Person() {
} }
@ -83,6 +88,7 @@ public class UnidirectionalSortedSetTest extends BaseEntityManagerFunctionalTest
public Set<Phone> getPhones() { public Set<Phone> getPhones() {
return phones; return phones;
} }
//tag::collections-unidirectional-sorted-set-natural-comparator-example[]
} }
@Entity(name = "Phone") @Entity(name = "Phone")
@ -97,6 +103,10 @@ public class UnidirectionalSortedSetTest extends BaseEntityManagerFunctionalTest
@Column(name = "`number`") @Column(name = "`number`")
private String number; private String number;
//Getters and setters are omitted for brevity
//end::collections-unidirectional-sorted-set-natural-comparator-example[]
public Phone() { public Phone() {
} }
@ -118,6 +128,7 @@ public class UnidirectionalSortedSetTest extends BaseEntityManagerFunctionalTest
return number; return number;
} }
//tag::collections-unidirectional-sorted-set-natural-comparator-example[]
@Override @Override
public int compareTo(Phone o) { public int compareTo(Phone o) {
return number.compareTo( o.getNumber() ); return number.compareTo( o.getNumber() );

View File

@ -14,6 +14,10 @@ public abstract class BaseEntity {
private Timestamp updatedOn; private Timestamp updatedOn;
//Getters and setters are omitted for brevity
//end::events-default-listener-mapping-example[]
public Timestamp getCreatedOn() { public Timestamp getCreatedOn() {
return createdOn; return createdOn;
} }
@ -29,6 +33,7 @@ public abstract class BaseEntity {
void setUpdatedOn(Timestamp updatedOn) { void setUpdatedOn(Timestamp updatedOn) {
this.updatedOn = updatedOn; this.updatedOn = updatedOn;
} }
//tag::events-default-listener-mapping-example[]
} }
//end::events-default-listener-mapping-example[] //end::events-default-listener-mapping-example[]

View File

@ -79,7 +79,6 @@ public class DirectVsQueryFetchingTest extends BaseEntityManagerFunctionalTestCa
//Getters and setters omitted for brevity //Getters and setters omitted for brevity
} }
//tag::fetching-direct-vs-query-domain-model-example[]
@Entity(name = "Employee") @Entity(name = "Employee")
public static class Employee { public static class Employee {

View File

@ -174,6 +174,10 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
private String name; private String name;
//Getters and setters are omitted for brevity
//end::flushing-auto-flush-jpql-entity-example[]
public Person() {} public Person() {}
public Person(String name) { public Person(String name) {
@ -187,7 +191,7 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
public String getName() { public String getName() {
return name; return name;
} }
//tag::flushing-auto-flush-jpql-entity-example[]
} }
@Entity(name = "Advertisement") @Entity(name = "Advertisement")
@ -199,6 +203,10 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
private String title; private String title;
//Getters and setters are omitted for brevity
//end::flushing-auto-flush-jpql-entity-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -214,6 +222,7 @@ public class AutoFlushTest extends BaseEntityManagerFunctionalTestCase {
public void setTitle(String title) { public void setTitle(String title) {
this.title = title; this.title = title;
} }
//tag::flushing-auto-flush-jpql-entity-example[]
} }
//end::flushing-auto-flush-jpql-entity-example[] //end::flushing-auto-flush-jpql-entity-example[]
} }

View File

@ -120,6 +120,10 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-value-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -151,6 +155,7 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-single-table-discriminator-value-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -159,6 +164,10 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-value-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -166,6 +175,7 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-single-table-discriminator-value-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -174,6 +184,10 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-value-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -181,6 +195,7 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-single-table-discriminator-value-example[]
} }
@Entity(name = "OtherAccount") @Entity(name = "OtherAccount")
@ -189,6 +204,10 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
private boolean active; private boolean active;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-value-example[]
public boolean isActive() { public boolean isActive() {
return active; return active;
} }
@ -196,6 +215,7 @@ public class DiscriminatorNotNullSingleTableTest extends BaseEntityManagerFuncti
public void setActive(boolean active) { public void setActive(boolean active) {
this.active = active; this.active = active;
} }
//tag::entity-inheritance-single-table-discriminator-value-example[]
} }
//end::entity-inheritance-single-table-discriminator-value-example[] //end::entity-inheritance-single-table-discriminator-value-example[]
} }

View File

@ -74,6 +74,10 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-primary-key-join-column-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -105,6 +109,7 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-joined-table-primary-key-join-column-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -113,6 +118,10 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-primary-key-join-column-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -120,6 +129,7 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-joined-table-primary-key-join-column-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -128,6 +138,10 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-primary-key-join-column-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -135,6 +149,7 @@ public class JoinTablePrimaryKeyJoinColumnTest extends BaseEntityManagerFunction
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-joined-table-primary-key-join-column-example[]
} }
//end::entity-inheritance-joined-table-primary-key-join-column-example[] //end::entity-inheritance-joined-table-primary-key-join-column-example[]
} }

View File

@ -76,6 +76,10 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -107,6 +111,7 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-joined-table-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -114,6 +119,10 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -121,6 +130,7 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-joined-table-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -128,6 +138,10 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-joined-table-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -135,6 +149,7 @@ public class JoinTableTest extends BaseEntityManagerFunctionalTestCase {
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-joined-table-example[]
} }
//end::entity-inheritance-joined-table-example[] //end::entity-inheritance-joined-table-example[]
} }

View File

@ -65,6 +65,10 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-mapped-superclass-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -96,6 +100,7 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-mapped-superclass-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -103,6 +108,10 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-mapped-superclass-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -110,6 +119,7 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-mapped-superclass-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -117,6 +127,10 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-mapped-superclass-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -124,6 +138,7 @@ public class MappedSuperclassTest extends BaseEntityManagerFunctionalTestCase {
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-mapped-superclass-example[]
} }
//end::entity-inheritance-mapped-superclass-example[] //end::entity-inheritance-mapped-superclass-example[]
} }

View File

@ -90,6 +90,10 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-formula-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -121,6 +125,7 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-single-table-discriminator-formula-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -131,6 +136,10 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-formula-example[]
private DebitAccount() { private DebitAccount() {
} }
@ -149,6 +158,7 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-single-table-discriminator-formula-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -159,6 +169,10 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-discriminator-formula-example[]
private CreditAccount() { private CreditAccount() {
} }
@ -177,6 +191,7 @@ public class SingleTableDiscriminatorFormulaTest extends BaseEntityManagerFuncti
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-single-table-discriminator-formula-example[]
} }
//end::entity-inheritance-single-table-discriminator-formula-example[] //end::entity-inheritance-single-table-discriminator-formula-example[]
} }

View File

@ -78,6 +78,10 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -109,6 +113,7 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-single-table-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -116,6 +121,10 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -123,6 +132,7 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-single-table-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -130,6 +140,10 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-single-table-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -137,6 +151,7 @@ public class SingleTableTest extends BaseEntityManagerFunctionalTestCase {
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-single-table-example[]
} }
//end::entity-inheritance-single-table-example[] //end::entity-inheritance-single-table-example[]
} }

View File

@ -76,6 +76,10 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal interestRate; private BigDecimal interestRate;
//Getters and setters are omitted for brevity
//end::entity-inheritance-table-per-class-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -107,6 +111,7 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
public void setInterestRate(BigDecimal interestRate) { public void setInterestRate(BigDecimal interestRate) {
this.interestRate = interestRate; this.interestRate = interestRate;
} }
//tag::entity-inheritance-table-per-class-example[]
} }
@Entity(name = "DebitAccount") @Entity(name = "DebitAccount")
@ -114,6 +119,10 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal overdraftFee; private BigDecimal overdraftFee;
//Getters and setters are omitted for brevity
//end::entity-inheritance-table-per-class-example[]
public BigDecimal getOverdraftFee() { public BigDecimal getOverdraftFee() {
return overdraftFee; return overdraftFee;
} }
@ -121,6 +130,7 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
public void setOverdraftFee(BigDecimal overdraftFee) { public void setOverdraftFee(BigDecimal overdraftFee) {
this.overdraftFee = overdraftFee; this.overdraftFee = overdraftFee;
} }
//tag::entity-inheritance-table-per-class-example[]
} }
@Entity(name = "CreditAccount") @Entity(name = "CreditAccount")
@ -128,6 +138,10 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
private BigDecimal creditLimit; private BigDecimal creditLimit;
//Getters and setters are omitted for brevity
//end::entity-inheritance-table-per-class-example[]
public BigDecimal getCreditLimit() { public BigDecimal getCreditLimit() {
return creditLimit; return creditLimit;
} }
@ -135,6 +149,7 @@ public class TablePerClassTest extends BaseEntityManagerFunctionalTestCase {
public void setCreditLimit(BigDecimal creditLimit) { public void setCreditLimit(BigDecimal creditLimit) {
this.creditLimit = creditLimit; this.creditLimit = creditLimit;
} }
//tag::entity-inheritance-table-per-class-example[]
} }
//end::entity-inheritance-table-per-class-example[] //end::entity-inheritance-table-per-class-example[]
} }

View File

@ -66,6 +66,9 @@ public class BitSetTypeDefTest extends BaseCoreFunctionalTestCase {
private BitSet bitSet; private BitSet bitSet;
//Getters and setters are omitted for brevity
//end::basic-custom-type-BitSetTypeDef-mapping-example[]
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -81,6 +84,7 @@ public class BitSetTypeDefTest extends BaseCoreFunctionalTestCase {
public void setBitSet(BitSet bitSet) { public void setBitSet(BitSet bitSet) {
this.bitSet = bitSet; this.bitSet = bitSet;
} }
//tag::basic-custom-type-BitSetTypeDef-mapping-example[]
} }
//end::basic-custom-type-BitSetTypeDef-mapping-example[] //end::basic-custom-type-BitSetTypeDef-mapping-example[]
} }

View File

@ -76,6 +76,9 @@ public class BitSetTypeTest extends BaseCoreFunctionalTestCase {
return id; return id;
} }
//Getters and setters are omitted for brevity
//end::basic-custom-type-BitSetType-mapping-example[]
public void setId(Integer id) { public void setId(Integer id) {
this.id = id; this.id = id;
} }
@ -87,6 +90,7 @@ public class BitSetTypeTest extends BaseCoreFunctionalTestCase {
public void setBitSet(BitSet bitSet) { public void setBitSet(BitSet bitSet) {
this.bitSet = bitSet; this.bitSet = bitSet;
} }
//tag::basic-custom-type-BitSetType-mapping-example[]
} }
//end::basic-custom-type-BitSetType-mapping-example[] //end::basic-custom-type-BitSetType-mapping-example[]
} }

View File

@ -119,6 +119,8 @@ public class BitSetUserTypeTest extends BaseCoreFunctionalTestCase {
@Type( type = "bitset" ) @Type( type = "bitset" )
private BitSet bitSet; private BitSet bitSet;
//Constructors, getters and setters are omitted for brevity
//end::basic-custom-type-BitSetUserType-mapping-example[] //end::basic-custom-type-BitSetUserType-mapping-example[]
public Product() { public Product() {
} }
@ -127,7 +129,6 @@ public class BitSetUserTypeTest extends BaseCoreFunctionalTestCase {
this.id = id.intValue(); this.id = id.intValue();
this.bitSet = bitSet; this.bitSet = bitSet;
} }
//tag::basic-custom-type-BitSetUserType-mapping-example[]
public Integer getId() { public Integer getId() {
return id; return id;
@ -144,6 +145,7 @@ public class BitSetUserTypeTest extends BaseCoreFunctionalTestCase {
public void setBitSet(BitSet bitSet) { public void setBitSet(BitSet bitSet) {
this.bitSet = bitSet; this.bitSet = bitSet;
} }
//tag::basic-custom-type-BitSetUserType-mapping-example[]
} }
//end::basic-custom-type-BitSetUserType-mapping-example[] //end::basic-custom-type-BitSetUserType-mapping-example[]
} }

View File

@ -164,8 +164,11 @@ public class JoinColumnOrFormulaTest extends BaseEntityManagerFunctionalTestCase
this.country = country; this.country = country;
} }
//tag::mapping-JoinColumnOrFormula-example[] //tag::mapping-JoinColumnOrFormula-example[]
} }
//end::mapping-JoinColumnOrFormula-example[]
//tag::mapping-JoinColumnOrFormula-example[]
@Entity(name = "Country") @Entity(name = "Country")
@Table(name = "countries") @Table(name = "countries")
@ -181,6 +184,10 @@ public class JoinColumnOrFormulaTest extends BaseEntityManagerFunctionalTestCase
@Column(name = "is_default") @Column(name = "is_default")
private boolean _default; private boolean _default;
//Getters and setters, equals and hashCode methods omitted for brevity
//end::mapping-JoinColumnOrFormula-example[]
public int getId() { public int getId() {
return id; return id;
} }
@ -229,6 +236,7 @@ public class JoinColumnOrFormulaTest extends BaseEntityManagerFunctionalTestCase
public int hashCode() { public int hashCode() {
return Objects.hash( getId() ); return Objects.hash( getId() );
} }
//tag::mapping-JoinColumnOrFormula-example[]
} }
//end::mapping-JoinColumnOrFormula-example[] //end::mapping-JoinColumnOrFormula-example[]
} }

View File

@ -143,6 +143,9 @@ public class JoinFormulaTest extends BaseEntityManagerFunctionalTestCase {
//tag::mapping-JoinFormula-example[] //tag::mapping-JoinFormula-example[]
} }
//end::mapping-JoinFormula-example[]
//tag::mapping-JoinFormula-example[]
@Entity(name = "Country") @Entity(name = "Country")
@Table(name = "countries") @Table(name = "countries")
@ -153,6 +156,10 @@ public class JoinFormulaTest extends BaseEntityManagerFunctionalTestCase {
private String name; private String name;
//Getters and setters, equals and hashCode methods omitted for brevity
//end::mapping-JoinFormula-example[]
public int getId() { public int getId() {
return id; return id;
} }
@ -185,6 +192,7 @@ public class JoinFormulaTest extends BaseEntityManagerFunctionalTestCase {
public int hashCode() { public int hashCode() {
return Objects.hash( getId() ); return Objects.hash( getId() );
} }
//tag::mapping-JoinFormula-example[]
} }
//end::mapping-JoinFormula-example[] //end::mapping-JoinFormula-example[]
} }

View File

@ -70,6 +70,10 @@ public class ParentTest extends BaseEntityManagerFunctionalTestCase {
@Parent @Parent
private City city; private City city;
//Getters and setters omitted for brevity
//end::mapping-Parent-example[]
private GPS() { private GPS() {
} }
@ -93,7 +97,11 @@ public class ParentTest extends BaseEntityManagerFunctionalTestCase {
public void setCity(City city) { public void setCity(City city) {
this.city = city; this.city = city;
} }
//tag::mapping-Parent-example[]
} }
//end::mapping-Parent-example[]
//tag::mapping-Parent-example[]
@Entity(name = "City") @Entity(name = "City")
public static class City { public static class City {

View File

@ -54,6 +54,9 @@ public class MoneyConverterTest extends BaseEntityManagerFunctionalTestCase {
private long cents; private long cents;
//Getters and setters are omitted for brevity
//end::basic-jpa-convert-money-converter-mapping-example[]
public Money(long cents) { public Money(long cents) {
this.cents = cents; this.cents = cents;
} }
@ -65,23 +68,12 @@ public class MoneyConverterTest extends BaseEntityManagerFunctionalTestCase {
public void setCents(long cents) { public void setCents(long cents) {
this.cents = cents; this.cents = cents;
} }
//tag::basic-jpa-convert-money-converter-mapping-example[]
} }
//end::basic-jpa-convert-money-converter-mapping-example[]
public static class MoneyConverter
implements AttributeConverter<Money, Long> {
@Override
public Long convertToDatabaseColumn(Money attribute) {
return attribute == null ? null : attribute.getCents();
}
@Override
public Money convertToEntityAttribute(Long dbData) {
return dbData == null ? null : new Money( dbData );
}
}
//tag::basic-jpa-convert-money-converter-mapping-example[] //tag::basic-jpa-convert-money-converter-mapping-example[]
@Entity(name = "Account") @Entity(name = "Account")
public static class Account { public static class Account {
@ -94,8 +86,7 @@ public class MoneyConverterTest extends BaseEntityManagerFunctionalTestCase {
private Money balance; private Money balance;
//Getters and setters are omitted for brevity //Getters and setters are omitted for brevity
//end::basic-jpa-convert-money-converter-mapping-example[]
//end::basic-jpa-convert-money-converter-mapping-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -121,5 +112,19 @@ public class MoneyConverterTest extends BaseEntityManagerFunctionalTestCase {
} }
//tag::basic-jpa-convert-money-converter-mapping-example[] //tag::basic-jpa-convert-money-converter-mapping-example[]
} }
public static class MoneyConverter
implements AttributeConverter<Money, Long> {
@Override
public Long convertToDatabaseColumn(Money attribute) {
return attribute == null ? null : attribute.getCents();
}
@Override
public Money convertToEntityAttribute(Long dbData) {
return dbData == null ? null : new Money( dbData );
}
}
//end::basic-jpa-convert-money-converter-mapping-example[] //end::basic-jpa-convert-money-converter-mapping-example[]
} }

View File

@ -141,6 +141,9 @@ public class EmbeddableImplicitOverrideTest
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private Country country; private Country country;
//Getters and setters, equals and hashCode methods omitted for brevity
//end::embeddable-multiple-namingstrategy-entity-mapping[]
public Publisher(String name, Country country) { public Publisher(String name, Country country) {
this.name = name; this.name = name;
this.country = country; this.country = country;
@ -148,9 +151,6 @@ public class EmbeddableImplicitOverrideTest
private Publisher() {} private Publisher() {}
//Getters and setters are omitted for brevity
//end::embeddable-multiple-namingstrategy-entity-mapping[]
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -161,6 +161,10 @@ public class EmbeddableOverrideTest extends BaseEntityManagerFunctionalTestCase
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private Country country; private Country country;
//Getters and setters, equals and hashCode methods omitted for brevity
//end::embeddable-type-association-mapping-example[]
public Publisher(String name, Country country) { public Publisher(String name, Country country) {
this.name = name; this.name = name;
this.country = country; this.country = country;
@ -168,9 +172,6 @@ public class EmbeddableOverrideTest extends BaseEntityManagerFunctionalTestCase
private Publisher() {} private Publisher() {}
//Getters and setters are omitted for brevity
//end::embeddable-type-association-mapping-example[]
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -110,6 +110,11 @@ public class SimpleEmbeddableTest extends BaseEntityManagerFunctionalTestCase {
@Column(name = "publisher_country") @Column(name = "publisher_country")
private String country; private String country;
//Getters and setters, equals and hashCode methods omitted for brevity
//end::embeddable-type-mapping-example[]
public Publisher(String name, String country) { public Publisher(String name, String country) {
this.name = name; this.name = name;
this.country = country; this.country = country;
@ -117,9 +122,6 @@ public class SimpleEmbeddableTest extends BaseEntityManagerFunctionalTestCase {
private Publisher() {} private Publisher() {}
//Getters and setters are omitted for brevity
//end::embeddable-type-mapping-example[]
public String getName() { public String getName() {
return name; return name;
} }

View File

@ -53,6 +53,9 @@ public class CreationTimestampTest extends BaseEntityManagerFunctionalTestCase {
@CreationTimestamp @CreationTimestamp
private Date timestamp; private Date timestamp;
//Constructors, getters and setters are omitted for brevity
//end::mapping-generated-CreationTimestamp-example[]
public Event() {} public Event() {}
public Long getId() { public Long getId() {
@ -62,6 +65,7 @@ public class CreationTimestampTest extends BaseEntityManagerFunctionalTestCase {
public Date getTimestamp() { public Date getTimestamp() {
return timestamp; return timestamp;
} }
//tag::mapping-generated-CreationTimestamp-example[]
} }
//end::mapping-generated-CreationTimestamp-example[] //end::mapping-generated-CreationTimestamp-example[]
} }

View File

@ -56,6 +56,9 @@ public class DatabaseValueGenerationTest extends BaseEntityManagerFunctionalTest
@FunctionCreationTimestamp @FunctionCreationTimestamp
private Date timestamp; private Date timestamp;
//Constructors, getters and setters are omitted for brevity
//end::mapping-database-generated-value-example[]
public Event() {} public Event() {}
public Long getId() { public Long getId() {
@ -65,7 +68,11 @@ public class DatabaseValueGenerationTest extends BaseEntityManagerFunctionalTest
public Date getTimestamp() { public Date getTimestamp() {
return timestamp; return timestamp;
} }
//tag::mapping-database-generated-value-example[]
} }
//end::mapping-database-generated-value-example[]
//tag::mapping-database-generated-value-example[]
@ValueGenerationType(generatedBy = FunctionCreationValueGeneration.class) @ValueGenerationType(generatedBy = FunctionCreationValueGeneration.class)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -56,6 +56,8 @@ public class InMemoryValueGenerationTest extends BaseEntityManagerFunctionalTest
@FunctionCreationTimestamp @FunctionCreationTimestamp
private Date timestamp; private Date timestamp;
//Constructors, getters and setters are omitted for brevity
//end::mapping-in-memory-generated-value-example[]
public Event() {} public Event() {}
public Long getId() { public Long getId() {
@ -65,7 +67,11 @@ public class InMemoryValueGenerationTest extends BaseEntityManagerFunctionalTest
public Date getTimestamp() { public Date getTimestamp() {
return timestamp; return timestamp;
} }
//tag::mapping-in-memory-generated-value-example[]
} }
//end::mapping-in-memory-generated-value-example[]
//tag::mapping-in-memory-generated-value-example[]
@ValueGenerationType(generatedBy = FunctionCreationValueGeneration.class) @ValueGenerationType(generatedBy = FunctionCreationValueGeneration.class)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -88,6 +88,10 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
@LazyGroup( "lobs" ) @LazyGroup( "lobs" )
private Blob image; private Blob image;
//Getters and setters are omitted for brevity
//end::BytecodeEnhancement-lazy-loading-example[]
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -119,6 +123,7 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
public void setImage(Blob image) { public void setImage(Blob image) {
this.image = image; this.image = image;
} }
//tag::BytecodeEnhancement-lazy-loading-example[]
} }
//end::BytecodeEnhancement-lazy-loading-example[] //end::BytecodeEnhancement-lazy-loading-example[]
@ -132,7 +137,11 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
private String name; private String name;
@OneToMany(mappedBy = "author") @OneToMany(mappedBy = "author")
private List<Book> books = new ArrayList<>( ); private List<Book> books = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::BytecodeEnhancement-dirty-tracking-bidirectional-example[]
public Long getId() { public Long getId() {
return id; return id;
@ -153,6 +162,7 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
public List<Book> getBooks() { public List<Book> getBooks() {
return books; return books;
} }
//tag::BytecodeEnhancement-dirty-tracking-bidirectional-example[]
} }
@Entity(name = "Book") @Entity(name = "Book")
@ -169,6 +179,10 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
@ManyToOne @ManyToOne
private Person author; private Person author;
//Getters and setters are omitted for brevity
//end::BytecodeEnhancement-dirty-tracking-bidirectional-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -200,6 +214,7 @@ public class BytecodeEnhancementTest extends BaseEntityManagerFunctionalTestCase
public void setIsbn(String isbn) { public void setIsbn(String isbn) {
this.isbn = isbn; this.isbn = isbn;
} }
//tag::BytecodeEnhancement-dirty-tracking-bidirectional-example[]
} }
//end::BytecodeEnhancement-dirty-tracking-bidirectional-example[] //end::BytecodeEnhancement-dirty-tracking-bidirectional-example[]
} }

View File

@ -50,7 +50,7 @@ public class CascadeOnDeleteTest extends BaseEntityManagerFunctionalTestCase {
} ); } );
} }
//tag::pc-cascade-on-delete-mapping-example[] //tag::pc-cascade-on-delete-mapping-Person-example[]
@Entity(name = "Person") @Entity(name = "Person")
public static class Person { public static class Person {
@ -60,7 +60,8 @@ public class CascadeOnDeleteTest extends BaseEntityManagerFunctionalTestCase {
private String name; private String name;
//Getters and setters are omitted for brevity //Getters and setters are omitted for brevity
//end::pc-cascade-on-delete-mapping-example[]
//end::pc-cascade-on-delete-mapping-Person-example[]
public Long getId() { public Long getId() {
return id; return id;
@ -77,9 +78,11 @@ public class CascadeOnDeleteTest extends BaseEntityManagerFunctionalTestCase {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
//tag::pc-cascade-on-delete-mapping-example[] //tag::pc-cascade-on-delete-mapping-Person-example[]
} }
//end::pc-cascade-on-delete-mapping-Person-example[]
//tag::pc-cascade-on-delete-mapping-Phone-example[]
@Entity(name = "Phone") @Entity(name = "Phone")
public static class Phone { public static class Phone {
@ -94,7 +97,8 @@ public class CascadeOnDeleteTest extends BaseEntityManagerFunctionalTestCase {
private Person owner; private Person owner;
//Getters and setters are omitted for brevity //Getters and setters are omitted for brevity
//end::pc-cascade-on-delete-mapping-example[]
//end::pc-cascade-on-delete-mapping-Phone-example[]
public Long getId() { public Long getId() {
return id; return id;
@ -119,7 +123,7 @@ public class CascadeOnDeleteTest extends BaseEntityManagerFunctionalTestCase {
public void setOwner(Person owner) { public void setOwner(Person owner) {
this.owner = owner; this.owner = owner;
} }
//tag::pc-cascade-on-delete-mapping-example[] //tag::pc-cascade-on-delete-mapping-Phone-example[]
} }
//end::pc-cascade-on-delete-mapping-example[] //end::pc-cascade-on-delete-mapping-Phone-example[]
} }

View File

@ -418,6 +418,10 @@ public class PersistenceContextTest extends BaseEntityManagerFunctionalTestCase
@ManyToOne @ManyToOne
private Person author; private Person author;
//Getters and setters are omitted for brevity
//end::pc-find-by-natural-id-entity-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -449,6 +453,7 @@ public class PersistenceContextTest extends BaseEntityManagerFunctionalTestCase
public void setIsbn(String isbn) { public void setIsbn(String isbn) {
this.isbn = isbn; this.isbn = isbn;
} }
//tag::pc-find-by-natural-id-entity-example[]
} }
//end::pc-find-by-natural-id-entity-example[] //end::pc-find-by-natural-id-entity-example[]
} }

View File

@ -22,6 +22,9 @@ public class Person {
@OneToMany(mappedBy = "owner", cascade = CascadeType.ALL) @OneToMany(mappedBy = "owner", cascade = CascadeType.ALL)
private List<Phone> phones = new ArrayList<>(); private List<Phone> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::pc-cascade-domain-model-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -42,6 +45,8 @@ public class Person {
return phones; return phones;
} }
//tag::pc-cascade-domain-model-example[]
public void addPhone(Phone phone) { public void addPhone(Phone phone) {
this.phones.add( phone ); this.phones.add( phone );
phone.setOwner( this ); phone.setOwner( this );

View File

@ -22,6 +22,9 @@ public class Phone {
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
private Person owner; private Person owner;
//Getters and setters are omitted for brevity
//end::pc-cascade-domain-model-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -45,5 +48,6 @@ public class Phone {
public void setOwner(Person owner) { public void setOwner(Person owner) {
this.owner = owner; this.owner = owner;
} }
//tag::pc-cascade-domain-model-example[]
} }
//end::pc-cascade-domain-model-example[] //end::pc-cascade-domain-model-example[]

View File

@ -31,6 +31,7 @@ public class Author {
public Set<Book> books = new HashSet<>(); public Set<Book> books = new HashSet<>();
//Getters and setters omitted for brevity //Getters and setters omitted for brevity
//end::entity-persister-mapping[] //end::entity-persister-mapping[]
public Integer getId() { public Integer getId() {

View File

@ -91,6 +91,10 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
@LazyGroup( "lobs" ) @LazyGroup( "lobs" )
private Blob image; private Blob image;
//Getters and setters are omitted for brevity
//end::schema-generation-domain-model-example[]
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -122,6 +126,7 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
public void setImage(Blob image) { public void setImage(Blob image) {
this.image = image; this.image = image;
} }
//tag::schema-generation-domain-model-example[]
} }
@Entity(name = "Person") @Entity(name = "Person")
@ -133,7 +138,11 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
private String name; private String name;
@OneToMany(mappedBy = "author") @OneToMany(mappedBy = "author")
private List<Book> books = new ArrayList<>( ); private List<Book> books = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::schema-generation-domain-model-example[]
public Long getId() { public Long getId() {
return id; return id;
@ -154,6 +163,7 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
public List<Book> getBooks() { public List<Book> getBooks() {
return books; return books;
} }
//tag::schema-generation-domain-model-example[]
} }
@Entity(name = "Book") @Entity(name = "Book")
@ -170,6 +180,10 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
@ManyToOne @ManyToOne
private Person author; private Person author;
//Getters and setters are omitted for brevity
//end::schema-generation-domain-model-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -201,6 +215,7 @@ public class SchemaGenerationTest extends BaseEntityManagerFunctionalTestCase {
public void setIsbn(String isbn) { public void setIsbn(String isbn) {
this.isbn = isbn; this.isbn = isbn;
} }
//tag::schema-generation-domain-model-example[]
} }
//end::schema-generation-domain-model-example[] //end::schema-generation-domain-model-example[]
} }

View File

@ -21,6 +21,10 @@ public class Captain {
@EmbeddedId @EmbeddedId
private Identity id; private Identity id;
//Getters and setters are omitted for brevity
//end::sql-composite-key-entity-associations_named-query-example[]
public Identity getId() { public Identity getId() {
return id; return id;
} }
@ -28,5 +32,6 @@ public class Captain {
public void setId(Identity id) { public void setId(Identity id) {
this.id = id; this.id = id;
} }
//tag::sql-composite-key-entity-associations_named-query-example[]
} }
//end::sql-composite-key-entity-associations_named-query-example[] //end::sql-composite-key-entity-associations_named-query-example[]

View File

@ -43,122 +43,127 @@ import static org.junit.Assert.assertNull;
@RequiresDialect(PostgreSQL82Dialect.class) @RequiresDialect(PostgreSQL82Dialect.class)
public class CustomSQLSecondaryTableTest extends BaseEntityManagerFunctionalTestCase { public class CustomSQLSecondaryTableTest extends BaseEntityManagerFunctionalTestCase {
@Override @Override
protected Class<?>[] getAnnotatedClasses() { protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { return new Class<?>[] {
Person.class Person.class
}; };
} }
@Before @Before
public void init() { public void init() {
doInJPA( this::entityManagerFactory, entityManager -> { doInJPA( this::entityManagerFactory, entityManager -> {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
session.doWork( connection -> { session.doWork( connection -> {
try(Statement statement = connection.createStatement(); ) { try(Statement statement = connection.createStatement(); ) {
statement.executeUpdate( "ALTER TABLE person ADD COLUMN valid boolean" ); statement.executeUpdate( "ALTER TABLE person ADD COLUMN valid boolean" );
statement.executeUpdate( "ALTER TABLE person_details ADD COLUMN valid boolean" ); statement.executeUpdate( "ALTER TABLE person_details ADD COLUMN valid boolean" );
} }
} ); } );
}); });
} }
@Test @Test
public void test_sql_custom_crud() { public void test_sql_custom_crud() {
Person _person = doInJPA( this::entityManagerFactory, entityManager -> { Person _person = doInJPA( this::entityManagerFactory, entityManager -> {
Person person = new Person(); Person person = new Person();
person.setName( "John Doe" ); person.setName( "John Doe" );
entityManager.persist( person ); entityManager.persist( person );
person.setImage( new byte[] {1, 2, 3} ); person.setImage( new byte[] {1, 2, 3} );
return person; return person;
} ); } );
doInJPA( this::entityManagerFactory, entityManager -> { doInJPA( this::entityManagerFactory, entityManager -> {
Long postId = _person.getId(); Long postId = _person.getId();
Person person = entityManager.find( Person.class, postId ); Person person = entityManager.find( Person.class, postId );
assertArrayEquals(new byte[] {1, 2, 3}, person.getImage()); assertArrayEquals(new byte[] {1, 2, 3}, person.getImage());
entityManager.remove( person ); entityManager.remove( person );
} ); } );
doInJPA( this::entityManagerFactory, entityManager -> { doInJPA( this::entityManagerFactory, entityManager -> {
Long postId = _person.getId(); Long postId = _person.getId();
Person person = entityManager.find( Person.class, postId ); Person person = entityManager.find( Person.class, postId );
assertNull(person); assertNull(person);
} ); } );
} }
//tag::sql-custom-crud-secondary-table-example[] //tag::sql-custom-crud-secondary-table-example[]
@Entity(name = "Person") @Entity(name = "Person")
@Table(name = "person") @Table(name = "person")
@SQLInsert( @SQLInsert(
sql = "INSERT INTO person (name, id, valid) VALUES (?, ?, true) " sql = "INSERT INTO person (name, id, valid) VALUES (?, ?, true) "
) )
@SQLDelete( @SQLDelete(
sql = "UPDATE person SET valid = false WHERE id = ? " sql = "UPDATE person SET valid = false WHERE id = ? "
) )
@SecondaryTable(name = "person_details", @SecondaryTable(name = "person_details",
pkJoinColumns = @PrimaryKeyJoinColumn(name = "person_id")) pkJoinColumns = @PrimaryKeyJoinColumn(name = "person_id"))
@org.hibernate.annotations.Table( @org.hibernate.annotations.Table(
appliesTo = "person_details", appliesTo = "person_details",
sqlInsert = @SQLInsert( sqlInsert = @SQLInsert(
sql = "INSERT INTO person_details (image, person_id, valid) VALUES (?, ?, true) ", sql = "INSERT INTO person_details (image, person_id, valid) VALUES (?, ?, true) ",
check = ResultCheckStyle.COUNT check = ResultCheckStyle.COUNT
), ),
sqlDelete = @SQLDelete( sqlDelete = @SQLDelete(
sql = "UPDATE person_details SET valid = false WHERE person_id = ? " sql = "UPDATE person_details SET valid = false WHERE person_id = ? "
) )
) )
@Loader(namedQuery = "find_valid_person") @Loader(namedQuery = "find_valid_person")
@NamedNativeQueries({ @NamedNativeQueries({
@NamedNativeQuery( @NamedNativeQuery(
name = "find_valid_person", name = "find_valid_person",
query = "select " + query = "SELECT " +
" p.id, " + " p.id, " +
" p.name, " + " p.name, " +
" pd.image " + " pd.image " +
"from person p " + "FROM person p " +
"left outer join person_details pd on p.id = pd.person_id " + "LEFT OUTER JOIN person_details pd ON p.id = pd.person_id " +
"where p.id = ? and p.valid = true and pd.valid = true", "WHERE p.id = ? AND p.valid = true AND pd.valid = true",
resultClass = Person.class resultClass = Person.class
) )
}) })
public static class Person { public static class Person {
@Id @Id
@GeneratedValue @GeneratedValue
private Long id; private Long id;
private String name; private String name;
@Column(name = "image", table = "person_details") @Column(name = "image", table = "person_details")
private byte[] image; private byte[] image;
public Long getId() { //Getters and setters are omitted for brevity
return id;
}
public void setId(Long id) { //end::sql-custom-crud-secondary-table-example[]
this.id = id;
}
public String getName() { public Long getId() {
return name; return id;
} }
public void setName(String name) { public void setId(Long id) {
this.name = name; this.id = id;
} }
public byte[] getImage() { public String getName() {
return image; return name;
} }
public void setImage(byte[] image) { public void setName(String name) {
this.image = image; this.name = name;
} }
}
//end::sql-custom-crud-secondary-table-example[] public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
//tag::sql-custom-crud-secondary-table-example[]
}
//end::sql-custom-crud-secondary-table-example[]
} }

View File

@ -99,7 +99,6 @@ public class CustomSQLTest extends BaseEntityManagerFunctionalTestCase {
} ); } );
} }
//tag::sql-custom-crud-example[] //tag::sql-custom-crud-example[]
@Entity(name = "Person") @Entity(name = "Person")
@SQLInsert( @SQLInsert(
@ -107,9 +106,11 @@ public class CustomSQLTest extends BaseEntityManagerFunctionalTestCase {
check = ResultCheckStyle.COUNT check = ResultCheckStyle.COUNT
) )
@SQLUpdate( @SQLUpdate(
sql = "UPDATE person SET name = ? where id = ? ") sql = "UPDATE person SET name = ? where id = ? "
)
@SQLDelete( @SQLDelete(
sql = "UPDATE person SET valid = false WHERE id = ? ") sql = "UPDATE person SET valid = false WHERE id = ? "
)
@Loader(namedQuery = "find_valid_person") @Loader(namedQuery = "find_valid_person")
@NamedNativeQueries({ @NamedNativeQueries({
@NamedNativeQuery( @NamedNativeQuery(
@ -136,6 +137,10 @@ public class CustomSQLTest extends BaseEntityManagerFunctionalTestCase {
@Where( clause = "valid = true" ) @Where( clause = "valid = true" )
private List<String> phones = new ArrayList<>(); private List<String> phones = new ArrayList<>();
//Getters and setters are omitted for brevity
//end::sql-custom-crud-example[]
public Long getId() { public Long getId() {
return id; return id;
} }
@ -155,7 +160,7 @@ public class CustomSQLTest extends BaseEntityManagerFunctionalTestCase {
public List<String> getPhones() { public List<String> getPhones() {
return phones; return phones;
} }
//tag::sql-custom-crud-example[]
} }
//end::sql-custom-crud-example[] //end::sql-custom-crud-example[]
} }

View File

@ -21,6 +21,10 @@ public class Dimensions {
private int width; private int width;
//Getters and setters are omitted for brevity
//end::sql-composite-key-entity-associations_named-query-example[]
public int getLength() { public int getLength() {
return length; return length;
} }
@ -36,5 +40,6 @@ public class Dimensions {
public void setWidth(int width) { public void setWidth(int width) {
this.width = width; this.width = width;
} }
//tag::sql-composite-key-entity-associations_named-query-example[]
} }
//end::sql-composite-key-entity-associations_named-query-example[] //end::sql-composite-key-entity-associations_named-query-example[]

View File

@ -22,6 +22,10 @@ public class Identity implements Serializable {
private String lastname; private String lastname;
//Getters and setters are omitted for brevity
//end::sql-composite-key-entity-associations_named-query-example[]
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
@ -38,6 +42,7 @@ public class Identity implements Serializable {
this.lastname = lastname; this.lastname = lastname;
} }
//tag::sql-composite-key-entity-associations_named-query-example[]
public boolean equals(Object o) { public boolean equals(Object o) {
if ( this == o ) return true; if ( this == o ) return true;
if ( o == null || getClass() != o.getClass() ) return false; if ( o == null || getClass() != o.getClass() ) return false;

View File

@ -16,6 +16,8 @@ public class PersonSummaryDTO {
private String name; private String name;
//Getters and setters are omitted for brevity
public Number getId() { public Number getId() {
return id; return id;
} }

View File

@ -495,10 +495,10 @@ public class SQLTest extends BaseEntityManagerFunctionalTestCase {
Session session = entityManager.unwrap( Session.class ); Session session = entityManager.unwrap( Session.class );
//tag::sql-hibernate-multi-entity-query-example[] //tag::sql-hibernate-multi-entity-query-example[]
List<Object> entities = session.createNativeQuery( List<Object> entities = session.createNativeQuery(
"SELECT * " + "SELECT * " +
"FROM Person pr, Partner pt " + "FROM Person pr, Partner pt " +
"WHERE pr.name = pt.name" ) "WHERE pr.name = pt.name" )
.list(); .list();
//end::sql-hibernate-multi-entity-query-example[] //end::sql-hibernate-multi-entity-query-example[]
assertEquals( 2, entities.size() ); assertEquals( 2, entities.size() );
} ); } );

View File

@ -81,6 +81,10 @@ public class SpaceShip {
private Dimensions dimensions; private Dimensions dimensions;
//Getters and setters are omitted for brevity
//end::sql-composite-key-entity-associations_named-query-example[]
public String getName() { public String getName() {
return name; return name;
} }
@ -120,5 +124,6 @@ public class SpaceShip {
public void setDimensions(Dimensions dimensions) { public void setDimensions(Dimensions dimensions) {
this.dimensions = dimensions; this.dimensions = dimensions;
} }
//tag::sql-composite-key-entity-associations_named-query-example[]
} }
//end::sql-composite-key-entity-associations_named-query-example[] //end::sql-composite-key-entity-associations_named-query-example[]

View File

@ -127,6 +127,10 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest
private boolean employed; private boolean employed;
//Getters and setters are omitted for brevity
//end::batch-bulk-hql-temp-table-base-class-example[]
public Integer getId() { public Integer getId() {
return id; return id;
} }
@ -176,6 +180,7 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest
public int hashCode() { public int hashCode() {
return Objects.hash( getId(), getCompanyName() ); return Objects.hash( getId(), getCompanyName() );
} }
//tag::batch-bulk-hql-temp-table-base-class-example[]
} }
//end::batch-bulk-hql-temp-table-base-class-example[] //end::batch-bulk-hql-temp-table-base-class-example[]
@ -189,6 +194,10 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest
private boolean fellow; private boolean fellow;
//Getters and setters are omitted for brevity
//end::batch-bulk-hql-temp-table-sub-classes-example[]
public boolean isFellow() { public boolean isFellow() {
return fellow; return fellow;
} }
@ -196,6 +205,7 @@ public abstract class AbstractBulkCompositeIdTest extends BaseCoreFunctionalTest
public void setFellow(boolean fellow) { public void setFellow(boolean fellow) {
this.fellow = fellow; this.fellow = fellow;
} }
//tag::batch-bulk-hql-temp-table-sub-classes-example[]
} }
//end::batch-bulk-hql-temp-table-sub-classes-example[] //end::batch-bulk-hql-temp-table-sub-classes-example[]
} }