-->
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: How to access Sort Field name of Foreign Key in entity using
PostPosted: Thu Jul 21, 2016 6:03 am 
Newbie

Joined: Thu Jul 21, 2016 5:00 am
Posts: 1
There are two entities and first entity is referred into second entity.

Entity 1:

Code:
   public class Yesh implements Serializable {
      
      private static final long serialVersionUID = 1L;
      @Id
      @Basic(optional = false)
      @Column(name = "ID")
      private Long id;

      @Fields({ @Field(index = Index.YES, store = Store.NO), @Field(name = "YeshName_for_sort", index = Index.YES, analyzer = @Analyzer(definition = "customanalyzer")) })
      @Column(name = "NAME", length = 100)
      private String name;

      public Yesh () {
      }

      public Yesh (Long id) {
         this.id = id;
      }

      public Yesh (Long id) {
         this.id = id;

      }

      public Long getId() {
         return id;
      }

      public void setId(Long id) {
         this.id = id;
      }



      public String getName() {
         return name;
      }

      public void setName(String name) {
         this.name = name;
      }


      @Override
      public String toString() {
         return "com.Prac.Yesh[ id=" + id + " ]";
      }

      }



Entity 2:

public class Kash implements Serializable {
Code:
      
      private static final long serialVersionUID = 1L;
      
      @Id
      @Basic(optional = false)
      @Column(name = "ID")
      private Long id;
      
        @IndexedEmbedded
        @ManyToOne
      Yesh yes; //Contain reference to first entity

      public Long getId() {
         return id;
      }

      public void setId(Long id) {
         this.id = id;
      }


         public Yesh getYes() {
         return yes;
      }

      public void setId(Yesh yes) {
         this.yes = yes;
      }
      }


There is no annotation in Entity 2 on reference Yesh; Entity 1 have field annotated with name "YeshName_for_sort". But when i try to access above field as given in following example:

Main Class:

Code:
    FullTextEntityManager ftem =    Search.getFullTextEntityManager(factory.createEntityManager());
     QueryBuilder qb = ftem.getSearchFactory().buildQueryBuilder().forEntity( Kash.class ).get();
     org.apache.lucene.search.Query query = qb.all().getQuery();
     FullTextQuery fullTextQuery = ftem.createFullTextQuery(query, Kash.class);
 
     //fullTextQuery.setSort(new Sort(new SortField("YeshName_for_sort", SortField.STRING, true)));
      The above statement is not working and i have also tried to replace YeshName_for_sort with 'yes' reference but it is not working.
 
     fullTextQuery.setFirstResult(0).setMaxResults(150);
     int size = fullTextQuery.getResultSize();
      List<Yesh> result = fullTextQuery.getResultList();
      for (Yeshuser : result) {
       logger.info("Yesh Name:" + user.getName());
       }


Sorting does not work. I also tried to change statements like:
Code:
        ftem.createFullTextQuery(query, Kash.class, Yesh.class); //added entity 1


or

Code:
    fullTextQuery.setSort(new Sort(new SortField("yes.name", SortField.STRING, true))); // Added property name for Yesh yes;



but it is not working.

What annotations need to be implemented in entities or any changes in main program to access the field for sorting?


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.