I have an object model where I have an abstract superclass called Recipient which is extended by concrete subclasses called Customer and Contact. Recipient contains an entity called Address, and as a result, Customer and Contact both contain Address. Customer also contains a collection of Contacts.
Here is some code to help clarify:
Code:
@MappedSuperclass
public abstract class Recipient {
private Address address;
@ManyToOne(fetch= FetchType.LAZY, cascade= CascadeType.PERSIST)
@JoinColumn(name = "ADDRESS_ID", nullable = false)
@IndexedEmbedded
public Address getAddress() {
return address;
}
public void setAddress(Address address) {
this.address = address;
}
}
----------------------------
@Entity
@Table(name = "ADDRESS")
@Indexed
public class Address {
.
.
.
}
----------------------------
@Entity
@Table(name = "CONTACT")
@Indexed
public class Contact extends Recipient {
.
.
.
}
----------------------------
@Entity
@Table(name = "CUSTOMER")
@Indexed
public class Customer extends Recipient {
.
.
.
@OneToMany(fetch= FetchType.LAZY, cascade= CascadeType.PERSIST)
@JoinColumn(name = "CUSTOMER_ID", nullable = false)
@IndexedEmbedded
public List<Contact> getContacts() {
return contacts;
}
public void setContacts(List<Contact> contacts) {
this.contacts = contacts;
}
.
.
.
}
As you can see, both Customer and Contact inherit an Address from Recipient, and Customer has a collection of Contacts.
The problem is that I cannot access the Contact's Address from the Customer. In other words, the mapping as I have it now does not allow me to make a query like
contacts.address.city:Philadelphia from the Customer index. Yet I can still access other Contact items inherited from Recipient like phoneNumber, and I can certainly access the Customer's own address through
address.city.
Please let me know how I need to alter my mappings to generate the indexes for Address from the Contact level.
Thanks.