-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate search- Spatial embedded query
PostPosted: Sat Sep 20, 2014 2:50 am 
Newbie

Joined: Tue Jul 26, 2011 6:46 pm
Posts: 11
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.