have two classes. User and Address.
User:
Code:
@Indexed
@Entity
@Table(name = "USERS")
public class USER {
@DocumentId
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "userSeq")
@TableGenerator(name = "userSeq", table = "SEQUENCES", pkColumnName = "SEQ_NAME", valueColumnName = "NEXT_VALUE", pkColumnValue = "USER_SEQ", initialValue = 1, allocationSize = 1)
private Long id;
@Field
@Column(name = "NAME", length = 255)
private String name;
@IndexedEmbedded(depth = 1)
@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.EAGER)
@JoinColumn(name = "ADDRESS_ID")
private Address address;
}
Address:
Code:
@Indexed
@Entity
@Spatial
@Table(name = "ADDRESSES")
public class Address {
@DocumentId
@Id
@Column(name = "ID")
@GeneratedValue(strategy = GenerationType.TABLE, generator = "addSeq")
@TableGenerator(name = "addtSeq", table = "SEQUENCES", pkColumnName = "SEQ_NAME", valueColumnName = "NEXT_VALUE", pkColumnValue = "ADD_SEQ", initialValue = 1, allocationSize = 1)
private Long id;
@Field
@Column(name = "NAME", length = 255)
private String name;
@Latitude
@Column(name = "LAT")
private Double latitude;
@Longitude
@Column(name = "LON")
private Double longitude;
@OneToMany(mappedBy = "address", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<User> users;
}
I can get results for direct Address query as follows:
Code:
FullTextSession fullTextSession = Search.getFullTextSession(session);
QueryBuilder builder = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(Address.class).get();
org.apache.lucene.search.Query luceneQuery = builder.spatial()
.onDefaultCoordinates().within(radius, Unit.KM).ofLatitude(lat)
.andLongitude(lon).createQuery();
Transaction tx = session.beginTransaction();
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(
luceneQuery, Address.class);
hibQuery.list();
But when I try same query replacing Address.class with User.class, it does not return me any results. As the indexes are embedded, my understanding is I should be getting it directly or do I need to change anything?