Hi
I have 2 classes Contact and Address. The following shows snippets of code for both classes:
Contact.java
Code:
@ContainedIn
@OneToMany(targetEntity=com.amin.phonebook.domain.Address.class, cascade = { CascadeType.ALL}, fetch=FetchType.EAGER)
@Type(type="java.util.Set")
private Set<Address> addresses;
Address.java
Code:
has address1, address2,
@ManyToOne
@JoinColumn(name="C_CONTACT_ID")
@IndexedEmbedded
private Contact contact;
I have some code to perform searching on Address
Code:
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery( query, Contact.class );
Using the following fields:
Code:
"addresses.address1", "addresses.address2", "addresses.town", "addresses.county", "addresses.country",
"addresses.postcode",
I'm not sure if this is a problem or perhaps i am doing it incorrectly. When i ran my test case using the above snippets of code i was not getting any results (for example i was trying to search on address1). I have set up Contact according to the documentation. However when i looked at sample test cases (hibernate search distribution) i noticed collections had @IndexEmbedded instead of @ContainedIn. So i updtaed my code to the following:
Code:
@ContainedIn
@OneToMany(targetEntity=com.amin.phonebook.domain.Address.class, cascade = { CascadeType.ALL}, fetch=FetchType.EAGER)
@IndexedEmbedded
@Type(type="java.util.Set")
private Set<Address> addresses;
And then when I ran my test case it worked. I was wondering if someone could tell me whether i use just @IndexEmbedded or @ContainedIn for querying collections. Obviously @IndexEmbedded worked but I am not sure if this is the correct approach. Any help would be appreciated.