Loading ...
Sorry, an error occurred while loading the content.

Re: [riojug] Busca Indexada

Expand Messages
  • Victor Hogemann
    Anderson, Você re-indexou suas entidades? Toda vez que você muda o mapeamento os índices são criados novamente, e você precisa re-indexar as entidades que
    Message 1 of 21 , Oct 2, 2009
    • 0 Attachment
      Anderson,

      Você re-indexou suas entidades? Toda vez que você muda o mapeamento os índices são criados novamente, e você precisa re-indexar as entidades que já existiam... senão vai ficar com o índice vazio. Segue um exemplo de como fazer:

          public void refreshIndex(final Class entityClass) {

              this.getHibernateTemplate().execute(new HibernateCallback() {


                  public Object doInHibernate(Session session) throws HibernateException, SQLException {

                      FullTextSession fullTextSession = Search.getFullTextSession(session);

                      Criteria crit = session.createCriteria(entityClass);

                      for (Object obj : crit.list()) {

                          T entity = (T) obj;

                          fullTextSession.index(entity);

                      }

                      return null;


                  }

              });

          }


      [ ]s

      2009/10/2 Anderson Moraes <amoraes@...>
       

      Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo vou
      mostrar o SQL que sai no console:



      try{

      final Session session =
      HibernateUtil.getSessionFactory().openSession();
      final FullTextSession ftSession =
      Search.getFullTextSession(session);
      final List<Video> videos =
      session.createCriteria(Video.class).list();


      for(Video v : videos) {
      ftSession.index(v);
      }


      final String[] stopWords =
      {"de","do","da","dos","das","a","o","na","no","em"};
      final MultiFieldQueryParser parser = new
      MultiFieldQueryParser(new
      String[]{"Video.assinante.nome","Video.description"} , new
      StopAnalyzer(stopWords));
      final Query query = parser.parse("Moraes");
      final FullTextQuery fullTextQuery =
      ftSession.createFullTextQuery(query, Video.class);

      final List<Video> list = fullTextQuery.list();


      HibernateUtil.getSessionFactory().close();


      if (list==null || list.size()==0){
      System.out.println("Nenhum Vídeo encontrado.");
      }else{
      for (Video v : list) {

      System.out.println(" " + v.getTitle());
      }
      }

      }catch(Exception e){
      e.printStackTrace();
      }
      }


      CONSOLE:
      Hibernate:

      select
      this_.NR_ID_VIDEO_PK as NR1_1_1_,
      this_.NR_ID_ASSINANTE as NR4_1_1_,
      this_.DT_DATE_UPLOAD as DT2_1_1_,
      this_.VC_DESCRIPTION as VC3_1_1_,
      this_.VC_PATH_IMAGE as VC5_1_1_,
      this_.VC_REAL_PATH as VC6_1_1_,
      this_.VC_TITLE as VC7_1_1_,
      this_.VC_URL as VC8_1_1_,
      assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
      assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
      assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
      assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
      assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
      assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
      assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
      assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
      assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
      from
      TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
      this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE

      OBS.: Existem 4 Assinantes com o sobre nome Moraes.

      On Fri, 2 Oct 2009 15:40:15 -0300

      Victor Hogemann <victor.hogemann@...> wrote:
      > Anderson,
      > Você precisa remover o @IndexedEmbedded da lista de vídeos do
      >Assinante:
      >
      > @ContainedIn
      > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
      > @Cascade(CascadeType.ALL)
      > @IndexedEmbedded
      > private List<Video> Videos;
      >
      >
      > [ ]s
      >
      > 2009/10/2 Anderson Moraes <amoraes@...>
      >
      >>
      >>
      >> Não consegui acertar meu método, segue as minhas Classes:
      >>
      >> ASSINANTE:
      >> @Entity
      >> @Table(name = "TBL_ASSINANTE")
      >> @Indexed
      >> public class Assinante extends PersistentObject implements
      >> Serializable{
      >>
      >> @Id
      >> @GeneratedValue(strategy = GenerationType.IDENTITY)
      >> @Column(name="NR_ID_ASSINANTE")
      >> private Long id;
      >> @Column(name="VC_EMAIL_ASSINANTE")
      >> private String email;
      >> @Column(name="VC_PASSWORD_ASSINANTE")
      >> private String password;
      >> @Field(index=Index.TOKENIZED, store=Store.YES)
      >> @Column(name="VC_NOME_ASSINANTE")
      >> private String nome;
      >> @Column(name="VC_CPF_ASSINANTE")
      >> private String cpf;
      >> @Column(name="VC_ENDERECO_ASSINANTE")
      >> private String endereco;
      >> @Column(name="VC_CIDADE_ASSINANTE")
      >> private String cidade;
      >> @Column(name="VC_ESTADO_ASSINANTE")
      >> private String estado;
      >> @Column(name="DT_DATA_CAD_ASSINANTE")
      >> private String dataCadastro;
      >>
      >> @ContainedIn
      >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
      >> @Cascade(CascadeType.ALL)
      >> @IndexedEmbedded
      >> private List<Video> Videos;
      >>
      >> VÍDEO:
      >> @Entity
      >> @Table(name = "TBL_VIDEO")
      >> @Indexed
      >> public class Video implements Serializable{
      >>
      >> @Id
      >> @GeneratedValue(strategy = GenerationType.IDENTITY)
      >> @Column(name="NR_ID_VIDEO_PK")
      >> private Long id;
      >> @Column(name="VC_TITLE")
      >> @Field(index=Index.TOKENIZED, store=Store.YES)
      >> private String title;
      >> @Column(name="VC_DESCRIPTION")
      >> @Field(index=Index.TOKENIZED, store=Store.YES)
      >> private String description;
      >> @Column(name="VC_URL")
      >> private String url;
      >> @Column(name="VC_REAL_PATH")
      >> private String realPath;
      >> @Column(name="NR_ID_ASSINANTE")
      >> private Long idAssinante;
      >> @Column(name="DT_DATE_UPLOAD")
      >> private String dataUpload;
      >> @Column(name="VC_PATH_IMAGE")
      >> private String pathImage;
      >>
      >> @IndexedEmbedded
      >> @OneToOne(fetch=FetchType.EAGER)
      >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
      >> updatable=false)
      >> @Fetch(FetchMode.JOIN)
      >> @Cascade(CascadeType.SAVE_UPDATE)
      >> private Assinante assinante;
      >>
      >> Deu erro:
      >> Caused by: org.hibernate.search.SearchException: Circular reference.
      >> Duplicate use of esseecraque.bean.Video in root entity
      >> esseecraque.bean.Video#assinante.Videos.
      >>
      >>
      >> On Fri, 2 Oct 2009 14:01:29 -0300
      >> Victor Hogemann <victor.hogemann@...
      >><victor.hogemann%40gmail.com>>

      >> wrote:
      >> > Anderson,
      >> > A forma mais fácil de fazer isso é criar uma associação
      >> >bi-direcional entre
      >> > Assinante e Video, assim você pode a partir do Video filtrar pelo
      >> >nome do
      >> > assinante usando somente uma query Lucene... Por exemplo:
      >> >
      >> > TermQuery query = new TermQuery(new Term("Video.assinante.nome",
      >> >"Fulano"));
      >> >FullTextQuery fullTextQuery =
      >> > fullTextSession.createFullTextQuery(query, Video.class);
      >> > return fullTextQuery.list();
      >> >
      >> >
      >> > Pelo que você escreveu a associação entre Assinante e Vídeo é
      >> >one-to-many,
      >> > então não vai ser uma mudança tão traumática assim no código. O
      >> >pulo-do-gato
      >> > é que você vai ter que repetir os dados de Assinante no indice de
      >> >Vídeo,
      >> > utilizando as annotations @IndexedEmbended e @ContainedIn.
      >> >
      >> > Em Vídeo você vai ter:
      >> >
      >> > @IndexedEmbeded
      >> > @OneToOne
      >> > Assinante assinante;
      >> >
      >> >
      >> > E em Assinante vai ficar:
      >> >
      >> > @ContainedIn
      >> > @OneToMany
      >> > List<Video> videos;
      >> >
      >> >
      >> > Eu escrevi um pequeno tutorial de hibernate-search, que
      >>basicamente
      >> >é um
      >> > resumo traduzido da referência em inglês do hibernate search. No
      >> >exemplo que
      >> > está lá tem um exemplo de como fazer busca em entidades
      >>associadas:
      >> >
      >> > http://victor.hogemann.eti.br/2009/06/hibernate-search.html
      >> >
      >> >
      >> > Espero ter ajudado, boa sorte!
      >> >
      >> > 2009/10/2 Anderson Moraes
      >><amoraes@...<amoraes%40tecmetal.com.br>

      >> >
      >> >
      >> >>
      >> >>
      >> >> Pessoal, bom dia.
      >> >>
      >> >> Vou explicar o que estou fazendo por parte, primeiro vou
      >>descrever
      >> >>os
      >> >> atributos da minha bean:
      >> >>
      >> >> BEAN Assinante:
      >> >> id
      >> >> nome
      >> >> Videos (Uma Coleção de Vídeo - private Collection<Video> Videos;)
      >> >>
      >> >> BEAN Video:
      >> >> id
      >> >> title
      >> >> description
      >> >> idAssinante
      >> >>
      >> >> Blz, até aí tudo bem.
      >> >> Aí eu uso o método abaixo para realizar uma busca nas duas
      >>classes
      >> >> (tabelas), sendo que em Assinante eu busco no atributo "nome" e
      >>em
      >> >> Video eu busco nos atributos "title" e "description", segue o
      >>método
      >> >> abaixou:
      >> >>
      >> >> ************** MÉTODO ********************
      >> >> try{
      >> >>
      >> >> final Session session =
      >> >> HibernateUtil.getSessionFactory().openSession();
      >> >> final FullTextSession ftSession =
      >> >> Search.getFullTextSession(session);
      >> >> final List<Assinante> assinantes =
      >> >> session.createCriteria(Assinante.class).list();
      >> >> final List<Video> videos =
      >> >> session.createCriteria(Video.class).list();
      >> >>
      >> >> for(Assinante a : assinantes) {
      >> >> ftSession.index(a);
      >> >> }
      >> >>
      >> >> for(Video v : videos) {
      >> >> ftSession.index(v);
      >> >> }
      >> >>
      >> >> final String[] stopWords =
      >> >> {"de","do","da","dos","das","a","o","na","no","em"};
      >> >> final MultiFieldQueryParser parser = new
      >>MultiFieldQueryParser(new
      >> >> String[]{"nome","Videos.description"} , new
      >> >>StopAnalyzer(stopWords));
      >> >> final Query query = parser.parse("Moraes Flamengo");
      >> >> final FullTextQuery fullTextQuery =
      >> >> ftSession.createFullTextQuery(query, Assinante.class);
      >> >> final List<Assinante> list = fullTextQuery.list();
      >> >> HibernateUtil.getSessionFactory().close();
      >> >>
      >> >>
      >> >> }catch(Exception e){
      >> >> e.printStackTrace();
      >> >> }
      >> >>
      >> >> ************** FIM MÉTODO ********************
      >> >>
      >> >> Ele funciona perfeitamente, repare na linha que eu vou destacar
      >> >>abaixo
      >> >> que eu informo em que campos procurar:
      >> >>
      >> >> final MultiFieldQueryParser parser = new
      >>MultiFieldQueryParser(new
      >> >> String[]{"nome","Videos.title","Videos.description"} , new
      >> >> StopAnalyzer(stopWords));
      >> >>
      >> >> Então, se eu fizer conforme abaixo:
      >> >>
      >> >> if (list==null || list.size()==0){
      >> >> System.out.println("Nenhum Vídeo encontrado.");
      >> >> }else{
      >> >> for(Assinante a : list) {
      >> >> System.out.println(a.getNome());
      >> >> for (Video v : a.getVideos()) {
      >> >> System.out.println(" " + v.getTitle());
      >> >> }
      >> >> }
      >> >> }
      >> >>
      >> >> Ele me lista o Nome do Assinante e seus Vídeos.
      >> >> Ex.:
      >> >> Anderson Moraes
      >> >> Vídeo 1
      >> >> Vídeo 4
      >> >> Vídeo 9
      >> >> Elba Ramalho
      >> >> Vídeo 3
      >> >> Vídeo 7
      >> >> Raul Seixas
      >> >> Zé Ramalho
      >> >> Vídeo 2
      >> >>
      >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso do exemplo
      >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem Assinante.
      >> >>
      >> >> Blz, agora vamos ao que eu quero.
      >> >>
      >> >> Eu quero recuperar dessa busca um List somente dos vídeos
      >> >> (List<Video>), independente do Assinante, o Assinante eu uso só
      >>para
      >> >> buscar pelo nome, por exemplo:
      >> >> Se eu buscar por "Ramalho", o meu list<Video> será preenchido com
      >>os
      >> >> vídeos de Elba Ramalho e Zé Ramalho.
      >> >>
      >> >> Esse List de Vídeos eu vou jogar na sessão para recuperar pelo
      >> >> Iterate, conforme exemplo abaixo:
      >> >>
      >> >> Na minha Action:
      >> >>
      >> >> request.setAttribute("Busca_Videos", listVideos);
      >> >>
      >> >> No meu JSP:
      >> >>
      >> >> <logic:notEmpty name="Busca_Videos">
      >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
      >> >> <bean:write name="resulBusca" property="title" />
      >> >> <bean:write name="resulBusca" property="description" />
      >> >> </logic:iterate>
      >> >> </logic:notEmpty>
      >> >> <logic:empty name="Busca_Video">
      >> >> <b>Nenhum vídeo encontrado.</b>
      >> >> </logic:empty>
      >> >>
      >> >> O meu problema é que eu não estou sabendo recuperar em cima da
      >>busca
      >> >> que eu fiz um LIST só de Vídeos.
      >> >>
      >> >> Alguém pode me ajudar com isso???
      >> >>
      >> >> Grato desde já,
      >> >>
      >> >> Anderson Moraes
      >> >>
      >> >>
      >> >
      >> >
      >> >
      >> > --
      >> > Victor Guilherme Hogemann
      >> > http://victor.hogemann.eti.br
      >>
      >>
      >>
      >
      >
      >
      > --
      > Victor Guilherme Hogemann
      > http://victor.hogemann.eti.br




      --
      Victor Guilherme Hogemann
      http://victor.hogemann.eti.br
    • Anderson Moraes
      Não entendi como eu executo essa classe, em que momento... On Fri, 2 Oct 2009 16:50:33 -0300
      Message 2 of 21 , Oct 2, 2009
      • 0 Attachment
        Não entendi como eu executo essa classe, em que momento...

        On Fri, 2 Oct 2009 16:50:33 -0300
        Victor Hogemann <victor.hogemann@...> wrote:
        > Anderson,
        > Você re-indexou suas entidades? Toda vez que você muda o mapeamento
        >os
        > índices são criados novamente, e você precisa re-indexar as
        >entidades que já
        > existiam... senão vai ficar com o índice vazio. Segue um exemplo de
        >como
        > fazer:
        >
        > public void refreshIndex(final Class entityClass) {
        >
        > this.getHibernateTemplate().execute(new HibernateCallback() {
        >
        >
        > public Object doInHibernate(Session session)
        > throwsHibernateException, SQLException {
        >
        > FullTextSession fullTextSession =
        > Search.getFullTextSession(session);
        >
        > Criteria crit = session.createCriteria(entityClass);
        >
        > for (Object obj : crit.list()) {
        >
        > T entity = (T) obj;
        >
        > fullTextSession.index(entity);
        >
        > }
        >
        > return null;
        >
        >
        > }
        >
        > });
        >
        > }
        >
        >
        > [ ]s
        >
        > 2009/10/2 Anderson Moraes <amoraes@...>
        >
        >>
        >>
        >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo vou
        >> mostrar o SQL que sai no console:
        >>
        >>
        >> try{
        >>
        >> final Session session =
        >> HibernateUtil.getSessionFactory().openSession();
        >> final FullTextSession ftSession =
        >> Search.getFullTextSession(session);
        >> final List<Video> videos =
        >> session.createCriteria(Video.class).list();
        >>
        >>
        >> for(Video v : videos) {
        >> ftSession.index(v);
        >> }
        >>
        >>
        >> final String[] stopWords =
        >> {"de","do","da","dos","das","a","o","na","no","em"};
        >> final MultiFieldQueryParser parser = new
        >> MultiFieldQueryParser(new
        >> String[]{"Video.assinante.nome","Video.description"} , new
        >> StopAnalyzer(stopWords));
        >> final Query query = parser.parse("Moraes");
        >> final FullTextQuery fullTextQuery =
        >> ftSession.createFullTextQuery(query, Video.class);
        >>
        >> final List<Video> list = fullTextQuery.list();
        >>
        >>
        >> HibernateUtil.getSessionFactory().close();
        >>
        >>
        >> if (list==null || list.size()==0){
        >> System.out.println("Nenhum Vídeo encontrado.");
        >> }else{
        >> for (Video v : list) {
        >> System.out.println(" " + v.getTitle());
        >> }
        >> }
        >>
        >> }catch(Exception e){
        >> e.printStackTrace();
        >> }
        >> }
        >>
        >>
        >> CONSOLE:
        >> Hibernate:
        >>
        >> select
        >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
        >> this_.NR_ID_ASSINANTE as NR4_1_1_,
        >> this_.DT_DATE_UPLOAD as DT2_1_1_,
        >> this_.VC_DESCRIPTION as VC3_1_1_,
        >> this_.VC_PATH_IMAGE as VC5_1_1_,
        >> this_.VC_REAL_PATH as VC6_1_1_,
        >> this_.VC_TITLE as VC7_1_1_,
        >> this_.VC_URL as VC8_1_1_,
        >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
        >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
        >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
        >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
        >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
        >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
        >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
        >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
        >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
        >> from
        >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
        >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
        >>
        >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
        >>
        >> On Fri, 2 Oct 2009 15:40:15 -0300
        >>
        >> Victor Hogemann <victor.hogemann@...
        >><victor.hogemann%40gmail.com>>
        >> wrote:
        >> > Anderson,
        >> > Você precisa remover o @IndexedEmbedded da lista de vídeos do
        >> >Assinante:
        >> >
        >> > @ContainedIn
        >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
        >> > @Cascade(CascadeType.ALL)
        >> > @IndexedEmbedded
        >> > private List<Video> Videos;
        >> >
        >> >
        >> > [ ]s
        >> >
        >> > 2009/10/2 Anderson Moraes
        >><amoraes@...<amoraes%40tecmetal.com.br>
        >> >
        >> >
        >> >>
        >> >>
        >> >> Não consegui acertar meu método, segue as minhas Classes:
        >> >>
        >> >> ASSINANTE:
        >> >> @Entity
        >> >> @Table(name = "TBL_ASSINANTE")
        >> >> @Indexed
        >> >> public class Assinante extends PersistentObject implements
        >> >> Serializable{
        >> >>
        >> >> @Id
        >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
        >> >> @Column(name="NR_ID_ASSINANTE")
        >> >> private Long id;
        >> >> @Column(name="VC_EMAIL_ASSINANTE")
        >> >> private String email;
        >> >> @Column(name="VC_PASSWORD_ASSINANTE")
        >> >> private String password;
        >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
        >> >> @Column(name="VC_NOME_ASSINANTE")
        >> >> private String nome;
        >> >> @Column(name="VC_CPF_ASSINANTE")
        >> >> private String cpf;
        >> >> @Column(name="VC_ENDERECO_ASSINANTE")
        >> >> private String endereco;
        >> >> @Column(name="VC_CIDADE_ASSINANTE")
        >> >> private String cidade;
        >> >> @Column(name="VC_ESTADO_ASSINANTE")
        >> >> private String estado;
        >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
        >> >> private String dataCadastro;
        >> >>
        >> >> @ContainedIn
        >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
        >> >> @Cascade(CascadeType.ALL)
        >> >> @IndexedEmbedded
        >> >> private List<Video> Videos;
        >> >>
        >> >> VÍDEO:
        >> >> @Entity
        >> >> @Table(name = "TBL_VIDEO")
        >> >> @Indexed
        >> >> public class Video implements Serializable{
        >> >>
        >> >> @Id
        >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
        >> >> @Column(name="NR_ID_VIDEO_PK")
        >> >> private Long id;
        >> >> @Column(name="VC_TITLE")
        >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
        >> >> private String title;
        >> >> @Column(name="VC_DESCRIPTION")
        >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
        >> >> private String description;
        >> >> @Column(name="VC_URL")
        >> >> private String url;
        >> >> @Column(name="VC_REAL_PATH")
        >> >> private String realPath;
        >> >> @Column(name="NR_ID_ASSINANTE")
        >> >> private Long idAssinante;
        >> >> @Column(name="DT_DATE_UPLOAD")
        >> >> private String dataUpload;
        >> >> @Column(name="VC_PATH_IMAGE")
        >> >> private String pathImage;
        >> >>
        >> >> @IndexedEmbedded
        >> >> @OneToOne(fetch=FetchType.EAGER)
        >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
        >> >> updatable=false)
        >> >> @Fetch(FetchMode.JOIN)
        >> >> @Cascade(CascadeType.SAVE_UPDATE)
        >> >> private Assinante assinante;
        >> >>
        >> >> Deu erro:
        >> >> Caused by: org.hibernate.search.SearchException: Circular
        >>reference.
        >> >> Duplicate use of esseecraque.bean.Video in root entity
        >> >> esseecraque.bean.Video#assinante.Videos.
        >> >>
        >> >>
        >> >> On Fri, 2 Oct 2009 14:01:29 -0300
        >> >> Victor Hogemann
        >><victor.hogemann@...<victor.hogemann%40gmail.com>
        >> >><victor.hogemann%40gmail.com>>
        >>
        >> >> wrote:
        >> >> > Anderson,
        >> >> > A forma mais fácil de fazer isso é criar uma associação
        >> >> >bi-direcional entre
        >> >> > Assinante e Video, assim você pode a partir do Video filtrar
        >>pelo
        >> >> >nome do
        >> >> > assinante usando somente uma query Lucene... Por exemplo:
        >> >> >
        >> >> > TermQuery query = new TermQuery(new
        >>Term("Video.assinante.nome",
        >> >> >"Fulano"));
        >> >> >FullTextQuery fullTextQuery =
        >> >> > fullTextSession.createFullTextQuery(query, Video.class);
        >> >> > return fullTextQuery.list();
        >> >> >
        >> >> >
        >> >> > Pelo que você escreveu a associação entre Assinante e Vídeo é
        >> >> >one-to-many,
        >> >> > então não vai ser uma mudança tão traumática assim no código. O
        >> >> >pulo-do-gato
        >> >> > é que você vai ter que repetir os dados de Assinante no indice
        >>de
        >> >> >Vídeo,
        >> >> > utilizando as annotations @IndexedEmbended e @ContainedIn.
        >> >> >
        >> >> > Em Vídeo você vai ter:
        >> >> >
        >> >> > @IndexedEmbeded
        >> >> > @OneToOne
        >> >> > Assinante assinante;
        >> >> >
        >> >> >
        >> >> > E em Assinante vai ficar:
        >> >> >
        >> >> > @ContainedIn
        >> >> > @OneToMany
        >> >> > List<Video> videos;
        >> >> >
        >> >> >
        >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
        >> >>basicamente
        >> >> >é um
        >> >> > resumo traduzido da referência em inglês do hibernate search.
        >>No
        >> >> >exemplo que
        >> >> > está lá tem um exemplo de como fazer busca em entidades
        >> >>associadas:
        >> >> >
        >> >> > http://victor.hogemann.eti.br/2009/06/hibernate-search.html
        >> >> >
        >> >> >
        >> >> > Espero ter ajudado, boa sorte!
        >> >> >
        >> >> > 2009/10/2 Anderson Moraes
        >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
        >> 40tecmetal.com.br>
        >>
        >> >> >
        >> >> >
        >> >> >>
        >> >> >>
        >> >> >> Pessoal, bom dia.
        >> >> >>
        >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
        >> >>descrever
        >> >> >>os
        >> >> >> atributos da minha bean:
        >> >> >>
        >> >> >> BEAN Assinante:
        >> >> >> id
        >> >> >> nome
        >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
        >>Videos;)
        >> >> >>
        >> >> >> BEAN Video:
        >> >> >> id
        >> >> >> title
        >> >> >> description
        >> >> >> idAssinante
        >> >> >>
        >> >> >> Blz, até aí tudo bem.
        >> >> >> Aí eu uso o método abaixo para realizar uma busca nas duas
        >> >>classes
        >> >> >> (tabelas), sendo que em Assinante eu busco no atributo "nome"
        >>e
        >> >>em
        >> >> >> Video eu busco nos atributos "title" e "description", segue o
        >> >>método
        >> >> >> abaixou:
        >> >> >>
        >> >> >> ************** MÉTODO ********************
        >> >> >> try{
        >> >> >>
        >> >> >> final Session session =
        >> >> >> HibernateUtil.getSessionFactory().openSession();
        >> >> >> final FullTextSession ftSession =
        >> >> >> Search.getFullTextSession(session);
        >> >> >> final List<Assinante> assinantes =
        >> >> >> session.createCriteria(Assinante.class).list();
        >> >> >> final List<Video> videos =
        >> >> >> session.createCriteria(Video.class).list();
        >> >> >>
        >> >> >> for(Assinante a : assinantes) {
        >> >> >> ftSession.index(a);
        >> >> >> }
        >> >> >>
        >> >> >> for(Video v : videos) {
        >> >> >> ftSession.index(v);
        >> >> >> }
        >> >> >>
        >> >> >> final String[] stopWords =
        >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
        >> >> >> final MultiFieldQueryParser parser = new
        >> >>MultiFieldQueryParser(new
        >> >> >> String[]{"nome","Videos.description"} , new
        >> >> >>StopAnalyzer(stopWords));
        >> >> >> final Query query = parser.parse("Moraes Flamengo");
        >> >> >> final FullTextQuery fullTextQuery =
        >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
        >> >> >> final List<Assinante> list = fullTextQuery.list();
        >> >> >> HibernateUtil.getSessionFactory().close();
        >> >> >>
        >> >> >>
        >> >> >> }catch(Exception e){
        >> >> >> e.printStackTrace();
        >> >> >> }
        >> >> >>
        >> >> >> ************** FIM MÉTODO ********************
        >> >> >>
        >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
        >>destacar
        >> >> >>abaixo
        >> >> >> que eu informo em que campos procurar:
        >> >> >>
        >> >> >> final MultiFieldQueryParser parser = new
        >> >>MultiFieldQueryParser(new
        >> >> >> String[]{"nome","Videos.title","Videos.description"} , new
        >> >> >> StopAnalyzer(stopWords));
        >> >> >>
        >> >> >> Então, se eu fizer conforme abaixo:
        >> >> >>
        >> >> >> if (list==null || list.size()==0){
        >> >> >> System.out.println("Nenhum Vídeo encontrado.");
        >> >> >> }else{
        >> >> >> for(Assinante a : list) {
        >> >> >> System.out.println(a.getNome());
        >> >> >> for (Video v : a.getVideos()) {
        >> >> >> System.out.println(" " + v.getTitle());
        >> >> >> }
        >> >> >> }
        >> >> >> }
        >> >> >>
        >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
        >> >> >> Ex.:
        >> >> >> Anderson Moraes
        >> >> >> Vídeo 1
        >> >> >> Vídeo 4
        >> >> >> Vídeo 9
        >> >> >> Elba Ramalho
        >> >> >> Vídeo 3
        >> >> >> Vídeo 7
        >> >> >> Raul Seixas
        >> >> >> Zé Ramalho
        >> >> >> Vídeo 2
        >> >> >>
        >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso do
        >>exemplo
        >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem Assinante.
        >> >> >>
        >> >> >> Blz, agora vamos ao que eu quero.
        >> >> >>
        >> >> >> Eu quero recuperar dessa busca um List somente dos vídeos
        >> >> >> (List<Video>), independente do Assinante, o Assinante eu uso
        >>só
        >> >>para
        >> >> >> buscar pelo nome, por exemplo:
        >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será preenchido
        >>com
        >> >>os
        >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
        >> >> >>
        >> >> >> Esse List de Vídeos eu vou jogar na sessão para recuperar pelo
        >> >> >> Iterate, conforme exemplo abaixo:
        >> >> >>
        >> >> >> Na minha Action:
        >> >> >>
        >> >> >> request.setAttribute("Busca_Videos", listVideos);
        >> >> >>
        >> >> >> No meu JSP:
        >> >> >>
        >> >> >> <logic:notEmpty name="Busca_Videos">
        >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
        >> >> >> <bean:write name="resulBusca" property="title" />
        >> >> >> <bean:write name="resulBusca" property="description" />
        >> >> >> </logic:iterate>
        >> >> >> </logic:notEmpty>
        >> >> >> <logic:empty name="Busca_Video">
        >> >> >> <b>Nenhum vídeo encontrado.</b>
        >> >> >> </logic:empty>
        >> >> >>
        >> >> >> O meu problema é que eu não estou sabendo recuperar em cima da
        >> >>busca
        >> >> >> que eu fiz um LIST só de Vídeos.
        >> >> >>
        >> >> >> Alguém pode me ajudar com isso???
        >> >> >>
        >> >> >> Grato desde já,
        >> >> >>
        >> >> >> Anderson Moraes
        >> >> >>
        >> >> >>
        >> >> >
        >> >> >
        >> >> >
        >> >> > --
        >> >> > Victor Guilherme Hogemann
        >> >> > http://victor.hogemann.eti.br
        >> >>
        >> >>
        >> >>
        >> >
        >> >
        >> >
        >> > --
        >> > Victor Guilherme Hogemann
        >> > http://victor.hogemann.eti.br
        >>
        >>
        >>
        >
        >
        >
        > --
        > Victor Guilherme Hogemann
        > http://victor.hogemann.eti.br
      • Victor Hogemann
        Anderson, Imagine a seguinte situação... Sua aplicação está funcionando, e de repente alguma coisa sai errada e o seu servidor capota. Beleza, você tem o
        Message 3 of 21 , Oct 2, 2009
        • 0 Attachment
          Anderson,

          Imagine a seguinte situação... Sua aplicação está funcionando, e de repente alguma coisa sai errada e o seu servidor capota. Beleza, você tem o backup do seu banco de dados, mas e os índices do Hibernate Search?

          Claro, você poderia fazer backup desses também... mas imagine que não tenha feito. Você vai precisar reconstruir seus índices a partir das entidades persistidas no banco, pra isso serve o método que eu te passei.

          Como você alterou o mapeamento das entidades no Hibernate Search, logo mudou a estrutura do índice, e aí é necessário re-indexar tudo novamente.

          Sacou?

          2009/10/2 Anderson Moraes <amoraes@...>
           

          Não entendi como eu executo essa classe, em que momento...

          On Fri, 2 Oct 2009 16:50:33 -0300


          Victor Hogemann <victor.hogemann@...> wrote:
          > Anderson,
          > Você re-indexou suas entidades? Toda vez que você muda o mapeamento
          >os
          > índices são criados novamente, e você precisa re-indexar as
          >entidades que já
          > existiam... senão vai ficar com o índice vazio. Segue um exemplo de
          >como
          > fazer:
          >
          > public void refreshIndex(final Class entityClass) {
          >
          > this.getHibernateTemplate().execute(new HibernateCallback() {
          >
          >
          > public Object doInHibernate(Session session)
          > throwsHibernateException, SQLException {

          >
          > FullTextSession fullTextSession =
          > Search.getFullTextSession(session);
          >
          > Criteria crit = session.createCriteria(entityClass);
          >
          > for (Object obj : crit.list()) {
          >
          > T entity = (T) obj;
          >
          > fullTextSession.index(entity);
          >
          > }
          >
          > return null;
          >
          >
          > }
          >
          > });
          >
          > }
          >
          >
          > [ ]s
          >
          > 2009/10/2 Anderson Moraes <amoraes@...>
          >
          >>
          >>
          >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo vou
          >> mostrar o SQL que sai no console:
          >>
          >>
          >> try{
          >>
          >> final Session session =
          >> HibernateUtil.getSessionFactory().openSession();
          >> final FullTextSession ftSession =
          >> Search.getFullTextSession(session);
          >> final List<Video> videos =
          >> session.createCriteria(Video.class).list();
          >>
          >>
          >> for(Video v : videos) {
          >> ftSession.index(v);
          >> }
          >>
          >>
          >> final String[] stopWords =
          >> {"de","do","da","dos","das","a","o","na","no","em"};
          >> final MultiFieldQueryParser parser = new
          >> MultiFieldQueryParser(new
          >> String[]{"Video.assinante.nome","Video.description"} , new
          >> StopAnalyzer(stopWords));
          >> final Query query = parser.parse("Moraes");
          >> final FullTextQuery fullTextQuery =
          >> ftSession.createFullTextQuery(query, Video.class);
          >>
          >> final List<Video> list = fullTextQuery.list();
          >>
          >>
          >> HibernateUtil.getSessionFactory().close();
          >>
          >>
          >> if (list==null || list.size()==0){
          >> System.out.println("Nenhum Vídeo encontrado.");
          >> }else{
          >> for (Video v : list) {
          >> System.out.println(" " + v.getTitle());
          >> }
          >> }
          >>
          >> }catch(Exception e){
          >> e.printStackTrace();
          >> }
          >> }
          >>
          >>
          >> CONSOLE:
          >> Hibernate:
          >>
          >> select
          >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
          >> this_.NR_ID_ASSINANTE as NR4_1_1_,
          >> this_.DT_DATE_UPLOAD as DT2_1_1_,
          >> this_.VC_DESCRIPTION as VC3_1_1_,
          >> this_.VC_PATH_IMAGE as VC5_1_1_,
          >> this_.VC_REAL_PATH as VC6_1_1_,
          >> this_.VC_TITLE as VC7_1_1_,
          >> this_.VC_URL as VC8_1_1_,
          >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
          >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
          >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
          >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
          >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
          >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
          >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
          >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
          >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
          >> from
          >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
          >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
          >>
          >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
          >>
          >> On Fri, 2 Oct 2009 15:40:15 -0300
          >>
          >> Victor Hogemann <victor.hogemann@...
          >><victor.hogemann%40gmail.com>>
          >> wrote:
          >> > Anderson,
          >> > Você precisa remover o @IndexedEmbedded da lista de vídeos do
          >> >Assinante:
          >> >
          >> > @ContainedIn
          >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
          >> > @Cascade(CascadeType.ALL)
          >> > @IndexedEmbedded
          >> > private List<Video> Videos;
          >> >
          >> >
          >> > [ ]s
          >> >
          >> > 2009/10/2 Anderson Moraes
          >><amoraes@...<amoraes%40tecmetal.com.br>

          >> >
          >> >
          >> >>
          >> >>
          >> >> Não consegui acertar meu método, segue as minhas Classes:
          >> >>
          >> >> ASSINANTE:
          >> >> @Entity
          >> >> @Table(name = "TBL_ASSINANTE")
          >> >> @Indexed
          >> >> public class Assinante extends PersistentObject implements
          >> >> Serializable{
          >> >>
          >> >> @Id
          >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
          >> >> @Column(name="NR_ID_ASSINANTE")
          >> >> private Long id;
          >> >> @Column(name="VC_EMAIL_ASSINANTE")
          >> >> private String email;
          >> >> @Column(name="VC_PASSWORD_ASSINANTE")
          >> >> private String password;
          >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
          >> >> @Column(name="VC_NOME_ASSINANTE")
          >> >> private String nome;
          >> >> @Column(name="VC_CPF_ASSINANTE")
          >> >> private String cpf;
          >> >> @Column(name="VC_ENDERECO_ASSINANTE")
          >> >> private String endereco;
          >> >> @Column(name="VC_CIDADE_ASSINANTE")
          >> >> private String cidade;
          >> >> @Column(name="VC_ESTADO_ASSINANTE")
          >> >> private String estado;
          >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
          >> >> private String dataCadastro;
          >> >>
          >> >> @ContainedIn
          >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
          >> >> @Cascade(CascadeType.ALL)
          >> >> @IndexedEmbedded
          >> >> private List<Video> Videos;
          >> >>
          >> >> VÍDEO:
          >> >> @Entity
          >> >> @Table(name = "TBL_VIDEO")
          >> >> @Indexed
          >> >> public class Video implements Serializable{
          >> >>
          >> >> @Id
          >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
          >> >> @Column(name="NR_ID_VIDEO_PK")
          >> >> private Long id;
          >> >> @Column(name="VC_TITLE")
          >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
          >> >> private String title;
          >> >> @Column(name="VC_DESCRIPTION")
          >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
          >> >> private String description;
          >> >> @Column(name="VC_URL")
          >> >> private String url;
          >> >> @Column(name="VC_REAL_PATH")
          >> >> private String realPath;
          >> >> @Column(name="NR_ID_ASSINANTE")
          >> >> private Long idAssinante;
          >> >> @Column(name="DT_DATE_UPLOAD")
          >> >> private String dataUpload;
          >> >> @Column(name="VC_PATH_IMAGE")
          >> >> private String pathImage;
          >> >>
          >> >> @IndexedEmbedded
          >> >> @OneToOne(fetch=FetchType.EAGER)
          >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
          >> >> updatable=false)
          >> >> @Fetch(FetchMode.JOIN)
          >> >> @Cascade(CascadeType.SAVE_UPDATE)
          >> >> private Assinante assinante;
          >> >>
          >> >> Deu erro:
          >> >> Caused by: org.hibernate.search.SearchException: Circular
          >>reference.
          >> >> Duplicate use of esseecraque.bean.Video in root entity
          >> >> esseecraque.bean.Video#assinante.Videos.
          >> >>
          >> >>
          >> >> On Fri, 2 Oct 2009 14:01:29 -0300
          >> >> Victor Hogemann
          >><victor.hogemann@...<victor.hogemann%40gmail.com>
          >> >><victor.hogemann%40gmail.com>>
          >>
          >> >> wrote:
          >> >> > Anderson,
          >> >> > A forma mais fácil de fazer isso é criar uma associação
          >> >> >bi-direcional entre
          >> >> > Assinante e Video, assim você pode a partir do Video filtrar
          >>pelo
          >> >> >nome do
          >> >> > assinante usando somente uma query Lucene... Por exemplo:
          >> >> >
          >> >> > TermQuery query = new TermQuery(new
          >>Term("Video.assinante.nome",
          >> >> >"Fulano"));
          >> >> >FullTextQuery fullTextQuery =
          >> >> > fullTextSession.createFullTextQuery(query, Video.class);
          >> >> > return fullTextQuery.list();
          >> >> >
          >> >> >
          >> >> > Pelo que você escreveu a associação entre Assinante e Vídeo é
          >> >> >one-to-many,
          >> >> > então não vai ser uma mudança tão traumática assim no código. O
          >> >> >pulo-do-gato
          >> >> > é que você vai ter que repetir os dados de Assinante no indice
          >>de
          >> >> >Vídeo,
          >> >> > utilizando as annotations @IndexedEmbended e @ContainedIn.
          >> >> >
          >> >> > Em Vídeo você vai ter:
          >> >> >
          >> >> > @IndexedEmbeded
          >> >> > @OneToOne
          >> >> > Assinante assinante;
          >> >> >
          >> >> >
          >> >> > E em Assinante vai ficar:
          >> >> >
          >> >> > @ContainedIn
          >> >> > @OneToMany
          >> >> > List<Video> videos;
          >> >> >
          >> >> >
          >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
          >> >>basicamente
          >> >> >é um
          >> >> > resumo traduzido da referência em inglês do hibernate search.
          >>No
          >> >> >exemplo que
          >> >> > está lá tem um exemplo de como fazer busca em entidades
          >> >>associadas:
          >> >> >
          >> >> > http://victor.hogemann.eti.br/2009/06/hibernate-search.html
          >> >> >
          >> >> >
          >> >> > Espero ter ajudado, boa sorte!
          >> >> >
          >> >> > 2009/10/2 Anderson Moraes
          >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

          >> 40tecmetal.com.br>
          >>
          >> >> >
          >> >> >
          >> >> >>
          >> >> >>
          >> >> >> Pessoal, bom dia.
          >> >> >>
          >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
          >> >>descrever
          >> >> >>os
          >> >> >> atributos da minha bean:
          >> >> >>
          >> >> >> BEAN Assinante:
          >> >> >> id
          >> >> >> nome
          >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
          >>Videos;)
          >> >> >>
          >> >> >> BEAN Video:
          >> >> >> id
          >> >> >> title
          >> >> >> description
          >> >> >> idAssinante
          >> >> >>
          >> >> >> Blz, até aí tudo bem.
          >> >> >> Aí eu uso o método abaixo para realizar uma busca nas duas
          >> >>classes
          >> >> >> (tabelas), sendo que em Assinante eu busco no atributo "nome"
          >>e
          >> >>em
          >> >> >> Video eu busco nos atributos "title" e "description", segue o
          >> >>método
          >> >> >> abaixou:
          >> >> >>
          >> >> >> ************** MÉTODO ********************
          >> >> >> try{
          >> >> >>
          >> >> >> final Session session =
          >> >> >> HibernateUtil.getSessionFactory().openSession();
          >> >> >> final FullTextSession ftSession =
          >> >> >> Search.getFullTextSession(session);
          >> >> >> final List<Assinante> assinantes =
          >> >> >> session.createCriteria(Assinante.class).list();
          >> >> >> final List<Video> videos =
          >> >> >> session.createCriteria(Video.class).list();
          >> >> >>
          >> >> >> for(Assinante a : assinantes) {
          >> >> >> ftSession.index(a);
          >> >> >> }
          >> >> >>
          >> >> >> for(Video v : videos) {
          >> >> >> ftSession.index(v);
          >> >> >> }
          >> >> >>
          >> >> >> final String[] stopWords =
          >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
          >> >> >> final MultiFieldQueryParser parser = new
          >> >>MultiFieldQueryParser(new
          >> >> >> String[]{"nome","Videos.description"} , new
          >> >> >>StopAnalyzer(stopWords));
          >> >> >> final Query query = parser.parse("Moraes Flamengo");
          >> >> >> final FullTextQuery fullTextQuery =
          >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
          >> >> >> final List<Assinante> list = fullTextQuery.list();
          >> >> >> HibernateUtil.getSessionFactory().close();
          >> >> >>
          >> >> >>
          >> >> >> }catch(Exception e){
          >> >> >> e.printStackTrace();
          >> >> >> }
          >> >> >>
          >> >> >> ************** FIM MÉTODO ********************
          >> >> >>
          >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
          >>destacar
          >> >> >>abaixo
          >> >> >> que eu informo em que campos procurar:
          >> >> >>
          >> >> >> final MultiFieldQueryParser parser = new
          >> >>MultiFieldQueryParser(new
          >> >> >> String[]{"nome","Videos.title","Videos.description"} , new
          >> >> >> StopAnalyzer(stopWords));
          >> >> >>
          >> >> >> Então, se eu fizer conforme abaixo:
          >> >> >>
          >> >> >> if (list==null || list.size()==0){
          >> >> >> System.out.println("Nenhum Vídeo encontrado.");
          >> >> >> }else{
          >> >> >> for(Assinante a : list) {
          >> >> >> System.out.println(a.getNome());
          >> >> >> for (Video v : a.getVideos()) {
          >> >> >> System.out.println(" " + v.getTitle());
          >> >> >> }
          >> >> >> }
          >> >> >> }
          >> >> >>
          >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
          >> >> >> Ex.:
          >> >> >> Anderson Moraes
          >> >> >> Vídeo 1
          >> >> >> Vídeo 4
          >> >> >> Vídeo 9
          >> >> >> Elba Ramalho
          >> >> >> Vídeo 3
          >> >> >> Vídeo 7
          >> >> >> Raul Seixas
          >> >> >> Zé Ramalho
          >> >> >> Vídeo 2
          >> >> >>
          >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso do
          >>exemplo
          >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem Assinante.
          >> >> >>
          >> >> >> Blz, agora vamos ao que eu quero.
          >> >> >>
          >> >> >> Eu quero recuperar dessa busca um List somente dos vídeos
          >> >> >> (List<Video>), independente do Assinante, o Assinante eu uso
          >>só
          >> >>para
          >> >> >> buscar pelo nome, por exemplo:
          >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será preenchido
          >>com
          >> >>os
          >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
          >> >> >>
          >> >> >> Esse List de Vídeos eu vou jogar na sessão para recuperar pelo
          >> >> >> Iterate, conforme exemplo abaixo:
          >> >> >>
          >> >> >> Na minha Action:
          >> >> >>
          >> >> >> request.setAttribute("Busca_Videos", listVideos);
          >> >> >>
          >> >> >> No meu JSP:
          >> >> >>
          >> >> >> <logic:notEmpty name="Busca_Videos">
          >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
          >> >> >> <bean:write name="resulBusca" property="title" />
          >> >> >> <bean:write name="resulBusca" property="description" />
          >> >> >> </logic:iterate>
          >> >> >> </logic:notEmpty>
          >> >> >> <logic:empty name="Busca_Video">
          >> >> >> <b>Nenhum vídeo encontrado.</b>
          >> >> >> </logic:empty>
          >> >> >>
          >> >> >> O meu problema é que eu não estou sabendo recuperar em cima da
          >> >>busca
          >> >> >> que eu fiz um LIST só de Vídeos.
          >> >> >>
          >> >> >> Alguém pode me ajudar com isso???
          >> >> >>
          >> >> >> Grato desde já,
          >> >> >>
          >> >> >> Anderson Moraes
          >> >> >>
          >> >> >>
          >> >> >
          >> >> >
          >> >> >
          >> >> > --
          >> >> > Victor Guilherme Hogemann
          >> >> > http://victor.hogemann.eti.br
          >> >>
          >> >>
          >> >>
          >> >
          >> >
          >> >
          >> > --
          >> > Victor Guilherme Hogemann
          >> > http://victor.hogemann.eti.br
          >>
          >>
          >>
          >
          >
          >
          > --
          > Victor Guilherme Hogemann
          > http://victor.hogemann.eti.br




          --
          Victor Guilherme Hogemann
          http://victor.hogemann.eti.br
        • Anderson Moraes
          Entendi sim, eu só não sei como fazer isso, como usar o método que vc me mando, como chamar... Desde já muito obrigado pela força que está me dando. On
          Message 4 of 21 , Oct 2, 2009
          • 0 Attachment
            Entendi sim, eu só não sei como fazer isso, como usar o método que vc
            me mando, como chamar...

            Desde já muito obrigado pela força que está me dando.



            On Fri, 2 Oct 2009 19:18:58 -0300
            Victor Hogemann <victor.hogemann@...> wrote:
            > Anderson,
            > Imagine a seguinte situação... Sua aplicação está funcionando, e de
            >repente
            > alguma coisa sai errada e o seu servidor capota. Beleza, você tem o
            >backup
            > do seu banco de dados, mas e os índices do Hibernate Search?
            >
            > Claro, você poderia fazer backup desses também... mas imagine que
            >não tenha
            > feito. Você vai precisar reconstruir seus índices a partir das
            >entidades
            > persistidas no banco, pra isso serve o método que eu te passei.
            >
            > Como você alterou o mapeamento das entidades no Hibernate Search,
            >logo mudou
            > a estrutura do índice, e aí é necessário re-indexar tudo novamente.
            >
            > Sacou?
            >
            > 2009/10/2 Anderson Moraes <amoraes@...>
            >
            >>
            >>
            >> Não entendi como eu executo essa classe, em que momento...
            >>
            >> On Fri, 2 Oct 2009 16:50:33 -0300
            >>
            >> Victor Hogemann <victor.hogemann@...
            >><victor.hogemann%40gmail.com>>
            >> wrote:
            >> > Anderson,
            >> > Você re-indexou suas entidades? Toda vez que você muda o
            >>mapeamento
            >> >os
            >> > índices são criados novamente, e você precisa re-indexar as
            >> >entidades que já
            >> > existiam... senão vai ficar com o índice vazio. Segue um exemplo
            >>de
            >> >como
            >> > fazer:
            >> >
            >> > public void refreshIndex(final Class entityClass) {
            >> >
            >> > this.getHibernateTemplate().execute(new HibernateCallback() {
            >> >
            >> >
            >> > public Object doInHibernate(Session session)
            >> > throwsHibernateException, SQLException {
            >>
            >> >
            >> > FullTextSession fullTextSession =
            >> > Search.getFullTextSession(session);
            >> >
            >> > Criteria crit = session.createCriteria(entityClass);
            >> >
            >> > for (Object obj : crit.list()) {
            >> >
            >> > T entity = (T) obj;
            >> >
            >> > fullTextSession.index(entity);
            >> >
            >> > }
            >> >
            >> > return null;
            >> >
            >> >
            >> > }
            >> >
            >> > });
            >> >
            >> > }
            >> >
            >> >
            >> > [ ]s
            >> >
            >> > 2009/10/2 Anderson Moraes
            >><amoraes@...<amoraes%40tecmetal.com.br>
            >> >
            >> >
            >> >>
            >> >>
            >> >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo
            >>vou
            >> >> mostrar o SQL que sai no console:
            >> >>
            >> >>
            >> >> try{
            >> >>
            >> >> final Session session =
            >> >> HibernateUtil.getSessionFactory().openSession();
            >> >> final FullTextSession ftSession =
            >> >> Search.getFullTextSession(session);
            >> >> final List<Video> videos =
            >> >> session.createCriteria(Video.class).list();
            >> >>
            >> >>
            >> >> for(Video v : videos) {
            >> >> ftSession.index(v);
            >> >> }
            >> >>
            >> >>
            >> >> final String[] stopWords =
            >> >> {"de","do","da","dos","das","a","o","na","no","em"};
            >> >> final MultiFieldQueryParser parser = new
            >> >> MultiFieldQueryParser(new
            >> >> String[]{"Video.assinante.nome","Video.description"} , new
            >> >> StopAnalyzer(stopWords));
            >> >> final Query query = parser.parse("Moraes");
            >> >> final FullTextQuery fullTextQuery =
            >> >> ftSession.createFullTextQuery(query, Video.class);
            >> >>
            >> >> final List<Video> list = fullTextQuery.list();
            >> >>
            >> >>
            >> >> HibernateUtil.getSessionFactory().close();
            >> >>
            >> >>
            >> >> if (list==null || list.size()==0){
            >> >> System.out.println("Nenhum Vídeo encontrado.");
            >> >> }else{
            >> >> for (Video v : list) {
            >> >> System.out.println(" " + v.getTitle());
            >> >> }
            >> >> }
            >> >>
            >> >> }catch(Exception e){
            >> >> e.printStackTrace();
            >> >> }
            >> >> }
            >> >>
            >> >>
            >> >> CONSOLE:
            >> >> Hibernate:
            >> >>
            >> >> select
            >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
            >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
            >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
            >> >> this_.VC_DESCRIPTION as VC3_1_1_,
            >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
            >> >> this_.VC_REAL_PATH as VC6_1_1_,
            >> >> this_.VC_TITLE as VC7_1_1_,
            >> >> this_.VC_URL as VC8_1_1_,
            >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
            >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
            >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
            >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
            >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
            >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
            >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
            >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
            >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
            >> >> from
            >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
            >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
            >> >>
            >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
            >> >>
            >> >> On Fri, 2 Oct 2009 15:40:15 -0300
            >> >>
            >> >> Victor Hogemann
            >><victor.hogemann@...<victor.hogemann%40gmail.com>
            >> >><victor.hogemann%40gmail.com>>
            >> >> wrote:
            >> >> > Anderson,
            >> >> > Você precisa remover o @IndexedEmbedded da lista de vídeos do
            >> >> >Assinante:
            >> >> >
            >> >> > @ContainedIn
            >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
            >> >> > @Cascade(CascadeType.ALL)
            >> >> > @IndexedEmbedded
            >> >> > private List<Video> Videos;
            >> >> >
            >> >> >
            >> >> > [ ]s
            >> >> >
            >> >> > 2009/10/2 Anderson Moraes
            >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
            >> 40tecmetal.com.br>
            >>
            >> >> >
            >> >> >
            >> >> >>
            >> >> >>
            >> >> >> Não consegui acertar meu método, segue as minhas Classes:
            >> >> >>
            >> >> >> ASSINANTE:
            >> >> >> @Entity
            >> >> >> @Table(name = "TBL_ASSINANTE")
            >> >> >> @Indexed
            >> >> >> public class Assinante extends PersistentObject implements
            >> >> >> Serializable{
            >> >> >>
            >> >> >> @Id
            >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
            >> >> >> @Column(name="NR_ID_ASSINANTE")
            >> >> >> private Long id;
            >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
            >> >> >> private String email;
            >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
            >> >> >> private String password;
            >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
            >> >> >> @Column(name="VC_NOME_ASSINANTE")
            >> >> >> private String nome;
            >> >> >> @Column(name="VC_CPF_ASSINANTE")
            >> >> >> private String cpf;
            >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
            >> >> >> private String endereco;
            >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
            >> >> >> private String cidade;
            >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
            >> >> >> private String estado;
            >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
            >> >> >> private String dataCadastro;
            >> >> >>
            >> >> >> @ContainedIn
            >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
            >> >> >> @Cascade(CascadeType.ALL)
            >> >> >> @IndexedEmbedded
            >> >> >> private List<Video> Videos;
            >> >> >>
            >> >> >> VÍDEO:
            >> >> >> @Entity
            >> >> >> @Table(name = "TBL_VIDEO")
            >> >> >> @Indexed
            >> >> >> public class Video implements Serializable{
            >> >> >>
            >> >> >> @Id
            >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
            >> >> >> @Column(name="NR_ID_VIDEO_PK")
            >> >> >> private Long id;
            >> >> >> @Column(name="VC_TITLE")
            >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
            >> >> >> private String title;
            >> >> >> @Column(name="VC_DESCRIPTION")
            >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
            >> >> >> private String description;
            >> >> >> @Column(name="VC_URL")
            >> >> >> private String url;
            >> >> >> @Column(name="VC_REAL_PATH")
            >> >> >> private String realPath;
            >> >> >> @Column(name="NR_ID_ASSINANTE")
            >> >> >> private Long idAssinante;
            >> >> >> @Column(name="DT_DATE_UPLOAD")
            >> >> >> private String dataUpload;
            >> >> >> @Column(name="VC_PATH_IMAGE")
            >> >> >> private String pathImage;
            >> >> >>
            >> >> >> @IndexedEmbedded
            >> >> >> @OneToOne(fetch=FetchType.EAGER)
            >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
            >> >> >> updatable=false)
            >> >> >> @Fetch(FetchMode.JOIN)
            >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
            >> >> >> private Assinante assinante;
            >> >> >>
            >> >> >> Deu erro:
            >> >> >> Caused by: org.hibernate.search.SearchException: Circular
            >> >>reference.
            >> >> >> Duplicate use of esseecraque.bean.Video in root entity
            >> >> >> esseecraque.bean.Video#assinante.Videos.
            >> >> >>
            >> >> >>
            >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
            >> >> >> Victor Hogemann
            >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
            >> <victor.hogemann%40gmail.com>
            >> >> >><victor.hogemann%40gmail.com>>
            >> >>
            >> >> >> wrote:
            >> >> >> > Anderson,
            >> >> >> > A forma mais fácil de fazer isso é criar uma associação
            >> >> >> >bi-direcional entre
            >> >> >> > Assinante e Video, assim você pode a partir do Video filtrar
            >> >>pelo
            >> >> >> >nome do
            >> >> >> > assinante usando somente uma query Lucene... Por exemplo:
            >> >> >> >
            >> >> >> > TermQuery query = new TermQuery(new
            >> >>Term("Video.assinante.nome",
            >> >> >> >"Fulano"));
            >> >> >> >FullTextQuery fullTextQuery =
            >> >> >> > fullTextSession.createFullTextQuery(query, Video.class);
            >> >> >> > return fullTextQuery.list();
            >> >> >> >
            >> >> >> >
            >> >> >> > Pelo que você escreveu a associação entre Assinante e Vídeo
            >>é
            >> >> >> >one-to-many,
            >> >> >> > então não vai ser uma mudança tão traumática assim no
            >>código. O
            >> >> >> >pulo-do-gato
            >> >> >> > é que você vai ter que repetir os dados de Assinante no
            >>indice
            >> >>de
            >> >> >> >Vídeo,
            >> >> >> > utilizando as annotations @IndexedEmbended e @ContainedIn.
            >> >> >> >
            >> >> >> > Em Vídeo você vai ter:
            >> >> >> >
            >> >> >> > @IndexedEmbeded
            >> >> >> > @OneToOne
            >> >> >> > Assinante assinante;
            >> >> >> >
            >> >> >> >
            >> >> >> > E em Assinante vai ficar:
            >> >> >> >
            >> >> >> > @ContainedIn
            >> >> >> > @OneToMany
            >> >> >> > List<Video> videos;
            >> >> >> >
            >> >> >> >
            >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
            >> >> >>basicamente
            >> >> >> >é um
            >> >> >> > resumo traduzido da referência em inglês do hibernate
            >>search.
            >> >>No
            >> >> >> >exemplo que
            >> >> >> > está lá tem um exemplo de como fazer busca em entidades
            >> >> >>associadas:
            >> >> >> >
            >> >> >> > http://victor.hogemann.eti.br/2009/06/hibernate-search.html
            >> >> >> >
            >> >> >> >
            >> >> >> > Espero ter ajudado, boa sorte!
            >> >> >> >
            >> >> >> > 2009/10/2 Anderson Moraes
            >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
            >> 40tecmetal.com.br><amoraes%
            >>
            >> >> 40tecmetal.com.br>
            >> >>
            >> >> >> >
            >> >> >> >
            >> >> >> >>
            >> >> >> >>
            >> >> >> >> Pessoal, bom dia.
            >> >> >> >>
            >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
            >> >> >>descrever
            >> >> >> >>os
            >> >> >> >> atributos da minha bean:
            >> >> >> >>
            >> >> >> >> BEAN Assinante:
            >> >> >> >> id
            >> >> >> >> nome
            >> >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
            >> >>Videos;)
            >> >> >> >>
            >> >> >> >> BEAN Video:
            >> >> >> >> id
            >> >> >> >> title
            >> >> >> >> description
            >> >> >> >> idAssinante
            >> >> >> >>
            >> >> >> >> Blz, até aí tudo bem.
            >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas duas
            >> >> >>classes
            >> >> >> >> (tabelas), sendo que em Assinante eu busco no atributo
            >>"nome"
            >> >>e
            >> >> >>em
            >> >> >> >> Video eu busco nos atributos "title" e "description", segue
            >>o
            >> >> >>método
            >> >> >> >> abaixou:
            >> >> >> >>
            >> >> >> >> ************** MÉTODO ********************
            >> >> >> >> try{
            >> >> >> >>
            >> >> >> >> final Session session =
            >> >> >> >> HibernateUtil.getSessionFactory().openSession();
            >> >> >> >> final FullTextSession ftSession =
            >> >> >> >> Search.getFullTextSession(session);
            >> >> >> >> final List<Assinante> assinantes =
            >> >> >> >> session.createCriteria(Assinante.class).list();
            >> >> >> >> final List<Video> videos =
            >> >> >> >> session.createCriteria(Video.class).list();
            >> >> >> >>
            >> >> >> >> for(Assinante a : assinantes) {
            >> >> >> >> ftSession.index(a);
            >> >> >> >> }
            >> >> >> >>
            >> >> >> >> for(Video v : videos) {
            >> >> >> >> ftSession.index(v);
            >> >> >> >> }
            >> >> >> >>
            >> >> >> >> final String[] stopWords =
            >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
            >> >> >> >> final MultiFieldQueryParser parser = new
            >> >> >>MultiFieldQueryParser(new
            >> >> >> >> String[]{"nome","Videos.description"} , new
            >> >> >> >>StopAnalyzer(stopWords));
            >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
            >> >> >> >> final FullTextQuery fullTextQuery =
            >> >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
            >> >> >> >> final List<Assinante> list = fullTextQuery.list();
            >> >> >> >> HibernateUtil.getSessionFactory().close();
            >> >> >> >>
            >> >> >> >>
            >> >> >> >> }catch(Exception e){
            >> >> >> >> e.printStackTrace();
            >> >> >> >> }
            >> >> >> >>
            >> >> >> >> ************** FIM MÉTODO ********************
            >> >> >> >>
            >> >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
            >> >>destacar
            >> >> >> >>abaixo
            >> >> >> >> que eu informo em que campos procurar:
            >> >> >> >>
            >> >> >> >> final MultiFieldQueryParser parser = new
            >> >> >>MultiFieldQueryParser(new
            >> >> >> >> String[]{"nome","Videos.title","Videos.description"} , new
            >> >> >> >> StopAnalyzer(stopWords));
            >> >> >> >>
            >> >> >> >> Então, se eu fizer conforme abaixo:
            >> >> >> >>
            >> >> >> >> if (list==null || list.size()==0){
            >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
            >> >> >> >> }else{
            >> >> >> >> for(Assinante a : list) {
            >> >> >> >> System.out.println(a.getNome());
            >> >> >> >> for (Video v : a.getVideos()) {
            >> >> >> >> System.out.println(" " + v.getTitle());
            >> >> >> >> }
            >> >> >> >> }
            >> >> >> >> }
            >> >> >> >>
            >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
            >> >> >> >> Ex.:
            >> >> >> >> Anderson Moraes
            >> >> >> >> Vídeo 1
            >> >> >> >> Vídeo 4
            >> >> >> >> Vídeo 9
            >> >> >> >> Elba Ramalho
            >> >> >> >> Vídeo 3
            >> >> >> >> Vídeo 7
            >> >> >> >> Raul Seixas
            >> >> >> >> Zé Ramalho
            >> >> >> >> Vídeo 2
            >> >> >> >>
            >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso do
            >> >>exemplo
            >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem Assinante.
            >> >> >> >>
            >> >> >> >> Blz, agora vamos ao que eu quero.
            >> >> >> >>
            >> >> >> >> Eu quero recuperar dessa busca um List somente dos vídeos
            >> >> >> >> (List<Video>), independente do Assinante, o Assinante eu
            >>uso
            >> >>só
            >> >> >>para
            >> >> >> >> buscar pelo nome, por exemplo:
            >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
            >>preenchido
            >> >>com
            >> >> >>os
            >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
            >> >> >> >>
            >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para recuperar
            >>pelo
            >> >> >> >> Iterate, conforme exemplo abaixo:
            >> >> >> >>
            >> >> >> >> Na minha Action:
            >> >> >> >>
            >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
            >> >> >> >>
            >> >> >> >> No meu JSP:
            >> >> >> >>
            >> >> >> >> <logic:notEmpty name="Busca_Videos">
            >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
            >> >> >> >> <bean:write name="resulBusca" property="title" />
            >> >> >> >> <bean:write name="resulBusca" property="description" />
            >> >> >> >> </logic:iterate>
            >> >> >> >> </logic:notEmpty>
            >> >> >> >> <logic:empty name="Busca_Video">
            >> >> >> >> <b>Nenhum vídeo encontrado.</b>
            >> >> >> >> </logic:empty>
            >> >> >> >>
            >> >> >> >> O meu problema é que eu não estou sabendo recuperar em cima
            >>da
            >> >> >>busca
            >> >> >> >> que eu fiz um LIST só de Vídeos.
            >> >> >> >>
            >> >> >> >> Alguém pode me ajudar com isso???
            >> >> >> >>
            >> >> >> >> Grato desde já,
            >> >> >> >>
            >> >> >> >> Anderson Moraes
            >> >> >> >>
            >> >> >> >>
            >> >> >> >
            >> >> >> >
            >> >> >> >
            >> >> >> > --
            >> >> >> > Victor Guilherme Hogemann
            >> >> >> > http://victor.hogemann.eti.br
            >> >> >>
            >> >> >>
            >> >> >>
            >> >> >
            >> >> >
            >> >> >
            >> >> > --
            >> >> > Victor Guilherme Hogemann
            >> >> > http://victor.hogemann.eti.br
            >> >>
            >> >>
            >> >>
            >> >
            >> >
            >> >
            >> > --
            >> > Victor Guilherme Hogemann
            >> > http://victor.hogemann.eti.br
            >>
            >>
            >>
            >
            >
            >
            > --
            > Victor Guilherme Hogemann
            > http://victor.hogemann.eti.br
          • Victor Hogemann
            Anderson, Se você estiver fazendo uma aplicação Web pode colocar dentro de um método de um controller qualquer, ou até mesmo dentro de um servlet
            Message 5 of 21 , Oct 5, 2009
            • 0 Attachment
              Anderson,

              Se você estiver fazendo uma aplicação Web pode colocar dentro de um método de um controller qualquer, ou até mesmo dentro de um servlet separado... O importante é chama-lo sem ninguém estar fazendo alterações na persistência.

              [ ]s

              2009/10/2 Anderson Moraes <amoraes@...>
               

              Entendi sim, eu só não sei como fazer isso, como usar o método que vc
              me mando, como chamar...

              Desde já muito obrigado pela força que está me dando.

              On Fri, 2 Oct 2009 19:18:58 -0300


              Victor Hogemann <victor.hogemann@...> wrote:
              > Anderson,
              > Imagine a seguinte situação... Sua aplicação está funcionando, e de
              >repente
              > alguma coisa sai errada e o seu servidor capota. Beleza, você tem o
              >backup
              > do seu banco de dados, mas e os índices do Hibernate Search?
              >
              > Claro, você poderia fazer backup desses também... mas imagine que
              >não tenha
              > feito. Você vai precisar reconstruir seus índices a partir das
              >entidades
              > persistidas no banco, pra isso serve o método que eu te passei.
              >
              > Como você alterou o mapeamento das entidades no Hibernate Search,
              >logo mudou
              > a estrutura do índice, e aí é necessário re-indexar tudo novamente.
              >
              > Sacou?
              >
              > 2009/10/2 Anderson Moraes <amoraes@...>
              >
              >>
              >>
              >> Não entendi como eu executo essa classe, em que momento...
              >>
              >> On Fri, 2 Oct 2009 16:50:33 -0300
              >>
              >> Victor Hogemann <victor.hogemann@...
              >><victor.hogemann%40gmail.com>>
              >> wrote:
              >> > Anderson,
              >> > Você re-indexou suas entidades? Toda vez que você muda o
              >>mapeamento
              >> >os
              >> > índices são criados novamente, e você precisa re-indexar as
              >> >entidades que já
              >> > existiam... senão vai ficar com o índice vazio. Segue um exemplo
              >>de
              >> >como
              >> > fazer:
              >> >
              >> > public void refreshIndex(final Class entityClass) {
              >> >
              >> > this.getHibernateTemplate().execute(new HibernateCallback() {
              >> >
              >> >
              >> > public Object doInHibernate(Session session)
              >> > throwsHibernateException, SQLException {
              >>
              >> >
              >> > FullTextSession fullTextSession =
              >> > Search.getFullTextSession(session);
              >> >
              >> > Criteria crit = session.createCriteria(entityClass);
              >> >
              >> > for (Object obj : crit.list()) {
              >> >
              >> > T entity = (T) obj;
              >> >
              >> > fullTextSession.index(entity);
              >> >
              >> > }
              >> >
              >> > return null;
              >> >
              >> >
              >> > }
              >> >
              >> > });
              >> >
              >> > }
              >> >
              >> >
              >> > [ ]s
              >> >
              >> > 2009/10/2 Anderson Moraes
              >><amoraes@...<amoraes%40tecmetal.com.br>

              >> >
              >> >
              >> >>
              >> >>
              >> >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo
              >>vou
              >> >> mostrar o SQL que sai no console:
              >> >>
              >> >>
              >> >> try{
              >> >>
              >> >> final Session session =
              >> >> HibernateUtil.getSessionFactory().openSession();
              >> >> final FullTextSession ftSession =
              >> >> Search.getFullTextSession(session);
              >> >> final List<Video> videos =
              >> >> session.createCriteria(Video.class).list();
              >> >>
              >> >>
              >> >> for(Video v : videos) {
              >> >> ftSession.index(v);
              >> >> }
              >> >>
              >> >>
              >> >> final String[] stopWords =
              >> >> {"de","do","da","dos","das","a","o","na","no","em"};
              >> >> final MultiFieldQueryParser parser = new
              >> >> MultiFieldQueryParser(new
              >> >> String[]{"Video.assinante.nome","Video.description"} , new
              >> >> StopAnalyzer(stopWords));
              >> >> final Query query = parser.parse("Moraes");
              >> >> final FullTextQuery fullTextQuery =
              >> >> ftSession.createFullTextQuery(query, Video.class);
              >> >>
              >> >> final List<Video> list = fullTextQuery.list();
              >> >>
              >> >>
              >> >> HibernateUtil.getSessionFactory().close();
              >> >>
              >> >>
              >> >> if (list==null || list.size()==0){
              >> >> System.out.println("Nenhum Vídeo encontrado.");
              >> >> }else{
              >> >> for (Video v : list) {
              >> >> System.out.println(" " + v.getTitle());
              >> >> }
              >> >> }
              >> >>
              >> >> }catch(Exception e){
              >> >> e.printStackTrace();
              >> >> }
              >> >> }
              >> >>
              >> >>
              >> >> CONSOLE:
              >> >> Hibernate:
              >> >>
              >> >> select
              >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
              >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
              >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
              >> >> this_.VC_DESCRIPTION as VC3_1_1_,
              >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
              >> >> this_.VC_REAL_PATH as VC6_1_1_,
              >> >> this_.VC_TITLE as VC7_1_1_,
              >> >> this_.VC_URL as VC8_1_1_,
              >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
              >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
              >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
              >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
              >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
              >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
              >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
              >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
              >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
              >> >> from
              >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
              >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
              >> >>
              >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
              >> >>
              >> >> On Fri, 2 Oct 2009 15:40:15 -0300
              >> >>
              >> >> Victor Hogemann
              >><victor.hogemann@...<victor.hogemann%40gmail.com>
              >> >><victor.hogemann%40gmail.com>>
              >> >> wrote:
              >> >> > Anderson,
              >> >> > Você precisa remover o @IndexedEmbedded da lista de vídeos do
              >> >> >Assinante:
              >> >> >
              >> >> > @ContainedIn
              >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
              >> >> > @Cascade(CascadeType.ALL)
              >> >> > @IndexedEmbedded
              >> >> > private List<Video> Videos;
              >> >> >
              >> >> >
              >> >> > [ ]s
              >> >> >
              >> >> > 2009/10/2 Anderson Moraes
              >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

              >> 40tecmetal.com.br>
              >>
              >> >> >
              >> >> >
              >> >> >>
              >> >> >>
              >> >> >> Não consegui acertar meu método, segue as minhas Classes:
              >> >> >>
              >> >> >> ASSINANTE:
              >> >> >> @Entity
              >> >> >> @Table(name = "TBL_ASSINANTE")
              >> >> >> @Indexed
              >> >> >> public class Assinante extends PersistentObject implements
              >> >> >> Serializable{
              >> >> >>
              >> >> >> @Id
              >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
              >> >> >> @Column(name="NR_ID_ASSINANTE")
              >> >> >> private Long id;
              >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
              >> >> >> private String email;
              >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
              >> >> >> private String password;
              >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
              >> >> >> @Column(name="VC_NOME_ASSINANTE")
              >> >> >> private String nome;
              >> >> >> @Column(name="VC_CPF_ASSINANTE")
              >> >> >> private String cpf;
              >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
              >> >> >> private String endereco;
              >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
              >> >> >> private String cidade;
              >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
              >> >> >> private String estado;
              >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
              >> >> >> private String dataCadastro;
              >> >> >>
              >> >> >> @ContainedIn
              >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
              >> >> >> @Cascade(CascadeType.ALL)
              >> >> >> @IndexedEmbedded
              >> >> >> private List<Video> Videos;
              >> >> >>
              >> >> >> VÍDEO:
              >> >> >> @Entity
              >> >> >> @Table(name = "TBL_VIDEO")
              >> >> >> @Indexed
              >> >> >> public class Video implements Serializable{
              >> >> >>
              >> >> >> @Id
              >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
              >> >> >> @Column(name="NR_ID_VIDEO_PK")
              >> >> >> private Long id;
              >> >> >> @Column(name="VC_TITLE")
              >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
              >> >> >> private String title;
              >> >> >> @Column(name="VC_DESCRIPTION")
              >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
              >> >> >> private String description;
              >> >> >> @Column(name="VC_URL")
              >> >> >> private String url;
              >> >> >> @Column(name="VC_REAL_PATH")
              >> >> >> private String realPath;
              >> >> >> @Column(name="NR_ID_ASSINANTE")
              >> >> >> private Long idAssinante;
              >> >> >> @Column(name="DT_DATE_UPLOAD")
              >> >> >> private String dataUpload;
              >> >> >> @Column(name="VC_PATH_IMAGE")
              >> >> >> private String pathImage;
              >> >> >>
              >> >> >> @IndexedEmbedded
              >> >> >> @OneToOne(fetch=FetchType.EAGER)
              >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
              >> >> >> updatable=false)
              >> >> >> @Fetch(FetchMode.JOIN)
              >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
              >> >> >> private Assinante assinante;
              >> >> >>
              >> >> >> Deu erro:
              >> >> >> Caused by: org.hibernate.search.SearchException: Circular
              >> >>reference.
              >> >> >> Duplicate use of esseecraque.bean.Video in root entity
              >> >> >> esseecraque.bean.Video#assinante.Videos.
              >> >> >>
              >> >> >>
              >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
              >> >> >> Victor Hogemann
              >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
              >> <victor.hogemann%40gmail.com>
              >> >> >><victor.hogemann%40gmail.com>>
              >> >>
              >> >> >> wrote:
              >> >> >> > Anderson,
              >> >> >> > A forma mais fácil de fazer isso é criar uma associação
              >> >> >> >bi-direcional entre
              >> >> >> > Assinante e Video, assim você pode a partir do Video filtrar
              >> >>pelo
              >> >> >> >nome do
              >> >> >> > assinante usando somente uma query Lucene... Por exemplo:
              >> >> >> >
              >> >> >> > TermQuery query = new TermQuery(new
              >> >>Term("Video.assinante.nome",
              >> >> >> >"Fulano"));
              >> >> >> >FullTextQuery fullTextQuery =
              >> >> >> > fullTextSession.createFullTextQuery(query, Video.class);
              >> >> >> > return fullTextQuery.list();
              >> >> >> >
              >> >> >> >
              >> >> >> > Pelo que você escreveu a associação entre Assinante e Vídeo
              >>é
              >> >> >> >one-to-many,
              >> >> >> > então não vai ser uma mudança tão traumática assim no
              >>código. O
              >> >> >> >pulo-do-gato
              >> >> >> > é que você vai ter que repetir os dados de Assinante no
              >>indice
              >> >>de
              >> >> >> >Vídeo,
              >> >> >> > utilizando as annotations @IndexedEmbended e @ContainedIn.
              >> >> >> >
              >> >> >> > Em Vídeo você vai ter:
              >> >> >> >
              >> >> >> > @IndexedEmbeded
              >> >> >> > @OneToOne
              >> >> >> > Assinante assinante;
              >> >> >> >
              >> >> >> >
              >> >> >> > E em Assinante vai ficar:
              >> >> >> >
              >> >> >> > @ContainedIn
              >> >> >> > @OneToMany
              >> >> >> > List<Video> videos;
              >> >> >> >
              >> >> >> >
              >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
              >> >> >>basicamente
              >> >> >> >é um
              >> >> >> > resumo traduzido da referência em inglês do hibernate
              >>search.
              >> >>No
              >> >> >> >exemplo que
              >> >> >> > está lá tem um exemplo de como fazer busca em entidades
              >> >> >>associadas:
              >> >> >> >
              >> >> >> > http://victor.hogemann.eti.br/2009/06/hibernate-search.html
              >> >> >> >
              >> >> >> >
              >> >> >> > Espero ter ajudado, boa sorte!
              >> >> >> >
              >> >> >> > 2009/10/2 Anderson Moraes
              >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
              >> 40tecmetal.com.br><amoraes%
              >>
              >> >> 40tecmetal.com.br>
              >> >>
              >> >> >> >
              >> >> >> >
              >> >> >> >>
              >> >> >> >>
              >> >> >> >> Pessoal, bom dia.
              >> >> >> >>
              >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
              >> >> >>descrever
              >> >> >> >>os
              >> >> >> >> atributos da minha bean:
              >> >> >> >>
              >> >> >> >> BEAN Assinante:
              >> >> >> >> id
              >> >> >> >> nome
              >> >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
              >> >>Videos;)
              >> >> >> >>
              >> >> >> >> BEAN Video:
              >> >> >> >> id
              >> >> >> >> title
              >> >> >> >> description
              >> >> >> >> idAssinante
              >> >> >> >>
              >> >> >> >> Blz, até aí tudo bem.
              >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas duas
              >> >> >>classes
              >> >> >> >> (tabelas), sendo que em Assinante eu busco no atributo
              >>"nome"
              >> >>e
              >> >> >>em
              >> >> >> >> Video eu busco nos atributos "title" e "description", segue
              >>o
              >> >> >>método
              >> >> >> >> abaixou:
              >> >> >> >>
              >> >> >> >> ************** MÉTODO ********************
              >> >> >> >> try{
              >> >> >> >>
              >> >> >> >> final Session session =
              >> >> >> >> HibernateUtil.getSessionFactory().openSession();
              >> >> >> >> final FullTextSession ftSession =
              >> >> >> >> Search.getFullTextSession(session);
              >> >> >> >> final List<Assinante> assinantes =
              >> >> >> >> session.createCriteria(Assinante.class).list();
              >> >> >> >> final List<Video> videos =
              >> >> >> >> session.createCriteria(Video.class).list();
              >> >> >> >>
              >> >> >> >> for(Assinante a : assinantes) {
              >> >> >> >> ftSession.index(a);
              >> >> >> >> }
              >> >> >> >>
              >> >> >> >> for(Video v : videos) {
              >> >> >> >> ftSession.index(v);
              >> >> >> >> }
              >> >> >> >>
              >> >> >> >> final String[] stopWords =
              >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
              >> >> >> >> final MultiFieldQueryParser parser = new
              >> >> >>MultiFieldQueryParser(new
              >> >> >> >> String[]{"nome","Videos.description"} , new
              >> >> >> >>StopAnalyzer(stopWords));
              >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
              >> >> >> >> final FullTextQuery fullTextQuery =
              >> >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
              >> >> >> >> final List<Assinante> list = fullTextQuery.list();
              >> >> >> >> HibernateUtil.getSessionFactory().close();
              >> >> >> >>
              >> >> >> >>
              >> >> >> >> }catch(Exception e){
              >> >> >> >> e.printStackTrace();
              >> >> >> >> }
              >> >> >> >>
              >> >> >> >> ************** FIM MÉTODO ********************
              >> >> >> >>
              >> >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
              >> >>destacar
              >> >> >> >>abaixo
              >> >> >> >> que eu informo em que campos procurar:
              >> >> >> >>
              >> >> >> >> final MultiFieldQueryParser parser = new
              >> >> >>MultiFieldQueryParser(new
              >> >> >> >> String[]{"nome","Videos.title","Videos.description"} , new
              >> >> >> >> StopAnalyzer(stopWords));
              >> >> >> >>
              >> >> >> >> Então, se eu fizer conforme abaixo:
              >> >> >> >>
              >> >> >> >> if (list==null || list.size()==0){
              >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
              >> >> >> >> }else{
              >> >> >> >> for(Assinante a : list) {
              >> >> >> >> System.out.println(a.getNome());
              >> >> >> >> for (Video v : a.getVideos()) {
              >> >> >> >> System.out.println(" " + v.getTitle());
              >> >> >> >> }
              >> >> >> >> }
              >> >> >> >> }
              >> >> >> >>
              >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
              >> >> >> >> Ex.:
              >> >> >> >> Anderson Moraes
              >> >> >> >> Vídeo 1
              >> >> >> >> Vídeo 4
              >> >> >> >> Vídeo 9
              >> >> >> >> Elba Ramalho
              >> >> >> >> Vídeo 3
              >> >> >> >> Vídeo 7
              >> >> >> >> Raul Seixas
              >> >> >> >> Zé Ramalho
              >> >> >> >> Vídeo 2
              >> >> >> >>
              >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso do
              >> >>exemplo
              >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem Assinante.
              >> >> >> >>
              >> >> >> >> Blz, agora vamos ao que eu quero.
              >> >> >> >>
              >> >> >> >> Eu quero recuperar dessa busca um List somente dos vídeos
              >> >> >> >> (List<Video>), independente do Assinante, o Assinante eu
              >>uso
              >> >>só
              >> >> >>para
              >> >> >> >> buscar pelo nome, por exemplo:
              >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
              >>preenchido
              >> >>com
              >> >> >>os
              >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
              >> >> >> >>
              >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para recuperar
              >>pelo
              >> >> >> >> Iterate, conforme exemplo abaixo:
              >> >> >> >>
              >> >> >> >> Na minha Action:
              >> >> >> >>
              >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
              >> >> >> >>
              >> >> >> >> No meu JSP:
              >> >> >> >>
              >> >> >> >> <logic:notEmpty name="Busca_Videos">
              >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
              >> >> >> >> <bean:write name="resulBusca" property="title" />
              >> >> >> >> <bean:write name="resulBusca" property="description" />
              >> >> >> >> </logic:iterate>
              >> >> >> >> </logic:notEmpty>
              >> >> >> >> <logic:empty name="Busca_Video">
              >> >> >> >> <b>Nenhum vídeo encontrado.</b>
              >> >> >> >> </logic:empty>
              >> >> >> >>
              >> >> >> >> O meu problema é que eu não estou sabendo recuperar em cima
              >>da
              >> >> >>busca
              >> >> >> >> que eu fiz um LIST só de Vídeos.
              >> >> >> >>
              >> >> >> >> Alguém pode me ajudar com isso???
              >> >> >> >>
              >> >> >> >> Grato desde já,
              >> >> >> >>
              >> >> >> >> Anderson Moraes
              >> >> >> >>
              >> >> >> >>
              >> >> >> >
              >> >> >> >
              >> >> >> >
              >> >> >> > --
              >> >> >> > Victor Guilherme Hogemann
              >> >> >> > http://victor.hogemann.eti.br
              >> >> >>
              >> >> >>
              >> >> >>
              >> >> >
              >> >> >
              >> >> >
              >> >> > --
              >> >> > Victor Guilherme Hogemann
              >> >> > http://victor.hogemann.eti.br
              >> >>
              >> >>
              >> >>
              >> >
              >> >
              >> >
              >> > --
              >> > Victor Guilherme Hogemann
              >> > http://victor.hogemann.eti.br
              >>
              >>
              >>
              >
              >
              >
              > --
              > Victor Guilherme Hogemann
              > http://victor.hogemann.eti.br




              --
              Victor Guilherme Hogemann
              http://victor.hogemann.eti.br
            • Anderson Moraes
              Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro de um main mesmo??? Esse exemplo que você me mandou serve para o meu caso ou tenho que fazer
              Message 6 of 21 , Oct 5, 2009
              • 0 Attachment
                Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro de um
                main mesmo???

                Esse exemplo que você me mandou serve para o meu caso ou tenho que
                fazer alguma modificação???

                Mais uma vez volto a lhe agradecer Victor, vlw pela força...

                Abraço,

                Anderson

                On Mon, 5 Oct 2009 11:08:55 -0300
                Victor Hogemann <victor.hogemann@...> wrote:
                > Anderson,
                > Se você estiver fazendo uma aplicação Web pode colocar dentro de um
                >método
                > de um controller qualquer, ou até mesmo dentro de um servlet
                >separado... O
                > importante é chama-lo sem ninguém estar fazendo alterações na
                >persistência.
                >
                > [ ]s
                >
                > 2009/10/2 Anderson Moraes <amoraes@...>
                >
                >>
                >>
                >> Entendi sim, eu só não sei como fazer isso, como usar o método que
                >>vc
                >> me mando, como chamar...
                >>
                >> Desde já muito obrigado pela força que está me dando.
                >>
                >> On Fri, 2 Oct 2009 19:18:58 -0300
                >>
                >> Victor Hogemann <victor.hogemann@...
                >><victor.hogemann%40gmail.com>>
                >> wrote:
                >> > Anderson,
                >> > Imagine a seguinte situação... Sua aplicação está funcionando, e
                >>de
                >> >repente
                >> > alguma coisa sai errada e o seu servidor capota. Beleza, você tem
                >>o
                >> >backup
                >> > do seu banco de dados, mas e os índices do Hibernate Search?
                >> >
                >> > Claro, você poderia fazer backup desses também... mas imagine que
                >> >não tenha
                >> > feito. Você vai precisar reconstruir seus índices a partir das
                >> >entidades
                >> > persistidas no banco, pra isso serve o método que eu te passei.
                >> >
                >> > Como você alterou o mapeamento das entidades no Hibernate Search,
                >> >logo mudou
                >> > a estrutura do índice, e aí é necessário re-indexar tudo
                >>novamente.
                >> >
                >> > Sacou?
                >> >
                >> > 2009/10/2 Anderson Moraes
                >><amoraes@...<amoraes%40tecmetal.com.br>
                >> >
                >> >
                >> >>
                >> >>
                >> >> Não entendi como eu executo essa classe, em que momento...
                >> >>
                >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                >> >>
                >> >> Victor Hogemann
                >><victor.hogemann@...<victor.hogemann%40gmail.com>
                >> >><victor.hogemann%40gmail.com>>
                >> >> wrote:
                >> >> > Anderson,
                >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                >> >>mapeamento
                >> >> >os
                >> >> > índices são criados novamente, e você precisa re-indexar as
                >> >> >entidades que já
                >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                >>exemplo
                >> >>de
                >> >> >como
                >> >> > fazer:
                >> >> >
                >> >> > public void refreshIndex(final Class entityClass) {
                >> >> >
                >> >> > this.getHibernateTemplate().execute(new HibernateCallback() {
                >> >> >
                >> >> >
                >> >> > public Object doInHibernate(Session session)
                >> >> > throwsHibernateException, SQLException {
                >> >>
                >> >> >
                >> >> > FullTextSession fullTextSession =
                >> >> > Search.getFullTextSession(session);
                >> >> >
                >> >> > Criteria crit = session.createCriteria(entityClass);
                >> >> >
                >> >> > for (Object obj : crit.list()) {
                >> >> >
                >> >> > T entity = (T) obj;
                >> >> >
                >> >> > fullTextSession.index(entity);
                >> >> >
                >> >> > }
                >> >> >
                >> >> > return null;
                >> >> >
                >> >> >
                >> >> > }
                >> >> >
                >> >> > });
                >> >> >
                >> >> > }
                >> >> >
                >> >> >
                >> >> > [ ]s
                >> >> >
                >> >> > 2009/10/2 Anderson Moraes
                >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                >> 40tecmetal.com.br>
                >>
                >> >> >
                >> >> >
                >> >> >>
                >> >> >>
                >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo
                >> >>vou
                >> >> >> mostrar o SQL que sai no console:
                >> >> >>
                >> >> >>
                >> >> >> try{
                >> >> >>
                >> >> >> final Session session =
                >> >> >> HibernateUtil.getSessionFactory().openSession();
                >> >> >> final FullTextSession ftSession =
                >> >> >> Search.getFullTextSession(session);
                >> >> >> final List<Video> videos =
                >> >> >> session.createCriteria(Video.class).list();
                >> >> >>
                >> >> >>
                >> >> >> for(Video v : videos) {
                >> >> >> ftSession.index(v);
                >> >> >> }
                >> >> >>
                >> >> >>
                >> >> >> final String[] stopWords =
                >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                >> >> >> final MultiFieldQueryParser parser = new
                >> >> >> MultiFieldQueryParser(new
                >> >> >> String[]{"Video.assinante.nome","Video.description"} , new
                >> >> >> StopAnalyzer(stopWords));
                >> >> >> final Query query = parser.parse("Moraes");
                >> >> >> final FullTextQuery fullTextQuery =
                >> >> >> ftSession.createFullTextQuery(query, Video.class);
                >> >> >>
                >> >> >> final List<Video> list = fullTextQuery.list();
                >> >> >>
                >> >> >>
                >> >> >> HibernateUtil.getSessionFactory().close();
                >> >> >>
                >> >> >>
                >> >> >> if (list==null || list.size()==0){
                >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                >> >> >> }else{
                >> >> >> for (Video v : list) {
                >> >> >> System.out.println(" " + v.getTitle());
                >> >> >> }
                >> >> >> }
                >> >> >>
                >> >> >> }catch(Exception e){
                >> >> >> e.printStackTrace();
                >> >> >> }
                >> >> >> }
                >> >> >>
                >> >> >>
                >> >> >> CONSOLE:
                >> >> >> Hibernate:
                >> >> >>
                >> >> >> select
                >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                >> >> >> this_.VC_TITLE as VC7_1_1_,
                >> >> >> this_.VC_URL as VC8_1_1_,
                >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                >> >> >> from
                >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
                >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                >> >> >>
                >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                >> >> >>
                >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                >> >> >>
                >> >> >> Victor Hogemann
                >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                >> <victor.hogemann%40gmail.com>
                >> >> >><victor.hogemann%40gmail.com>>
                >> >> >> wrote:
                >> >> >> > Anderson,
                >> >> >> > Você precisa remover o @IndexedEmbedded da lista de vídeos
                >>do
                >> >> >> >Assinante:
                >> >> >> >
                >> >> >> > @ContainedIn
                >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                >> >> >> > @Cascade(CascadeType.ALL)
                >> >> >> > @IndexedEmbedded
                >> >> >> > private List<Video> Videos;
                >> >> >> >
                >> >> >> >
                >> >> >> > [ ]s
                >> >> >> >
                >> >> >> > 2009/10/2 Anderson Moraes
                >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                >> 40tecmetal.com.br><amoraes%
                >>
                >> >> 40tecmetal.com.br>
                >> >>
                >> >> >> >
                >> >> >> >
                >> >> >> >>
                >> >> >> >>
                >> >> >> >> Não consegui acertar meu método, segue as minhas Classes:
                >> >> >> >>
                >> >> >> >> ASSINANTE:
                >> >> >> >> @Entity
                >> >> >> >> @Table(name = "TBL_ASSINANTE")
                >> >> >> >> @Indexed
                >> >> >> >> public class Assinante extends PersistentObject implements
                >> >> >> >> Serializable{
                >> >> >> >>
                >> >> >> >> @Id
                >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                >> >> >> >> private Long id;
                >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                >> >> >> >> private String email;
                >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                >> >> >> >> private String password;
                >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                >> >> >> >> private String nome;
                >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                >> >> >> >> private String cpf;
                >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                >> >> >> >> private String endereco;
                >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                >> >> >> >> private String cidade;
                >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                >> >> >> >> private String estado;
                >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                >> >> >> >> private String dataCadastro;
                >> >> >> >>
                >> >> >> >> @ContainedIn
                >> >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                >> >> >> >> @Cascade(CascadeType.ALL)
                >> >> >> >> @IndexedEmbedded
                >> >> >> >> private List<Video> Videos;
                >> >> >> >>
                >> >> >> >> VÍDEO:
                >> >> >> >> @Entity
                >> >> >> >> @Table(name = "TBL_VIDEO")
                >> >> >> >> @Indexed
                >> >> >> >> public class Video implements Serializable{
                >> >> >> >>
                >> >> >> >> @Id
                >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                >> >> >> >> private Long id;
                >> >> >> >> @Column(name="VC_TITLE")
                >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                >> >> >> >> private String title;
                >> >> >> >> @Column(name="VC_DESCRIPTION")
                >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                >> >> >> >> private String description;
                >> >> >> >> @Column(name="VC_URL")
                >> >> >> >> private String url;
                >> >> >> >> @Column(name="VC_REAL_PATH")
                >> >> >> >> private String realPath;
                >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                >> >> >> >> private Long idAssinante;
                >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                >> >> >> >> private String dataUpload;
                >> >> >> >> @Column(name="VC_PATH_IMAGE")
                >> >> >> >> private String pathImage;
                >> >> >> >>
                >> >> >> >> @IndexedEmbedded
                >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                >> >> >> >> updatable=false)
                >> >> >> >> @Fetch(FetchMode.JOIN)
                >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                >> >> >> >> private Assinante assinante;
                >> >> >> >>
                >> >> >> >> Deu erro:
                >> >> >> >> Caused by: org.hibernate.search.SearchException: Circular
                >> >> >>reference.
                >> >> >> >> Duplicate use of esseecraque.bean.Video in root entity
                >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                >> >> >> >>
                >> >> >> >>
                >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                >> >> >> >> Victor Hogemann
                >> >> >><victor.hogemann@...
                >><victor.hogemann%40gmail.com><victor.hogemann%
                >> 40gmail.com>
                >> >> <victor.hogemann%40gmail.com>
                >> >> >> >><victor.hogemann%40gmail.com>>
                >> >> >>
                >> >> >> >> wrote:
                >> >> >> >> > Anderson,
                >> >> >> >> > A forma mais fácil de fazer isso é criar uma associação
                >> >> >> >> >bi-direcional entre
                >> >> >> >> > Assinante e Video, assim você pode a partir do Video
                >>filtrar
                >> >> >>pelo
                >> >> >> >> >nome do
                >> >> >> >> > assinante usando somente uma query Lucene... Por exemplo:
                >> >> >> >> >
                >> >> >> >> > TermQuery query = new TermQuery(new
                >> >> >>Term("Video.assinante.nome",
                >> >> >> >> >"Fulano"));
                >> >> >> >> >FullTextQuery fullTextQuery =
                >> >> >> >> > fullTextSession.createFullTextQuery(query, Video.class);
                >> >> >> >> > return fullTextQuery.list();
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> > Pelo que você escreveu a associação entre Assinante e
                >>Vídeo
                >> >>é
                >> >> >> >> >one-to-many,
                >> >> >> >> > então não vai ser uma mudança tão traumática assim no
                >> >>código. O
                >> >> >> >> >pulo-do-gato
                >> >> >> >> > é que você vai ter que repetir os dados de Assinante no
                >> >>indice
                >> >> >>de
                >> >> >> >> >Vídeo,
                >> >> >> >> > utilizando as annotations @IndexedEmbended e
                >>@ContainedIn.
                >> >> >> >> >
                >> >> >> >> > Em Vídeo você vai ter:
                >> >> >> >> >
                >> >> >> >> > @IndexedEmbeded
                >> >> >> >> > @OneToOne
                >> >> >> >> > Assinante assinante;
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> > E em Assinante vai ficar:
                >> >> >> >> >
                >> >> >> >> > @ContainedIn
                >> >> >> >> > @OneToMany
                >> >> >> >> > List<Video> videos;
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
                >> >> >> >>basicamente
                >> >> >> >> >é um
                >> >> >> >> > resumo traduzido da referência em inglês do hibernate
                >> >>search.
                >> >> >>No
                >> >> >> >> >exemplo que
                >> >> >> >> > está lá tem um exemplo de como fazer busca em entidades
                >> >> >> >>associadas:
                >> >> >> >> >
                >> >> >> >> >
                >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> > Espero ter ajudado, boa sorte!
                >> >> >> >> >
                >> >> >> >> > 2009/10/2 Anderson Moraes
                >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                >><amoraes%
                >> 40tecmetal.com.br> <amoraes%
                >> >> 40tecmetal.com.br><amoraes%
                >> >>
                >> >> >> 40tecmetal.com.br>
                >> >> >>
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> >>
                >> >> >> >> >>
                >> >> >> >> >> Pessoal, bom dia.
                >> >> >> >> >>
                >> >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
                >> >> >> >>descrever
                >> >> >> >> >>os
                >> >> >> >> >> atributos da minha bean:
                >> >> >> >> >>
                >> >> >> >> >> BEAN Assinante:
                >> >> >> >> >> id
                >> >> >> >> >> nome
                >> >> >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
                >> >> >>Videos;)
                >> >> >> >> >>
                >> >> >> >> >> BEAN Video:
                >> >> >> >> >> id
                >> >> >> >> >> title
                >> >> >> >> >> description
                >> >> >> >> >> idAssinante
                >> >> >> >> >>
                >> >> >> >> >> Blz, até aí tudo bem.
                >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas
                >>duas
                >> >> >> >>classes
                >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no atributo
                >> >>"nome"
                >> >> >>e
                >> >> >> >>em
                >> >> >> >> >> Video eu busco nos atributos "title" e "description",
                >>segue
                >> >>o
                >> >> >> >>método
                >> >> >> >> >> abaixou:
                >> >> >> >> >>
                >> >> >> >> >> ************** MÉTODO ********************
                >> >> >> >> >> try{
                >> >> >> >> >>
                >> >> >> >> >> final Session session =
                >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                >> >> >> >> >> final FullTextSession ftSession =
                >> >> >> >> >> Search.getFullTextSession(session);
                >> >> >> >> >> final List<Assinante> assinantes =
                >> >> >> >> >> session.createCriteria(Assinante.class).list();
                >> >> >> >> >> final List<Video> videos =
                >> >> >> >> >> session.createCriteria(Video.class).list();
                >> >> >> >> >>
                >> >> >> >> >> for(Assinante a : assinantes) {
                >> >> >> >> >> ftSession.index(a);
                >> >> >> >> >> }
                >> >> >> >> >>
                >> >> >> >> >> for(Video v : videos) {
                >> >> >> >> >> ftSession.index(v);
                >> >> >> >> >> }
                >> >> >> >> >>
                >> >> >> >> >> final String[] stopWords =
                >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                >> >> >> >> >> final MultiFieldQueryParser parser = new
                >> >> >> >>MultiFieldQueryParser(new
                >> >> >> >> >> String[]{"nome","Videos.description"} , new
                >> >> >> >> >>StopAnalyzer(stopWords));
                >> >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
                >> >> >> >> >> final FullTextQuery fullTextQuery =
                >> >> >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
                >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                >> >> >> >> >>
                >> >> >> >> >>
                >> >> >> >> >> }catch(Exception e){
                >> >> >> >> >> e.printStackTrace();
                >> >> >> >> >> }
                >> >> >> >> >>
                >> >> >> >> >> ************** FIM MÉTODO ********************
                >> >> >> >> >>
                >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
                >> >> >>destacar
                >> >> >> >> >>abaixo
                >> >> >> >> >> que eu informo em que campos procurar:
                >> >> >> >> >>
                >> >> >> >> >> final MultiFieldQueryParser parser = new
                >> >> >> >>MultiFieldQueryParser(new
                >> >> >> >> >> String[]{"nome","Videos.title","Videos.description"} ,
                >>new
                >> >> >> >> >> StopAnalyzer(stopWords));
                >> >> >> >> >>
                >> >> >> >> >> Então, se eu fizer conforme abaixo:
                >> >> >> >> >>
                >> >> >> >> >> if (list==null || list.size()==0){
                >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                >> >> >> >> >> }else{
                >> >> >> >> >> for(Assinante a : list) {
                >> >> >> >> >> System.out.println(a.getNome());
                >> >> >> >> >> for (Video v : a.getVideos()) {
                >> >> >> >> >> System.out.println(" " + v.getTitle());
                >> >> >> >> >> }
                >> >> >> >> >> }
                >> >> >> >> >> }
                >> >> >> >> >>
                >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                >> >> >> >> >> Ex.:
                >> >> >> >> >> Anderson Moraes
                >> >> >> >> >> Vídeo 1
                >> >> >> >> >> Vídeo 4
                >> >> >> >> >> Vídeo 9
                >> >> >> >> >> Elba Ramalho
                >> >> >> >> >> Vídeo 3
                >> >> >> >> >> Vídeo 7
                >> >> >> >> >> Raul Seixas
                >> >> >> >> >> Zé Ramalho
                >> >> >> >> >> Vídeo 2
                >> >> >> >> >>
                >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso
                >>do
                >> >> >>exemplo
                >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                >>Assinante.
                >> >> >> >> >>
                >> >> >> >> >> Blz, agora vamos ao que eu quero.
                >> >> >> >> >>
                >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                >>vídeos
                >> >> >> >> >> (List<Video>), independente do Assinante, o Assinante eu
                >> >>uso
                >> >> >>só
                >> >> >> >>para
                >> >> >> >> >> buscar pelo nome, por exemplo:
                >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                >> >>preenchido
                >> >> >>com
                >> >> >> >>os
                >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                >> >> >> >> >>
                >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                >>recuperar
                >> >>pelo
                >> >> >> >> >> Iterate, conforme exemplo abaixo:
                >> >> >> >> >>
                >> >> >> >> >> Na minha Action:
                >> >> >> >> >>
                >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                >> >> >> >> >>
                >> >> >> >> >> No meu JSP:
                >> >> >> >> >>
                >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                >> >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
                >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                >> >> >> >> >> <bean:write name="resulBusca" property="description" />
                >> >> >> >> >> </logic:iterate>
                >> >> >> >> >> </logic:notEmpty>
                >> >> >> >> >> <logic:empty name="Busca_Video">
                >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                >> >> >> >> >> </logic:empty>
                >> >> >> >> >>
                >> >> >> >> >> O meu problema é que eu não estou sabendo recuperar em
                >>cima
                >> >>da
                >> >> >> >>busca
                >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                >> >> >> >> >>
                >> >> >> >> >> Alguém pode me ajudar com isso???
                >> >> >> >> >>
                >> >> >> >> >> Grato desde já,
                >> >> >> >> >>
                >> >> >> >> >> Anderson Moraes
                >> >> >> >> >>
                >> >> >> >> >>
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> >
                >> >> >> >> > --
                >> >> >> >> > Victor Guilherme Hogemann
                >> >> >> >> > http://victor.hogemann.eti.br
                >> >> >> >>
                >> >> >> >>
                >> >> >> >>
                >> >> >> >
                >> >> >> >
                >> >> >> >
                >> >> >> > --
                >> >> >> > Victor Guilherme Hogemann
                >> >> >> > http://victor.hogemann.eti.br
                >> >> >>
                >> >> >>
                >> >> >>
                >> >> >
                >> >> >
                >> >> >
                >> >> > --
                >> >> > Victor Guilherme Hogemann
                >> >> > http://victor.hogemann.eti.br
                >> >>
                >> >>
                >> >>
                >> >
                >> >
                >> >
                >> > --
                >> > Victor Guilherme Hogemann
                >> > http://victor.hogemann.eti.br
                >>
                >>
                >>
                >
                >
                >
                > --
                > Victor Guilherme Hogemann
                > http://victor.hogemann.eti.br
              • Victor Hogemann
                Anderson, Pode fazer dentro de um main sim, e o método serve pra qualquer entidade indexada com hibernate-search... Por exemplo, basta chamar
                Message 7 of 21 , Oct 5, 2009
                • 0 Attachment
                  Anderson,

                  Pode fazer dentro de um main sim, e o método serve pra qualquer entidade indexada com hibernate-search... Por exemplo, basta chamar refreshIndex(Assinante.class) e refreshIndex(Video.class) no seu caso.

                  [ ]s

                  2009/10/5 Anderson Moraes <amoraes@...>
                   

                  Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro de um
                  main mesmo???

                  Esse exemplo que você me mandou serve para o meu caso ou tenho que
                  fazer alguma modificação???

                  Mais uma vez volto a lhe agradecer Victor, vlw pela força...

                  Abraço,

                  Anderson

                  On Mon, 5 Oct 2009 11:08:55 -0300


                  Victor Hogemann <victor.hogemann@...> wrote:
                  > Anderson,
                  > Se você estiver fazendo uma aplicação Web pode colocar dentro de um
                  >método
                  > de um controller qualquer, ou até mesmo dentro de um servlet
                  >separado... O
                  > importante é chama-lo sem ninguém estar fazendo alterações na
                  >persistência.
                  >
                  > [ ]s
                  >
                  > 2009/10/2 Anderson Moraes <amoraes@...>
                  >
                  >>
                  >>
                  >> Entendi sim, eu só não sei como fazer isso, como usar o método que
                  >>vc
                  >> me mando, como chamar...
                  >>
                  >> Desde já muito obrigado pela força que está me dando.
                  >>
                  >> On Fri, 2 Oct 2009 19:18:58 -0300
                  >>
                  >> Victor Hogemann <victor.hogemann@...
                  >><victor.hogemann%40gmail.com>>
                  >> wrote:
                  >> > Anderson,
                  >> > Imagine a seguinte situação... Sua aplicação está funcionando, e
                  >>de
                  >> >repente
                  >> > alguma coisa sai errada e o seu servidor capota. Beleza, você tem
                  >>o
                  >> >backup
                  >> > do seu banco de dados, mas e os índices do Hibernate Search?
                  >> >
                  >> > Claro, você poderia fazer backup desses também... mas imagine que
                  >> >não tenha
                  >> > feito. Você vai precisar reconstruir seus índices a partir das
                  >> >entidades
                  >> > persistidas no banco, pra isso serve o método que eu te passei.
                  >> >
                  >> > Como você alterou o mapeamento das entidades no Hibernate Search,
                  >> >logo mudou
                  >> > a estrutura do índice, e aí é necessário re-indexar tudo
                  >>novamente.
                  >> >
                  >> > Sacou?
                  >> >
                  >> > 2009/10/2 Anderson Moraes
                  >><amoraes@...<amoraes%40tecmetal.com.br>

                  >> >
                  >> >
                  >> >>
                  >> >>
                  >> >> Não entendi como eu executo essa classe, em que momento...
                  >> >>
                  >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                  >> >>
                  >> >> Victor Hogemann
                  >><victor.hogemann@...<victor.hogemann%40gmail.com>
                  >> >><victor.hogemann%40gmail.com>>
                  >> >> wrote:
                  >> >> > Anderson,
                  >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                  >> >>mapeamento
                  >> >> >os
                  >> >> > índices são criados novamente, e você precisa re-indexar as
                  >> >> >entidades que já
                  >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                  >>exemplo
                  >> >>de
                  >> >> >como
                  >> >> > fazer:
                  >> >> >
                  >> >> > public void refreshIndex(final Class entityClass) {
                  >> >> >
                  >> >> > this.getHibernateTemplate().execute(new HibernateCallback() {
                  >> >> >
                  >> >> >
                  >> >> > public Object doInHibernate(Session session)
                  >> >> > throwsHibernateException, SQLException {
                  >> >>
                  >> >> >
                  >> >> > FullTextSession fullTextSession =
                  >> >> > Search.getFullTextSession(session);
                  >> >> >
                  >> >> > Criteria crit = session.createCriteria(entityClass);
                  >> >> >
                  >> >> > for (Object obj : crit.list()) {
                  >> >> >
                  >> >> > T entity = (T) obj;
                  >> >> >
                  >> >> > fullTextSession.index(entity);
                  >> >> >
                  >> >> > }
                  >> >> >
                  >> >> > return null;
                  >> >> >
                  >> >> >
                  >> >> > }
                  >> >> >
                  >> >> > });
                  >> >> >
                  >> >> > }
                  >> >> >
                  >> >> >
                  >> >> > [ ]s
                  >> >> >
                  >> >> > 2009/10/2 Anderson Moraes
                  >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

                  >> 40tecmetal.com.br>
                  >>
                  >> >> >
                  >> >> >
                  >> >> >>
                  >> >> >>
                  >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz, abaixo
                  >> >>vou
                  >> >> >> mostrar o SQL que sai no console:
                  >> >> >>
                  >> >> >>
                  >> >> >> try{
                  >> >> >>
                  >> >> >> final Session session =
                  >> >> >> HibernateUtil.getSessionFactory().openSession();
                  >> >> >> final FullTextSession ftSession =
                  >> >> >> Search.getFullTextSession(session);
                  >> >> >> final List<Video> videos =
                  >> >> >> session.createCriteria(Video.class).list();
                  >> >> >>
                  >> >> >>
                  >> >> >> for(Video v : videos) {
                  >> >> >> ftSession.index(v);
                  >> >> >> }
                  >> >> >>
                  >> >> >>
                  >> >> >> final String[] stopWords =
                  >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                  >> >> >> final MultiFieldQueryParser parser = new
                  >> >> >> MultiFieldQueryParser(new
                  >> >> >> String[]{"Video.assinante.nome","Video.description"} , new
                  >> >> >> StopAnalyzer(stopWords));
                  >> >> >> final Query query = parser.parse("Moraes");
                  >> >> >> final FullTextQuery fullTextQuery =
                  >> >> >> ftSession.createFullTextQuery(query, Video.class);
                  >> >> >>
                  >> >> >> final List<Video> list = fullTextQuery.list();
                  >> >> >>
                  >> >> >>
                  >> >> >> HibernateUtil.getSessionFactory().close();
                  >> >> >>
                  >> >> >>
                  >> >> >> if (list==null || list.size()==0){
                  >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                  >> >> >> }else{
                  >> >> >> for (Video v : list) {
                  >> >> >> System.out.println(" " + v.getTitle());
                  >> >> >> }
                  >> >> >> }
                  >> >> >>
                  >> >> >> }catch(Exception e){
                  >> >> >> e.printStackTrace();
                  >> >> >> }
                  >> >> >> }
                  >> >> >>
                  >> >> >>
                  >> >> >> CONSOLE:
                  >> >> >> Hibernate:
                  >> >> >>
                  >> >> >> select
                  >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                  >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                  >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                  >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                  >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                  >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                  >> >> >> this_.VC_TITLE as VC7_1_1_,
                  >> >> >> this_.VC_URL as VC8_1_1_,
                  >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                  >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                  >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                  >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                  >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                  >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                  >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                  >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                  >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                  >> >> >> from
                  >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_ on
                  >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                  >> >> >>
                  >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                  >> >> >>
                  >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                  >> >> >>
                  >> >> >> Victor Hogemann
                  >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                  >> <victor.hogemann%40gmail.com>
                  >> >> >><victor.hogemann%40gmail.com>>
                  >> >> >> wrote:
                  >> >> >> > Anderson,
                  >> >> >> > Você precisa remover o @IndexedEmbedded da lista de vídeos
                  >>do
                  >> >> >> >Assinante:
                  >> >> >> >
                  >> >> >> > @ContainedIn
                  >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                  >> >> >> > @Cascade(CascadeType.ALL)
                  >> >> >> > @IndexedEmbedded
                  >> >> >> > private List<Video> Videos;
                  >> >> >> >
                  >> >> >> >
                  >> >> >> > [ ]s
                  >> >> >> >
                  >> >> >> > 2009/10/2 Anderson Moraes
                  >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                  >> 40tecmetal.com.br><amoraes%
                  >>
                  >> >> 40tecmetal.com.br>
                  >> >>
                  >> >> >> >
                  >> >> >> >
                  >> >> >> >>
                  >> >> >> >>
                  >> >> >> >> Não consegui acertar meu método, segue as minhas Classes:
                  >> >> >> >>
                  >> >> >> >> ASSINANTE:
                  >> >> >> >> @Entity
                  >> >> >> >> @Table(name = "TBL_ASSINANTE")
                  >> >> >> >> @Indexed
                  >> >> >> >> public class Assinante extends PersistentObject implements
                  >> >> >> >> Serializable{
                  >> >> >> >>
                  >> >> >> >> @Id
                  >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                  >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                  >> >> >> >> private Long id;
                  >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                  >> >> >> >> private String email;
                  >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                  >> >> >> >> private String password;
                  >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                  >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                  >> >> >> >> private String nome;
                  >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                  >> >> >> >> private String cpf;
                  >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                  >> >> >> >> private String endereco;
                  >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                  >> >> >> >> private String cidade;
                  >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                  >> >> >> >> private String estado;
                  >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                  >> >> >> >> private String dataCadastro;
                  >> >> >> >>
                  >> >> >> >> @ContainedIn
                  >> >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                  >> >> >> >> @Cascade(CascadeType.ALL)
                  >> >> >> >> @IndexedEmbedded
                  >> >> >> >> private List<Video> Videos;
                  >> >> >> >>
                  >> >> >> >> VÍDEO:
                  >> >> >> >> @Entity
                  >> >> >> >> @Table(name = "TBL_VIDEO")
                  >> >> >> >> @Indexed
                  >> >> >> >> public class Video implements Serializable{
                  >> >> >> >>
                  >> >> >> >> @Id
                  >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                  >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                  >> >> >> >> private Long id;
                  >> >> >> >> @Column(name="VC_TITLE")
                  >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                  >> >> >> >> private String title;
                  >> >> >> >> @Column(name="VC_DESCRIPTION")
                  >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                  >> >> >> >> private String description;
                  >> >> >> >> @Column(name="VC_URL")
                  >> >> >> >> private String url;
                  >> >> >> >> @Column(name="VC_REAL_PATH")
                  >> >> >> >> private String realPath;
                  >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                  >> >> >> >> private Long idAssinante;
                  >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                  >> >> >> >> private String dataUpload;
                  >> >> >> >> @Column(name="VC_PATH_IMAGE")
                  >> >> >> >> private String pathImage;
                  >> >> >> >>
                  >> >> >> >> @IndexedEmbedded
                  >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                  >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                  >> >> >> >> updatable=false)
                  >> >> >> >> @Fetch(FetchMode.JOIN)
                  >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                  >> >> >> >> private Assinante assinante;
                  >> >> >> >>
                  >> >> >> >> Deu erro:
                  >> >> >> >> Caused by: org.hibernate.search.SearchException: Circular
                  >> >> >>reference.
                  >> >> >> >> Duplicate use of esseecraque.bean.Video in root entity
                  >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                  >> >> >> >>
                  >> >> >> >>
                  >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                  >> >> >> >> Victor Hogemann
                  >> >> >><victor.hogemann@...
                  >><victor.hogemann%40gmail.com><victor.hogemann%
                  >> 40gmail.com>
                  >> >> <victor.hogemann%40gmail.com>
                  >> >> >> >><victor.hogemann%40gmail.com>>
                  >> >> >>
                  >> >> >> >> wrote:
                  >> >> >> >> > Anderson,
                  >> >> >> >> > A forma mais fácil de fazer isso é criar uma associação
                  >> >> >> >> >bi-direcional entre
                  >> >> >> >> > Assinante e Video, assim você pode a partir do Video
                  >>filtrar
                  >> >> >>pelo
                  >> >> >> >> >nome do
                  >> >> >> >> > assinante usando somente uma query Lucene... Por exemplo:
                  >> >> >> >> >
                  >> >> >> >> > TermQuery query = new TermQuery(new
                  >> >> >>Term("Video.assinante.nome",
                  >> >> >> >> >"Fulano"));
                  >> >> >> >> >FullTextQuery fullTextQuery =
                  >> >> >> >> > fullTextSession.createFullTextQuery(query, Video.class);
                  >> >> >> >> > return fullTextQuery.list();
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> > Pelo que você escreveu a associação entre Assinante e
                  >>Vídeo
                  >> >>é
                  >> >> >> >> >one-to-many,
                  >> >> >> >> > então não vai ser uma mudança tão traumática assim no
                  >> >>código. O
                  >> >> >> >> >pulo-do-gato
                  >> >> >> >> > é que você vai ter que repetir os dados de Assinante no
                  >> >>indice
                  >> >> >>de
                  >> >> >> >> >Vídeo,
                  >> >> >> >> > utilizando as annotations @IndexedEmbended e
                  >>@ContainedIn.
                  >> >> >> >> >
                  >> >> >> >> > Em Vídeo você vai ter:
                  >> >> >> >> >
                  >> >> >> >> > @IndexedEmbeded
                  >> >> >> >> > @OneToOne
                  >> >> >> >> > Assinante assinante;
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> > E em Assinante vai ficar:
                  >> >> >> >> >
                  >> >> >> >> > @ContainedIn
                  >> >> >> >> > @OneToMany
                  >> >> >> >> > List<Video> videos;
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search, que
                  >> >> >> >>basicamente
                  >> >> >> >> >é um
                  >> >> >> >> > resumo traduzido da referência em inglês do hibernate
                  >> >>search.
                  >> >> >>No
                  >> >> >> >> >exemplo que
                  >> >> >> >> > está lá tem um exemplo de como fazer busca em entidades
                  >> >> >> >>associadas:
                  >> >> >> >> >
                  >> >> >> >> >
                  >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> > Espero ter ajudado, boa sorte!
                  >> >> >> >> >
                  >> >> >> >> > 2009/10/2 Anderson Moraes
                  >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                  >><amoraes%
                  >> 40tecmetal.com.br> <amoraes%
                  >> >> 40tecmetal.com.br><amoraes%
                  >> >>
                  >> >> >> 40tecmetal.com.br>
                  >> >> >>
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> >>
                  >> >> >> >> >>
                  >> >> >> >> >> Pessoal, bom dia.
                  >> >> >> >> >>
                  >> >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro vou
                  >> >> >> >>descrever
                  >> >> >> >> >>os
                  >> >> >> >> >> atributos da minha bean:
                  >> >> >> >> >>
                  >> >> >> >> >> BEAN Assinante:
                  >> >> >> >> >> id
                  >> >> >> >> >> nome
                  >> >> >> >> >> Videos (Uma Coleção de Vídeo - private Collection<Video>
                  >> >> >>Videos;)
                  >> >> >> >> >>
                  >> >> >> >> >> BEAN Video:
                  >> >> >> >> >> id
                  >> >> >> >> >> title
                  >> >> >> >> >> description
                  >> >> >> >> >> idAssinante
                  >> >> >> >> >>
                  >> >> >> >> >> Blz, até aí tudo bem.
                  >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas
                  >>duas
                  >> >> >> >>classes
                  >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no atributo
                  >> >>"nome"
                  >> >> >>e
                  >> >> >> >>em
                  >> >> >> >> >> Video eu busco nos atributos "title" e "description",
                  >>segue
                  >> >>o
                  >> >> >> >>método
                  >> >> >> >> >> abaixou:
                  >> >> >> >> >>
                  >> >> >> >> >> ************** MÉTODO ********************
                  >> >> >> >> >> try{
                  >> >> >> >> >>
                  >> >> >> >> >> final Session session =
                  >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                  >> >> >> >> >> final FullTextSession ftSession =
                  >> >> >> >> >> Search.getFullTextSession(session);
                  >> >> >> >> >> final List<Assinante> assinantes =
                  >> >> >> >> >> session.createCriteria(Assinante.class).list();
                  >> >> >> >> >> final List<Video> videos =
                  >> >> >> >> >> session.createCriteria(Video.class).list();
                  >> >> >> >> >>
                  >> >> >> >> >> for(Assinante a : assinantes) {
                  >> >> >> >> >> ftSession.index(a);
                  >> >> >> >> >> }
                  >> >> >> >> >>
                  >> >> >> >> >> for(Video v : videos) {
                  >> >> >> >> >> ftSession.index(v);
                  >> >> >> >> >> }
                  >> >> >> >> >>
                  >> >> >> >> >> final String[] stopWords =
                  >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                  >> >> >> >> >> final MultiFieldQueryParser parser = new
                  >> >> >> >>MultiFieldQueryParser(new
                  >> >> >> >> >> String[]{"nome","Videos.description"} , new
                  >> >> >> >> >>StopAnalyzer(stopWords));
                  >> >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
                  >> >> >> >> >> final FullTextQuery fullTextQuery =
                  >> >> >> >> >> ftSession.createFullTextQuery(query, Assinante.class);
                  >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                  >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                  >> >> >> >> >>
                  >> >> >> >> >>
                  >> >> >> >> >> }catch(Exception e){
                  >> >> >> >> >> e.printStackTrace();
                  >> >> >> >> >> }
                  >> >> >> >> >>
                  >> >> >> >> >> ************** FIM MÉTODO ********************
                  >> >> >> >> >>
                  >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu vou
                  >> >> >>destacar
                  >> >> >> >> >>abaixo
                  >> >> >> >> >> que eu informo em que campos procurar:
                  >> >> >> >> >>
                  >> >> >> >> >> final MultiFieldQueryParser parser = new
                  >> >> >> >>MultiFieldQueryParser(new
                  >> >> >> >> >> String[]{"nome","Videos.title","Videos.description"} ,
                  >>new
                  >> >> >> >> >> StopAnalyzer(stopWords));
                  >> >> >> >> >>
                  >> >> >> >> >> Então, se eu fizer conforme abaixo:
                  >> >> >> >> >>
                  >> >> >> >> >> if (list==null || list.size()==0){
                  >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                  >> >> >> >> >> }else{
                  >> >> >> >> >> for(Assinante a : list) {
                  >> >> >> >> >> System.out.println(a.getNome());
                  >> >> >> >> >> for (Video v : a.getVideos()) {
                  >> >> >> >> >> System.out.println(" " + v.getTitle());
                  >> >> >> >> >> }
                  >> >> >> >> >> }
                  >> >> >> >> >> }
                  >> >> >> >> >>
                  >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                  >> >> >> >> >> Ex.:
                  >> >> >> >> >> Anderson Moraes
                  >> >> >> >> >> Vídeo 1
                  >> >> >> >> >> Vídeo 4
                  >> >> >> >> >> Vídeo 9
                  >> >> >> >> >> Elba Ramalho
                  >> >> >> >> >> Vídeo 3
                  >> >> >> >> >> Vídeo 7
                  >> >> >> >> >> Raul Seixas
                  >> >> >> >> >> Zé Ramalho
                  >> >> >> >> >> Vídeo 2
                  >> >> >> >> >>
                  >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no caso
                  >>do
                  >> >> >>exemplo
                  >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                  >>Assinante.
                  >> >> >> >> >>
                  >> >> >> >> >> Blz, agora vamos ao que eu quero.
                  >> >> >> >> >>
                  >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                  >>vídeos
                  >> >> >> >> >> (List<Video>), independente do Assinante, o Assinante eu
                  >> >>uso
                  >> >> >>só
                  >> >> >> >>para
                  >> >> >> >> >> buscar pelo nome, por exemplo:
                  >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                  >> >>preenchido
                  >> >> >>com
                  >> >> >> >>os
                  >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                  >> >> >> >> >>
                  >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                  >>recuperar
                  >> >>pelo
                  >> >> >> >> >> Iterate, conforme exemplo abaixo:
                  >> >> >> >> >>
                  >> >> >> >> >> Na minha Action:
                  >> >> >> >> >>
                  >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                  >> >> >> >> >>
                  >> >> >> >> >> No meu JSP:
                  >> >> >> >> >>
                  >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                  >> >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
                  >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                  >> >> >> >> >> <bean:write name="resulBusca" property="description" />
                  >> >> >> >> >> </logic:iterate>
                  >> >> >> >> >> </logic:notEmpty>
                  >> >> >> >> >> <logic:empty name="Busca_Video">
                  >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                  >> >> >> >> >> </logic:empty>
                  >> >> >> >> >>
                  >> >> >> >> >> O meu problema é que eu não estou sabendo recuperar em
                  >>cima
                  >> >>da
                  >> >> >> >>busca
                  >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                  >> >> >> >> >>
                  >> >> >> >> >> Alguém pode me ajudar com isso???
                  >> >> >> >> >>
                  >> >> >> >> >> Grato desde já,
                  >> >> >> >> >>
                  >> >> >> >> >> Anderson Moraes
                  >> >> >> >> >>
                  >> >> >> >> >>
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> >
                  >> >> >> >> > --
                  >> >> >> >> > Victor Guilherme Hogemann
                  >> >> >> >> > http://victor.hogemann.eti.br
                  >> >> >> >>
                  >> >> >> >>
                  >> >> >> >>
                  >> >> >> >
                  >> >> >> >
                  >> >> >> >
                  >> >> >> > --
                  >> >> >> > Victor Guilherme Hogemann
                  >> >> >> > http://victor.hogemann.eti.br
                  >> >> >>
                  >> >> >>
                  >> >> >>
                  >> >> >
                  >> >> >
                  >> >> >
                  >> >> > --
                  >> >> > Victor Guilherme Hogemann
                  >> >> > http://victor.hogemann.eti.br
                  >> >>
                  >> >>
                  >> >>
                  >> >
                  >> >
                  >> >
                  >> > --
                  >> > Victor Guilherme Hogemann
                  >> > http://victor.hogemann.eti.br
                  >>
                  >>
                  >>
                  >
                  >
                  >
                  > --
                  > Victor Guilherme Hogemann
                  > http://victor.hogemann.eti.br




                  --
                  Victor Guilherme Hogemann
                  http://victor.hogemann.eti.br
                • Anderson Moraes
                  Está dando erro em this.getHibernateTemplate().execute(new HibernateCallback(){ , diz que os métodos getHibernateTemplate() é indefinido e que
                  Message 8 of 21 , Oct 5, 2009
                  • 0 Attachment
                    Está dando erro em "this.getHibernateTemplate().execute(new
                    HibernateCallback(){", diz que os métodos getHibernateTemplate() é
                    indefinido e que HibernateCallback() não pode ser definido para o
                    tipo.



                    On Mon, 5 Oct 2009 14:48:47 -0300
                    Victor Hogemann <victor.hogemann@...> wrote:
                    > Anderson,
                    > Pode fazer dentro de um main sim, e o método serve pra qualquer
                    >entidade
                    > indexada com hibernate-search... Por exemplo, basta chamar
                    > refreshIndex(Assinante.class) e refreshIndex(Video.class) no seu
                    >caso.
                    >
                    > [ ]s
                    >
                    > 2009/10/5 Anderson Moraes <amoraes@...>
                    >
                    >>
                    >>
                    >> Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro de
                    >>um
                    >> main mesmo???
                    >>
                    >> Esse exemplo que você me mandou serve para o meu caso ou tenho que
                    >> fazer alguma modificação???
                    >>
                    >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                    >>
                    >> Abraço,
                    >>
                    >> Anderson
                    >>
                    >> On Mon, 5 Oct 2009 11:08:55 -0300
                    >>
                    >> Victor Hogemann <victor.hogemann@...
                    >><victor.hogemann%40gmail.com>>
                    >> wrote:
                    >> > Anderson,
                    >> > Se você estiver fazendo uma aplicação Web pode colocar dentro de
                    >>um
                    >> >método
                    >> > de um controller qualquer, ou até mesmo dentro de um servlet
                    >> >separado... O
                    >> > importante é chama-lo sem ninguém estar fazendo alterações na
                    >> >persistência.
                    >> >
                    >> > [ ]s
                    >> >
                    >> > 2009/10/2 Anderson Moraes
                    >><amoraes@...<amoraes%40tecmetal.com.br>
                    >> >
                    >> >
                    >> >>
                    >> >>
                    >> >> Entendi sim, eu só não sei como fazer isso, como usar o método
                    >>que
                    >> >>vc
                    >> >> me mando, como chamar...
                    >> >>
                    >> >> Desde já muito obrigado pela força que está me dando.
                    >> >>
                    >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                    >> >>
                    >> >> Victor Hogemann
                    >><victor.hogemann@...<victor.hogemann%40gmail.com>
                    >> >><victor.hogemann%40gmail.com>>
                    >> >> wrote:
                    >> >> > Anderson,
                    >> >> > Imagine a seguinte situação... Sua aplicação está funcionando,
                    >>e
                    >> >>de
                    >> >> >repente
                    >> >> > alguma coisa sai errada e o seu servidor capota. Beleza, você
                    >>tem
                    >> >>o
                    >> >> >backup
                    >> >> > do seu banco de dados, mas e os índices do Hibernate Search?
                    >> >> >
                    >> >> > Claro, você poderia fazer backup desses também... mas imagine
                    >>que
                    >> >> >não tenha
                    >> >> > feito. Você vai precisar reconstruir seus índices a partir das
                    >> >> >entidades
                    >> >> > persistidas no banco, pra isso serve o método que eu te passei.
                    >> >> >
                    >> >> > Como você alterou o mapeamento das entidades no Hibernate
                    >>Search,
                    >> >> >logo mudou
                    >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                    >> >>novamente.
                    >> >> >
                    >> >> > Sacou?
                    >> >> >
                    >> >> > 2009/10/2 Anderson Moraes
                    >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                    >> 40tecmetal.com.br>
                    >>
                    >> >> >
                    >> >> >
                    >> >> >>
                    >> >> >>
                    >> >> >> Não entendi como eu executo essa classe, em que momento...
                    >> >> >>
                    >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                    >> >> >>
                    >> >> >> Victor Hogemann
                    >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                    >> <victor.hogemann%40gmail.com>
                    >> >> >><victor.hogemann%40gmail.com>>
                    >> >> >> wrote:
                    >> >> >> > Anderson,
                    >> >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                    >> >> >>mapeamento
                    >> >> >> >os
                    >> >> >> > índices são criados novamente, e você precisa re-indexar as
                    >> >> >> >entidades que já
                    >> >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                    >> >>exemplo
                    >> >> >>de
                    >> >> >> >como
                    >> >> >> > fazer:
                    >> >> >> >
                    >> >> >> > public void refreshIndex(final Class entityClass) {
                    >> >> >> >
                    >> >> >> > this.getHibernateTemplate().execute(new HibernateCallback()
                    >>{
                    >> >> >> >
                    >> >> >> >
                    >> >> >> > public Object doInHibernate(Session session)
                    >> >> >> > throwsHibernateException, SQLException {
                    >> >> >>
                    >> >> >> >
                    >> >> >> > FullTextSession fullTextSession =
                    >> >> >> > Search.getFullTextSession(session);
                    >> >> >> >
                    >> >> >> > Criteria crit = session.createCriteria(entityClass);
                    >> >> >> >
                    >> >> >> > for (Object obj : crit.list()) {
                    >> >> >> >
                    >> >> >> > T entity = (T) obj;
                    >> >> >> >
                    >> >> >> > fullTextSession.index(entity);
                    >> >> >> >
                    >> >> >> > }
                    >> >> >> >
                    >> >> >> > return null;
                    >> >> >> >
                    >> >> >> >
                    >> >> >> > }
                    >> >> >> >
                    >> >> >> > });
                    >> >> >> >
                    >> >> >> > }
                    >> >> >> >
                    >> >> >> >
                    >> >> >> > [ ]s
                    >> >> >> >
                    >> >> >> > 2009/10/2 Anderson Moraes
                    >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                    >> 40tecmetal.com.br><amoraes%
                    >>
                    >> >> 40tecmetal.com.br>
                    >> >>
                    >> >> >> >
                    >> >> >> >
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz,
                    >>abaixo
                    >> >> >>vou
                    >> >> >> >> mostrar o SQL que sai no console:
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> try{
                    >> >> >> >>
                    >> >> >> >> final Session session =
                    >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                    >> >> >> >> final FullTextSession ftSession =
                    >> >> >> >> Search.getFullTextSession(session);
                    >> >> >> >> final List<Video> videos =
                    >> >> >> >> session.createCriteria(Video.class).list();
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> for(Video v : videos) {
                    >> >> >> >> ftSession.index(v);
                    >> >> >> >> }
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> final String[] stopWords =
                    >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                    >> >> >> >> final MultiFieldQueryParser parser = new
                    >> >> >> >> MultiFieldQueryParser(new
                    >> >> >> >> String[]{"Video.assinante.nome","Video.description"} , new
                    >> >> >> >> StopAnalyzer(stopWords));
                    >> >> >> >> final Query query = parser.parse("Moraes");
                    >> >> >> >> final FullTextQuery fullTextQuery =
                    >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                    >> >> >> >>
                    >> >> >> >> final List<Video> list = fullTextQuery.list();
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> HibernateUtil.getSessionFactory().close();
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> if (list==null || list.size()==0){
                    >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                    >> >> >> >> }else{
                    >> >> >> >> for (Video v : list) {
                    >> >> >> >> System.out.println(" " + v.getTitle());
                    >> >> >> >> }
                    >> >> >> >> }
                    >> >> >> >>
                    >> >> >> >> }catch(Exception e){
                    >> >> >> >> e.printStackTrace();
                    >> >> >> >> }
                    >> >> >> >> }
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >> CONSOLE:
                    >> >> >> >> Hibernate:
                    >> >> >> >>
                    >> >> >> >> select
                    >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                    >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                    >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                    >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                    >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                    >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                    >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                    >> >> >> >> this_.VC_URL as VC8_1_1_,
                    >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                    >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                    >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                    >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                    >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                    >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                    >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                    >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                    >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                    >> >> >> >> from
                    >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_
                    >>on
                    >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                    >> >> >> >>
                    >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                    >> >> >> >>
                    >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                    >> >> >> >>
                    >> >> >> >> Victor Hogemann
                    >> >> >><victor.hogemann@...
                    >><victor.hogemann%40gmail.com><victor.hogemann%
                    >> 40gmail.com>
                    >> >> <victor.hogemann%40gmail.com>
                    >> >> >> >><victor.hogemann%40gmail.com>>
                    >> >> >> >> wrote:
                    >> >> >> >> > Anderson,
                    >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                    >>vídeos
                    >> >>do
                    >> >> >> >> >Assinante:
                    >> >> >> >> >
                    >> >> >> >> > @ContainedIn
                    >> >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                    >> >> >> >> > @Cascade(CascadeType.ALL)
                    >> >> >> >> > @IndexedEmbedded
                    >> >> >> >> > private List<Video> Videos;
                    >> >> >> >> >
                    >> >> >> >> >
                    >> >> >> >> > [ ]s
                    >> >> >> >> >
                    >> >> >> >> > 2009/10/2 Anderson Moraes
                    >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                    >><amoraes%
                    >> 40tecmetal.com.br> <amoraes%
                    >> >> 40tecmetal.com.br><amoraes%
                    >> >>
                    >> >> >> 40tecmetal.com.br>
                    >> >> >>
                    >> >> >> >> >
                    >> >> >> >> >
                    >> >> >> >> >>
                    >> >> >> >> >>
                    >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                    >>Classes:
                    >> >> >> >> >>
                    >> >> >> >> >> ASSINANTE:
                    >> >> >> >> >> @Entity
                    >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                    >> >> >> >> >> @Indexed
                    >> >> >> >> >> public class Assinante extends PersistentObject
                    >>implements
                    >> >> >> >> >> Serializable{
                    >> >> >> >> >>
                    >> >> >> >> >> @Id
                    >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                    >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                    >> >> >> >> >> private Long id;
                    >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                    >> >> >> >> >> private String email;
                    >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                    >> >> >> >> >> private String password;
                    >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                    >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                    >> >> >> >> >> private String nome;
                    >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                    >> >> >> >> >> private String cpf;
                    >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                    >> >> >> >> >> private String endereco;
                    >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                    >> >> >> >> >> private String cidade;
                    >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                    >> >> >> >> >> private String estado;
                    >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                    >> >> >> >> >> private String dataCadastro;
                    >> >> >> >> >>
                    >> >> >> >> >> @ContainedIn
                    >> >> >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                    >> >> >> >> >> @Cascade(CascadeType.ALL)
                    >> >> >> >> >> @IndexedEmbedded
                    >> >> >> >> >> private List<Video> Videos;
                    >> >> >> >> >>
                    >> >> >> >> >> VÍDEO:
                    >> >> >> >> >> @Entity
                    >> >> >> >> >> @Table(name = "TBL_VIDEO")
                    >> >> >> >> >> @Indexed
                    >> >> >> >> >> public class Video implements Serializable{
                    >> >> >> >> >>
                    >> >> >> >> >> @Id
                    >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                    >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                    >> >> >> >> >> private Long id;
                    >> >> >> >> >> @Column(name="VC_TITLE")
                    >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                    >> >> >> >> >> private String title;
                    >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                    >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                    >> >> >> >> >> private String description;
                    >> >> >> >> >> @Column(name="VC_URL")
                    >> >> >> >> >> private String url;
                    >> >> >> >> >> @Column(name="VC_REAL_PATH")
                    >> >> >> >> >> private String realPath;
                    >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                    >> >> >> >> >> private Long idAssinante;
                    >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                    >> >> >> >> >> private String dataUpload;
                    >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                    >> >> >> >> >> private String pathImage;
                    >> >> >> >> >>
                    >> >> >> >> >> @IndexedEmbedded
                    >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                    >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                    >> >> >> >> >> updatable=false)
                    >> >> >> >> >> @Fetch(FetchMode.JOIN)
                    >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                    >> >> >> >> >> private Assinante assinante;
                    >> >> >> >> >>
                    >> >> >> >> >> Deu erro:
                    >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                    >>Circular
                    >> >> >> >>reference.
                    >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root entity
                    >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                    >> >> >> >> >>
                    >> >> >> >> >>
                    >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                    >> >> >> >> >> Victor Hogemann
                    >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                    >> >><victor.hogemann%40gmail.com><victor.hogemann%
                    >> >> 40gmail.com>
                    >> >> >> <victor.hogemann%40gmail.com>
                    >> >> >> >> >><victor.hogemann%40gmail.com>>
                    >> >> >> >>
                    >> >> >> >> >> wrote:
                    >> >> >> >> >> > Anderson,
                    >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                    >>associação
                    >> >> >> >> >> >bi-direcional entre
                    >> >> >> >> >> > Assinante e Video, assim você pode a partir do Video
                    >> >>filtrar
                    >> >> >> >>pelo
                    >> >> >> >> >> >nome do
                    >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                    >>exemplo:
                    >> >> >> >> >> >
                    >> >> >> >> >> > TermQuery query = new TermQuery(new
                    >> >> >> >>Term("Video.assinante.nome",
                    >> >> >> >> >> >"Fulano"));
                    >> >> >> >> >> >FullTextQuery fullTextQuery =
                    >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                    >>Video.class);
                    >> >> >> >> >> > return fullTextQuery.list();
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> > Pelo que você escreveu a associação entre Assinante e
                    >> >>Vídeo
                    >> >> >>é
                    >> >> >> >> >> >one-to-many,
                    >> >> >> >> >> > então não vai ser uma mudança tão traumática assim no
                    >> >> >>código. O
                    >> >> >> >> >> >pulo-do-gato
                    >> >> >> >> >> > é que você vai ter que repetir os dados de Assinante
                    >>no
                    >> >> >>indice
                    >> >> >> >>de
                    >> >> >> >> >> >Vídeo,
                    >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                    >> >>@ContainedIn.
                    >> >> >> >> >> >
                    >> >> >> >> >> > Em Vídeo você vai ter:
                    >> >> >> >> >> >
                    >> >> >> >> >> > @IndexedEmbeded
                    >> >> >> >> >> > @OneToOne
                    >> >> >> >> >> > Assinante assinante;
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> > E em Assinante vai ficar:
                    >> >> >> >> >> >
                    >> >> >> >> >> > @ContainedIn
                    >> >> >> >> >> > @OneToMany
                    >> >> >> >> >> > List<Video> videos;
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search,
                    >>que
                    >> >> >> >> >>basicamente
                    >> >> >> >> >> >é um
                    >> >> >> >> >> > resumo traduzido da referência em inglês do hibernate
                    >> >> >>search.
                    >> >> >> >>No
                    >> >> >> >> >> >exemplo que
                    >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                    >>entidades
                    >> >> >> >> >>associadas:
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> > Espero ter ajudado, boa sorte!
                    >> >> >> >> >> >
                    >> >> >> >> >> > 2009/10/2 Anderson Moraes
                    >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                    >><amoraes%
                    >> 40tecmetal.com.br>
                    >> >><amoraes%
                    >> >> 40tecmetal.com.br> <amoraes%
                    >> >> >> 40tecmetal.com.br><amoraes%
                    >> >> >>
                    >> >> >> >> 40tecmetal.com.br>
                    >> >> >> >>
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> >>
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Pessoal, bom dia.
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro
                    >>vou
                    >> >> >> >> >>descrever
                    >> >> >> >> >> >>os
                    >> >> >> >> >> >> atributos da minha bean:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> BEAN Assinante:
                    >> >> >> >> >> >> id
                    >> >> >> >> >> >> nome
                    >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                    >>Collection<Video>
                    >> >> >> >>Videos;)
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> BEAN Video:
                    >> >> >> >> >> >> id
                    >> >> >> >> >> >> title
                    >> >> >> >> >> >> description
                    >> >> >> >> >> >> idAssinante
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Blz, até aí tudo bem.
                    >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas
                    >> >>duas
                    >> >> >> >> >>classes
                    >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                    >>atributo
                    >> >> >>"nome"
                    >> >> >> >>e
                    >> >> >> >> >>em
                    >> >> >> >> >> >> Video eu busco nos atributos "title" e "description",
                    >> >>segue
                    >> >> >>o
                    >> >> >> >> >>método
                    >> >> >> >> >> >> abaixou:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> ************** MÉTODO ********************
                    >> >> >> >> >> >> try{
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> final Session session =
                    >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                    >> >> >> >> >> >> final FullTextSession ftSession =
                    >> >> >> >> >> >> Search.getFullTextSession(session);
                    >> >> >> >> >> >> final List<Assinante> assinantes =
                    >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                    >> >> >> >> >> >> final List<Video> videos =
                    >> >> >> >> >> >> session.createCriteria(Video.class).list();
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> for(Assinante a : assinantes) {
                    >> >> >> >> >> >> ftSession.index(a);
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> for(Video v : videos) {
                    >> >> >> >> >> >> ftSession.index(v);
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> final String[] stopWords =
                    >> >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                    >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                    >> >> >> >> >>MultiFieldQueryParser(new
                    >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                    >> >> >> >> >> >>StopAnalyzer(stopWords));
                    >> >> >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
                    >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                    >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                    >>Assinante.class);
                    >> >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                    >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                    >> >> >> >> >> >>
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> }catch(Exception e){
                    >> >> >> >> >> >> e.printStackTrace();
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> ************** FIM MÉTODO ********************
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu
                    >>vou
                    >> >> >> >>destacar
                    >> >> >> >> >> >>abaixo
                    >> >> >> >> >> >> que eu informo em que campos procurar:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                    >> >> >> >> >>MultiFieldQueryParser(new
                    >> >> >> >> >> >> String[]{"nome","Videos.title","Videos.description"}
                    >>,
                    >> >>new
                    >> >> >> >> >> >> StopAnalyzer(stopWords));
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> if (list==null || list.size()==0){
                    >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                    >> >> >> >> >> >> }else{
                    >> >> >> >> >> >> for(Assinante a : list) {
                    >> >> >> >> >> >> System.out.println(a.getNome());
                    >> >> >> >> >> >> for (Video v : a.getVideos()) {
                    >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >> }
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                    >> >> >> >> >> >> Ex.:
                    >> >> >> >> >> >> Anderson Moraes
                    >> >> >> >> >> >> Vídeo 1
                    >> >> >> >> >> >> Vídeo 4
                    >> >> >> >> >> >> Vídeo 9
                    >> >> >> >> >> >> Elba Ramalho
                    >> >> >> >> >> >> Vídeo 3
                    >> >> >> >> >> >> Vídeo 7
                    >> >> >> >> >> >> Raul Seixas
                    >> >> >> >> >> >> Zé Ramalho
                    >> >> >> >> >> >> Vídeo 2
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no
                    >>caso
                    >> >>do
                    >> >> >> >>exemplo
                    >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                    >> >>Assinante.
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                    >> >>vídeos
                    >> >> >> >> >> >> (List<Video>), independente do Assinante, o Assinante
                    >>eu
                    >> >> >>uso
                    >> >> >> >>só
                    >> >> >> >> >>para
                    >> >> >> >> >> >> buscar pelo nome, por exemplo:
                    >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                    >> >> >>preenchido
                    >> >> >> >>com
                    >> >> >> >> >>os
                    >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                    >> >>recuperar
                    >> >> >>pelo
                    >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Na minha Action:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> No meu JSP:
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                    >> >> >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
                    >> >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                    >> >> >> >> >> >> <bean:write name="resulBusca" property="description"
                    >>/>
                    >> >> >> >> >> >> </logic:iterate>
                    >> >> >> >> >> >> </logic:notEmpty>
                    >> >> >> >> >> >> <logic:empty name="Busca_Video">
                    >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                    >> >> >> >> >> >> </logic:empty>
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> O meu problema é que eu não estou sabendo recuperar
                    >>em
                    >> >>cima
                    >> >> >>da
                    >> >> >> >> >>busca
                    >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Alguém pode me ajudar com isso???
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Grato desde já,
                    >> >> >> >> >> >>
                    >> >> >> >> >> >> Anderson Moraes
                    >> >> >> >> >> >>
                    >> >> >> >> >> >>
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> >
                    >> >> >> >> >> > --
                    >> >> >> >> >> > Victor Guilherme Hogemann
                    >> >> >> >> >> > http://victor.hogemann.eti.br
                    >> >> >> >> >>
                    >> >> >> >> >>
                    >> >> >> >> >>
                    >> >> >> >> >
                    >> >> >> >> >
                    >> >> >> >> >
                    >> >> >> >> > --
                    >> >> >> >> > Victor Guilherme Hogemann
                    >> >> >> >> > http://victor.hogemann.eti.br
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >>
                    >> >> >> >
                    >> >> >> >
                    >> >> >> >
                    >> >> >> > --
                    >> >> >> > Victor Guilherme Hogemann
                    >> >> >> > http://victor.hogemann.eti.br
                    >> >> >>
                    >> >> >>
                    >> >> >>
                    >> >> >
                    >> >> >
                    >> >> >
                    >> >> > --
                    >> >> > Victor Guilherme Hogemann
                    >> >> > http://victor.hogemann.eti.br
                    >> >>
                    >> >>
                    >> >>
                    >> >
                    >> >
                    >> >
                    >> > --
                    >> > Victor Guilherme Hogemann
                    >> > http://victor.hogemann.eti.br
                    >>
                    >>
                    >>
                    >
                    >
                    >
                    > --
                    > Victor Guilherme Hogemann
                    > http://victor.hogemann.eti.br
                  • Victor Hogemann
                    Anderson, Desculpe... esse método está feito pra usar o suporte a Hibernate do SpringFramework. Você vai ter que alterar ele se estiver usando o Hibernate
                    Message 9 of 21 , Oct 5, 2009
                    • 0 Attachment
                      Anderson,

                      Desculpe... esse método está feito pra usar o suporte a Hibernate do SpringFramework. Você vai ter que alterar ele se estiver usando o Hibernate "na unha".

                      [ ]s

                      2009/10/5 Anderson Moraes <amoraes@...>
                       

                      Está dando erro em "this.getHibernateTemplate().execute(new
                      HibernateCallback(){", diz que os métodos getHibernateTemplate() é
                      indefinido e que HibernateCallback() não pode ser definido para o
                      tipo.

                      On Mon, 5 Oct 2009 14:48:47 -0300


                      Victor Hogemann <victor.hogemann@...> wrote:
                      > Anderson,
                      > Pode fazer dentro de um main sim, e o método serve pra qualquer
                      >entidade
                      > indexada com hibernate-search... Por exemplo, basta chamar
                      > refreshIndex(Assinante.class) e refreshIndex(Video.class) no seu
                      >caso.
                      >
                      > [ ]s
                      >
                      > 2009/10/5 Anderson Moraes <amoraes@...>
                      >
                      >>
                      >>
                      >> Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro de
                      >>um
                      >> main mesmo???
                      >>
                      >> Esse exemplo que você me mandou serve para o meu caso ou tenho que
                      >> fazer alguma modificação???
                      >>
                      >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                      >>
                      >> Abraço,
                      >>
                      >> Anderson
                      >>
                      >> On Mon, 5 Oct 2009 11:08:55 -0300
                      >>
                      >> Victor Hogemann <victor.hogemann@...
                      >><victor.hogemann%40gmail.com>>
                      >> wrote:
                      >> > Anderson,
                      >> > Se você estiver fazendo uma aplicação Web pode colocar dentro de
                      >>um
                      >> >método
                      >> > de um controller qualquer, ou até mesmo dentro de um servlet
                      >> >separado... O
                      >> > importante é chama-lo sem ninguém estar fazendo alterações na
                      >> >persistência.
                      >> >
                      >> > [ ]s
                      >> >
                      >> > 2009/10/2 Anderson Moraes
                      >><amoraes@...<amoraes%40tecmetal.com.br>

                      >> >
                      >> >
                      >> >>
                      >> >>
                      >> >> Entendi sim, eu só não sei como fazer isso, como usar o método
                      >>que
                      >> >>vc
                      >> >> me mando, como chamar...
                      >> >>
                      >> >> Desde já muito obrigado pela força que está me dando.
                      >> >>
                      >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                      >> >>
                      >> >> Victor Hogemann
                      >><victor.hogemann@...<victor.hogemann%40gmail.com>
                      >> >><victor.hogemann%40gmail.com>>
                      >> >> wrote:
                      >> >> > Anderson,
                      >> >> > Imagine a seguinte situação... Sua aplicação está funcionando,
                      >>e
                      >> >>de
                      >> >> >repente
                      >> >> > alguma coisa sai errada e o seu servidor capota. Beleza, você
                      >>tem
                      >> >>o
                      >> >> >backup
                      >> >> > do seu banco de dados, mas e os índices do Hibernate Search?
                      >> >> >
                      >> >> > Claro, você poderia fazer backup desses também... mas imagine
                      >>que
                      >> >> >não tenha
                      >> >> > feito. Você vai precisar reconstruir seus índices a partir das
                      >> >> >entidades
                      >> >> > persistidas no banco, pra isso serve o método que eu te passei.
                      >> >> >
                      >> >> > Como você alterou o mapeamento das entidades no Hibernate
                      >>Search,
                      >> >> >logo mudou
                      >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                      >> >>novamente.
                      >> >> >
                      >> >> > Sacou?
                      >> >> >
                      >> >> > 2009/10/2 Anderson Moraes
                      >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

                      >> 40tecmetal.com.br>
                      >>
                      >> >> >
                      >> >> >
                      >> >> >>
                      >> >> >>
                      >> >> >> Não entendi como eu executo essa classe, em que momento...
                      >> >> >>
                      >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                      >> >> >>
                      >> >> >> Victor Hogemann
                      >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                      >> <victor.hogemann%40gmail.com>
                      >> >> >><victor.hogemann%40gmail.com>>
                      >> >> >> wrote:
                      >> >> >> > Anderson,
                      >> >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                      >> >> >>mapeamento
                      >> >> >> >os
                      >> >> >> > índices são criados novamente, e você precisa re-indexar as
                      >> >> >> >entidades que já
                      >> >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                      >> >>exemplo
                      >> >> >>de
                      >> >> >> >como
                      >> >> >> > fazer:
                      >> >> >> >
                      >> >> >> > public void refreshIndex(final Class entityClass) {
                      >> >> >> >
                      >> >> >> > this.getHibernateTemplate().execute(new HibernateCallback()
                      >>{
                      >> >> >> >
                      >> >> >> >
                      >> >> >> > public Object doInHibernate(Session session)
                      >> >> >> > throwsHibernateException, SQLException {
                      >> >> >>
                      >> >> >> >
                      >> >> >> > FullTextSession fullTextSession =
                      >> >> >> > Search.getFullTextSession(session);
                      >> >> >> >
                      >> >> >> > Criteria crit = session.createCriteria(entityClass);
                      >> >> >> >
                      >> >> >> > for (Object obj : crit.list()) {
                      >> >> >> >
                      >> >> >> > T entity = (T) obj;
                      >> >> >> >
                      >> >> >> > fullTextSession.index(entity);
                      >> >> >> >
                      >> >> >> > }
                      >> >> >> >
                      >> >> >> > return null;
                      >> >> >> >
                      >> >> >> >
                      >> >> >> > }
                      >> >> >> >
                      >> >> >> > });
                      >> >> >> >
                      >> >> >> > }
                      >> >> >> >
                      >> >> >> >
                      >> >> >> > [ ]s
                      >> >> >> >
                      >> >> >> > 2009/10/2 Anderson Moraes
                      >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                      >> 40tecmetal.com.br><amoraes%
                      >>
                      >> >> 40tecmetal.com.br>
                      >> >>
                      >> >> >> >
                      >> >> >> >
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz,
                      >>abaixo
                      >> >> >>vou
                      >> >> >> >> mostrar o SQL que sai no console:
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> try{
                      >> >> >> >>
                      >> >> >> >> final Session session =
                      >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                      >> >> >> >> final FullTextSession ftSession =
                      >> >> >> >> Search.getFullTextSession(session);
                      >> >> >> >> final List<Video> videos =
                      >> >> >> >> session.createCriteria(Video.class).list();
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> for(Video v : videos) {
                      >> >> >> >> ftSession.index(v);
                      >> >> >> >> }
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> final String[] stopWords =
                      >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                      >> >> >> >> final MultiFieldQueryParser parser = new
                      >> >> >> >> MultiFieldQueryParser(new
                      >> >> >> >> String[]{"Video.assinante.nome","Video.description"} , new
                      >> >> >> >> StopAnalyzer(stopWords));
                      >> >> >> >> final Query query = parser.parse("Moraes");
                      >> >> >> >> final FullTextQuery fullTextQuery =
                      >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                      >> >> >> >>
                      >> >> >> >> final List<Video> list = fullTextQuery.list();
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> HibernateUtil.getSessionFactory().close();
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> if (list==null || list.size()==0){
                      >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                      >> >> >> >> }else{
                      >> >> >> >> for (Video v : list) {
                      >> >> >> >> System.out.println(" " + v.getTitle());
                      >> >> >> >> }
                      >> >> >> >> }
                      >> >> >> >>
                      >> >> >> >> }catch(Exception e){
                      >> >> >> >> e.printStackTrace();
                      >> >> >> >> }
                      >> >> >> >> }
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >> CONSOLE:
                      >> >> >> >> Hibernate:
                      >> >> >> >>
                      >> >> >> >> select
                      >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                      >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                      >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                      >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                      >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                      >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                      >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                      >> >> >> >> this_.VC_URL as VC8_1_1_,
                      >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                      >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                      >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                      >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                      >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                      >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                      >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                      >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                      >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                      >> >> >> >> from
                      >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE assinante2_
                      >>on
                      >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                      >> >> >> >>
                      >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                      >> >> >> >>
                      >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                      >> >> >> >>
                      >> >> >> >> Victor Hogemann
                      >> >> >><victor.hogemann@...
                      >><victor.hogemann%40gmail.com><victor.hogemann%
                      >> 40gmail.com>
                      >> >> <victor.hogemann%40gmail.com>
                      >> >> >> >><victor.hogemann%40gmail.com>>
                      >> >> >> >> wrote:
                      >> >> >> >> > Anderson,
                      >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                      >>vídeos
                      >> >>do
                      >> >> >> >> >Assinante:
                      >> >> >> >> >
                      >> >> >> >> > @ContainedIn
                      >> >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                      >> >> >> >> > @Cascade(CascadeType.ALL)
                      >> >> >> >> > @IndexedEmbedded
                      >> >> >> >> > private List<Video> Videos;
                      >> >> >> >> >
                      >> >> >> >> >
                      >> >> >> >> > [ ]s
                      >> >> >> >> >
                      >> >> >> >> > 2009/10/2 Anderson Moraes
                      >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                      >><amoraes%
                      >> 40tecmetal.com.br> <amoraes%
                      >> >> 40tecmetal.com.br><amoraes%
                      >> >>
                      >> >> >> 40tecmetal.com.br>
                      >> >> >>
                      >> >> >> >> >
                      >> >> >> >> >
                      >> >> >> >> >>
                      >> >> >> >> >>
                      >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                      >>Classes:
                      >> >> >> >> >>
                      >> >> >> >> >> ASSINANTE:
                      >> >> >> >> >> @Entity
                      >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                      >> >> >> >> >> @Indexed
                      >> >> >> >> >> public class Assinante extends PersistentObject
                      >>implements
                      >> >> >> >> >> Serializable{
                      >> >> >> >> >>
                      >> >> >> >> >> @Id
                      >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                      >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                      >> >> >> >> >> private Long id;
                      >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                      >> >> >> >> >> private String email;
                      >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                      >> >> >> >> >> private String password;
                      >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                      >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                      >> >> >> >> >> private String nome;
                      >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                      >> >> >> >> >> private String cpf;
                      >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                      >> >> >> >> >> private String endereco;
                      >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                      >> >> >> >> >> private String cidade;
                      >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                      >> >> >> >> >> private String estado;
                      >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                      >> >> >> >> >> private String dataCadastro;
                      >> >> >> >> >>
                      >> >> >> >> >> @ContainedIn
                      >> >> >> >> >> @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                      >> >> >> >> >> @Cascade(CascadeType.ALL)
                      >> >> >> >> >> @IndexedEmbedded
                      >> >> >> >> >> private List<Video> Videos;
                      >> >> >> >> >>
                      >> >> >> >> >> VÍDEO:
                      >> >> >> >> >> @Entity
                      >> >> >> >> >> @Table(name = "TBL_VIDEO")
                      >> >> >> >> >> @Indexed
                      >> >> >> >> >> public class Video implements Serializable{
                      >> >> >> >> >>
                      >> >> >> >> >> @Id
                      >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                      >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                      >> >> >> >> >> private Long id;
                      >> >> >> >> >> @Column(name="VC_TITLE")
                      >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                      >> >> >> >> >> private String title;
                      >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                      >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                      >> >> >> >> >> private String description;
                      >> >> >> >> >> @Column(name="VC_URL")
                      >> >> >> >> >> private String url;
                      >> >> >> >> >> @Column(name="VC_REAL_PATH")
                      >> >> >> >> >> private String realPath;
                      >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                      >> >> >> >> >> private Long idAssinante;
                      >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                      >> >> >> >> >> private String dataUpload;
                      >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                      >> >> >> >> >> private String pathImage;
                      >> >> >> >> >>
                      >> >> >> >> >> @IndexedEmbedded
                      >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                      >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                      >> >> >> >> >> updatable=false)
                      >> >> >> >> >> @Fetch(FetchMode.JOIN)
                      >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                      >> >> >> >> >> private Assinante assinante;
                      >> >> >> >> >>
                      >> >> >> >> >> Deu erro:
                      >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                      >>Circular
                      >> >> >> >>reference.
                      >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root entity
                      >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                      >> >> >> >> >>
                      >> >> >> >> >>
                      >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                      >> >> >> >> >> Victor Hogemann
                      >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                      >> >><victor.hogemann%40gmail.com><victor.hogemann%
                      >> >> 40gmail.com>
                      >> >> >> <victor.hogemann%40gmail.com>
                      >> >> >> >> >><victor.hogemann%40gmail.com>>
                      >> >> >> >>
                      >> >> >> >> >> wrote:
                      >> >> >> >> >> > Anderson,
                      >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                      >>associação
                      >> >> >> >> >> >bi-direcional entre
                      >> >> >> >> >> > Assinante e Video, assim você pode a partir do Video
                      >> >>filtrar
                      >> >> >> >>pelo
                      >> >> >> >> >> >nome do
                      >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                      >>exemplo:
                      >> >> >> >> >> >
                      >> >> >> >> >> > TermQuery query = new TermQuery(new
                      >> >> >> >>Term("Video.assinante.nome",
                      >> >> >> >> >> >"Fulano"));
                      >> >> >> >> >> >FullTextQuery fullTextQuery =
                      >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                      >>Video.class);
                      >> >> >> >> >> > return fullTextQuery.list();
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> > Pelo que você escreveu a associação entre Assinante e
                      >> >>Vídeo
                      >> >> >>é
                      >> >> >> >> >> >one-to-many,
                      >> >> >> >> >> > então não vai ser uma mudança tão traumática assim no
                      >> >> >>código. O
                      >> >> >> >> >> >pulo-do-gato
                      >> >> >> >> >> > é que você vai ter que repetir os dados de Assinante
                      >>no
                      >> >> >>indice
                      >> >> >> >>de
                      >> >> >> >> >> >Vídeo,
                      >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                      >> >>@ContainedIn.
                      >> >> >> >> >> >
                      >> >> >> >> >> > Em Vídeo você vai ter:
                      >> >> >> >> >> >
                      >> >> >> >> >> > @IndexedEmbeded
                      >> >> >> >> >> > @OneToOne
                      >> >> >> >> >> > Assinante assinante;
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> > E em Assinante vai ficar:
                      >> >> >> >> >> >
                      >> >> >> >> >> > @ContainedIn
                      >> >> >> >> >> > @OneToMany
                      >> >> >> >> >> > List<Video> videos;
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search,
                      >>que
                      >> >> >> >> >>basicamente
                      >> >> >> >> >> >é um
                      >> >> >> >> >> > resumo traduzido da referência em inglês do hibernate
                      >> >> >>search.
                      >> >> >> >>No
                      >> >> >> >> >> >exemplo que
                      >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                      >>entidades
                      >> >> >> >> >>associadas:
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> > Espero ter ajudado, boa sorte!
                      >> >> >> >> >> >
                      >> >> >> >> >> > 2009/10/2 Anderson Moraes
                      >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                      >><amoraes%
                      >> 40tecmetal.com.br>
                      >> >><amoraes%
                      >> >> 40tecmetal.com.br> <amoraes%
                      >> >> >> 40tecmetal.com.br><amoraes%
                      >> >> >>
                      >> >> >> >> 40tecmetal.com.br>
                      >> >> >> >>
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> >>
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Pessoal, bom dia.
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Vou explicar o que estou fazendo por parte, primeiro
                      >>vou
                      >> >> >> >> >>descrever
                      >> >> >> >> >> >>os
                      >> >> >> >> >> >> atributos da minha bean:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> BEAN Assinante:
                      >> >> >> >> >> >> id
                      >> >> >> >> >> >> nome
                      >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                      >>Collection<Video>
                      >> >> >> >>Videos;)
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> BEAN Video:
                      >> >> >> >> >> >> id
                      >> >> >> >> >> >> title
                      >> >> >> >> >> >> description
                      >> >> >> >> >> >> idAssinante
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Blz, até aí tudo bem.
                      >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca nas
                      >> >>duas
                      >> >> >> >> >>classes
                      >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                      >>atributo
                      >> >> >>"nome"
                      >> >> >> >>e
                      >> >> >> >> >>em
                      >> >> >> >> >> >> Video eu busco nos atributos "title" e "description",
                      >> >>segue
                      >> >> >>o
                      >> >> >> >> >>método
                      >> >> >> >> >> >> abaixou:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> ************** MÉTODO ********************
                      >> >> >> >> >> >> try{
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> final Session session =
                      >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                      >> >> >> >> >> >> final FullTextSession ftSession =
                      >> >> >> >> >> >> Search.getFullTextSession(session);
                      >> >> >> >> >> >> final List<Assinante> assinantes =
                      >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                      >> >> >> >> >> >> final List<Video> videos =
                      >> >> >> >> >> >> session.createCriteria(Video.class).list();
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> for(Assinante a : assinantes) {
                      >> >> >> >> >> >> ftSession.index(a);
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> for(Video v : videos) {
                      >> >> >> >> >> >> ftSession.index(v);
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> final String[] stopWords =
                      >> >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                      >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                      >> >> >> >> >>MultiFieldQueryParser(new
                      >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                      >> >> >> >> >> >>StopAnalyzer(stopWords));
                      >> >> >> >> >> >> final Query query = parser.parse("Moraes Flamengo");
                      >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                      >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                      >>Assinante.class);
                      >> >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                      >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                      >> >> >> >> >> >>
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> }catch(Exception e){
                      >> >> >> >> >> >> e.printStackTrace();
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> ************** FIM MÉTODO ********************
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu
                      >>vou
                      >> >> >> >>destacar
                      >> >> >> >> >> >>abaixo
                      >> >> >> >> >> >> que eu informo em que campos procurar:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                      >> >> >> >> >>MultiFieldQueryParser(new
                      >> >> >> >> >> >> String[]{"nome","Videos.title","Videos.description"}
                      >>,
                      >> >>new
                      >> >> >> >> >> >> StopAnalyzer(stopWords));
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> if (list==null || list.size()==0){
                      >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                      >> >> >> >> >> >> }else{
                      >> >> >> >> >> >> for(Assinante a : list) {
                      >> >> >> >> >> >> System.out.println(a.getNome());
                      >> >> >> >> >> >> for (Video v : a.getVideos()) {
                      >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >> }
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                      >> >> >> >> >> >> Ex.:
                      >> >> >> >> >> >> Anderson Moraes
                      >> >> >> >> >> >> Vídeo 1
                      >> >> >> >> >> >> Vídeo 4
                      >> >> >> >> >> >> Vídeo 9
                      >> >> >> >> >> >> Elba Ramalho
                      >> >> >> >> >> >> Vídeo 3
                      >> >> >> >> >> >> Vídeo 7
                      >> >> >> >> >> >> Raul Seixas
                      >> >> >> >> >> >> Zé Ramalho
                      >> >> >> >> >> >> Vídeo 2
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no
                      >>caso
                      >> >>do
                      >> >> >> >>exemplo
                      >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                      >> >>Assinante.
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                      >> >>vídeos
                      >> >> >> >> >> >> (List<Video>), independente do Assinante, o Assinante
                      >>eu
                      >> >> >>uso
                      >> >> >> >>só
                      >> >> >> >> >>para
                      >> >> >> >> >> >> buscar pelo nome, por exemplo:
                      >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                      >> >> >>preenchido
                      >> >> >> >>com
                      >> >> >> >> >>os
                      >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                      >> >>recuperar
                      >> >> >>pelo
                      >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Na minha Action:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> No meu JSP:
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                      >> >> >> >> >> >> <logic:iterate id="resulBusca" name="Busca_Videos">
                      >> >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                      >> >> >> >> >> >> <bean:write name="resulBusca" property="description"
                      >>/>
                      >> >> >> >> >> >> </logic:iterate>
                      >> >> >> >> >> >> </logic:notEmpty>
                      >> >> >> >> >> >> <logic:empty name="Busca_Video">
                      >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                      >> >> >> >> >> >> </logic:empty>
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> O meu problema é que eu não estou sabendo recuperar
                      >>em
                      >> >>cima
                      >> >> >>da
                      >> >> >> >> >>busca
                      >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Alguém pode me ajudar com isso???
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Grato desde já,
                      >> >> >> >> >> >>
                      >> >> >> >> >> >> Anderson Moraes
                      >> >> >> >> >> >>
                      >> >> >> >> >> >>
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> >
                      >> >> >> >> >> > --
                      >> >> >> >> >> > Victor Guilherme Hogemann
                      >> >> >> >> >> > http://victor.hogemann.eti.br
                      >> >> >> >> >>
                      >> >> >> >> >>
                      >> >> >> >> >>
                      >> >> >> >> >
                      >> >> >> >> >
                      >> >> >> >> >
                      >> >> >> >> > --
                      >> >> >> >> > Victor Guilherme Hogemann
                      >> >> >> >> > http://victor.hogemann.eti.br
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >>
                      >> >> >> >
                      >> >> >> >
                      >> >> >> >
                      >> >> >> > --
                      >> >> >> > Victor Guilherme Hogemann
                      >> >> >> > http://victor.hogemann.eti.br
                      >> >> >>
                      >> >> >>
                      >> >> >>
                      >> >> >
                      >> >> >
                      >> >> >
                      >> >> > --
                      >> >> > Victor Guilherme Hogemann
                      >> >> > http://victor.hogemann.eti.br
                      >> >>
                      >> >>
                      >> >>
                      >> >
                      >> >
                      >> >
                      >> > --
                      >> > Victor Guilherme Hogemann
                      >> > http://victor.hogemann.eti.br
                      >>
                      >>
                      >>
                      >
                      >
                      >
                      > --
                      > Victor Guilherme Hogemann
                      > http://victor.hogemann.eti.br




                      --
                      Victor Guilherme Hogemann
                      http://victor.hogemann.eti.br
                    • Anderson Moraes
                      Estou utilizando STRUTS, como ficaria o mesmo nesse caso??? On Mon, 5 Oct 2009 17:47:21 -0300
                      Message 10 of 21 , Oct 5, 2009
                      • 0 Attachment
                        Estou utilizando STRUTS, como ficaria o mesmo nesse caso???

                        On Mon, 5 Oct 2009 17:47:21 -0300
                        Victor Hogemann <victor.hogemann@...> wrote:
                        > Anderson,
                        > Desculpe... esse método está feito pra usar o suporte a Hibernate do
                        > SpringFramework. Você vai ter que alterar ele se estiver usando o
                        >Hibernate
                        > "na unha".
                        >
                        > [ ]s
                        >
                        > 2009/10/5 Anderson Moraes <amoraes@...>
                        >
                        >>
                        >>
                        >> Está dando erro em "this.getHibernateTemplate().execute(new
                        >> HibernateCallback(){", diz que os métodos getHibernateTemplate() é
                        >> indefinido e que HibernateCallback() não pode ser definido para o
                        >> tipo.
                        >>
                        >> On Mon, 5 Oct 2009 14:48:47 -0300
                        >>
                        >> Victor Hogemann <victor.hogemann@...
                        >><victor.hogemann%40gmail.com>>
                        >> wrote:
                        >> > Anderson,
                        >> > Pode fazer dentro de um main sim, e o método serve pra qualquer
                        >> >entidade
                        >> > indexada com hibernate-search... Por exemplo, basta chamar
                        >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no seu
                        >> >caso.
                        >> >
                        >> > [ ]s
                        >> >
                        >> > 2009/10/5 Anderson Moraes
                        >><amoraes@...<amoraes%40tecmetal.com.br>
                        >> >
                        >> >
                        >> >>
                        >> >>
                        >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro
                        >>de
                        >> >>um
                        >> >> main mesmo???
                        >> >>
                        >> >> Esse exemplo que você me mandou serve para o meu caso ou tenho
                        >>que
                        >> >> fazer alguma modificação???
                        >> >>
                        >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                        >> >>
                        >> >> Abraço,
                        >> >>
                        >> >> Anderson
                        >> >>
                        >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                        >> >>
                        >> >> Victor Hogemann
                        >><victor.hogemann@...<victor.hogemann%40gmail.com>
                        >> >><victor.hogemann%40gmail.com>>
                        >> >> wrote:
                        >> >> > Anderson,
                        >> >> > Se você estiver fazendo uma aplicação Web pode colocar dentro
                        >>de
                        >> >>um
                        >> >> >método
                        >> >> > de um controller qualquer, ou até mesmo dentro de um servlet
                        >> >> >separado... O
                        >> >> > importante é chama-lo sem ninguém estar fazendo alterações na
                        >> >> >persistência.
                        >> >> >
                        >> >> > [ ]s
                        >> >> >
                        >> >> > 2009/10/2 Anderson Moraes
                        >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                        >> 40tecmetal.com.br>
                        >>
                        >> >> >
                        >> >> >
                        >> >> >>
                        >> >> >>
                        >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o método
                        >> >>que
                        >> >> >>vc
                        >> >> >> me mando, como chamar...
                        >> >> >>
                        >> >> >> Desde já muito obrigado pela força que está me dando.
                        >> >> >>
                        >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                        >> >> >>
                        >> >> >> Victor Hogemann
                        >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                        >> <victor.hogemann%40gmail.com>
                        >> >> >><victor.hogemann%40gmail.com>>
                        >> >> >> wrote:
                        >> >> >> > Anderson,
                        >> >> >> > Imagine a seguinte situação... Sua aplicação está
                        >>funcionando,
                        >> >>e
                        >> >> >>de
                        >> >> >> >repente
                        >> >> >> > alguma coisa sai errada e o seu servidor capota. Beleza,
                        >>você
                        >> >>tem
                        >> >> >>o
                        >> >> >> >backup
                        >> >> >> > do seu banco de dados, mas e os índices do Hibernate Search?
                        >> >> >> >
                        >> >> >> > Claro, você poderia fazer backup desses também... mas
                        >>imagine
                        >> >>que
                        >> >> >> >não tenha
                        >> >> >> > feito. Você vai precisar reconstruir seus índices a partir
                        >>das
                        >> >> >> >entidades
                        >> >> >> > persistidas no banco, pra isso serve o método que eu te
                        >>passei.
                        >> >> >> >
                        >> >> >> > Como você alterou o mapeamento das entidades no Hibernate
                        >> >>Search,
                        >> >> >> >logo mudou
                        >> >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                        >> >> >>novamente.
                        >> >> >> >
                        >> >> >> > Sacou?
                        >> >> >> >
                        >> >> >> > 2009/10/2 Anderson Moraes
                        >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                        >> 40tecmetal.com.br><amoraes%
                        >>
                        >> >> 40tecmetal.com.br>
                        >> >>
                        >> >> >> >
                        >> >> >> >
                        >> >> >> >>
                        >> >> >> >>
                        >> >> >> >> Não entendi como eu executo essa classe, em que momento...
                        >> >> >> >>
                        >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                        >> >> >> >>
                        >> >> >> >> Victor Hogemann
                        >> >> >><victor.hogemann@...
                        >><victor.hogemann%40gmail.com><victor.hogemann%
                        >> 40gmail.com>
                        >> >> <victor.hogemann%40gmail.com>
                        >> >> >> >><victor.hogemann%40gmail.com>>
                        >> >> >> >> wrote:
                        >> >> >> >> > Anderson,
                        >> >> >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                        >> >> >> >>mapeamento
                        >> >> >> >> >os
                        >> >> >> >> > índices são criados novamente, e você precisa re-indexar
                        >>as
                        >> >> >> >> >entidades que já
                        >> >> >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                        >> >> >>exemplo
                        >> >> >> >>de
                        >> >> >> >> >como
                        >> >> >> >> > fazer:
                        >> >> >> >> >
                        >> >> >> >> > public void refreshIndex(final Class entityClass) {
                        >> >> >> >> >
                        >> >> >> >> > this.getHibernateTemplate().execute(new
                        >>HibernateCallback()
                        >> >>{
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> > public Object doInHibernate(Session session)
                        >> >> >> >> > throwsHibernateException, SQLException {
                        >> >> >> >>
                        >> >> >> >> >
                        >> >> >> >> > FullTextSession fullTextSession =
                        >> >> >> >> > Search.getFullTextSession(session);
                        >> >> >> >> >
                        >> >> >> >> > Criteria crit = session.createCriteria(entityClass);
                        >> >> >> >> >
                        >> >> >> >> > for (Object obj : crit.list()) {
                        >> >> >> >> >
                        >> >> >> >> > T entity = (T) obj;
                        >> >> >> >> >
                        >> >> >> >> > fullTextSession.index(entity);
                        >> >> >> >> >
                        >> >> >> >> > }
                        >> >> >> >> >
                        >> >> >> >> > return null;
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> > }
                        >> >> >> >> >
                        >> >> >> >> > });
                        >> >> >> >> >
                        >> >> >> >> > }
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> > [ ]s
                        >> >> >> >> >
                        >> >> >> >> > 2009/10/2 Anderson Moraes
                        >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                        >><amoraes%
                        >> 40tecmetal.com.br> <amoraes%
                        >> >> 40tecmetal.com.br><amoraes%
                        >> >>
                        >> >> >> 40tecmetal.com.br>
                        >> >> >>
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz,
                        >> >>abaixo
                        >> >> >> >>vou
                        >> >> >> >> >> mostrar o SQL que sai no console:
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> try{
                        >> >> >> >> >>
                        >> >> >> >> >> final Session session =
                        >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                        >> >> >> >> >> final FullTextSession ftSession =
                        >> >> >> >> >> Search.getFullTextSession(session);
                        >> >> >> >> >> final List<Video> videos =
                        >> >> >> >> >> session.createCriteria(Video.class).list();
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> for(Video v : videos) {
                        >> >> >> >> >> ftSession.index(v);
                        >> >> >> >> >> }
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> final String[] stopWords =
                        >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                        >> >> >> >> >> final MultiFieldQueryParser parser = new
                        >> >> >> >> >> MultiFieldQueryParser(new
                        >> >> >> >> >> String[]{"Video.assinante.nome","Video.description"} ,
                        >>new
                        >> >> >> >> >> StopAnalyzer(stopWords));
                        >> >> >> >> >> final Query query = parser.parse("Moraes");
                        >> >> >> >> >> final FullTextQuery fullTextQuery =
                        >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                        >> >> >> >> >>
                        >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> if (list==null || list.size()==0){
                        >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                        >> >> >> >> >> }else{
                        >> >> >> >> >> for (Video v : list) {
                        >> >> >> >> >> System.out.println(" " + v.getTitle());
                        >> >> >> >> >> }
                        >> >> >> >> >> }
                        >> >> >> >> >>
                        >> >> >> >> >> }catch(Exception e){
                        >> >> >> >> >> e.printStackTrace();
                        >> >> >> >> >> }
                        >> >> >> >> >> }
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >> CONSOLE:
                        >> >> >> >> >> Hibernate:
                        >> >> >> >> >>
                        >> >> >> >> >> select
                        >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                        >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                        >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                        >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                        >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                        >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                        >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                        >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                        >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                        >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                        >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                        >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                        >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                        >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                        >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                        >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                        >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                        >> >> >> >> >> from
                        >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                        >>assinante2_
                        >> >>on
                        >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                        >> >> >> >> >>
                        >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                        >> >> >> >> >>
                        >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                        >> >> >> >> >>
                        >> >> >> >> >> Victor Hogemann
                        >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                        >> >><victor.hogemann%40gmail.com><victor.hogemann%
                        >> >> 40gmail.com>
                        >> >> >> <victor.hogemann%40gmail.com>
                        >> >> >> >> >><victor.hogemann%40gmail.com>>
                        >> >> >> >> >> wrote:
                        >> >> >> >> >> > Anderson,
                        >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                        >> >>vídeos
                        >> >> >>do
                        >> >> >> >> >> >Assinante:
                        >> >> >> >> >> >
                        >> >> >> >> >> > @ContainedIn
                        >> >> >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                        >> >> >> >> >> > @Cascade(CascadeType.ALL)
                        >> >> >> >> >> > @IndexedEmbedded
                        >> >> >> >> >> > private List<Video> Videos;
                        >> >> >> >> >> >
                        >> >> >> >> >> >
                        >> >> >> >> >> > [ ]s
                        >> >> >> >> >> >
                        >> >> >> >> >> > 2009/10/2 Anderson Moraes
                        >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                        >><amoraes%
                        >> 40tecmetal.com.br>
                        >> >><amoraes%
                        >> >> 40tecmetal.com.br> <amoraes%
                        >> >> >> 40tecmetal.com.br><amoraes%
                        >> >> >>
                        >> >> >> >> 40tecmetal.com.br>
                        >> >> >> >>
                        >> >> >> >> >> >
                        >> >> >> >> >> >
                        >> >> >> >> >> >>
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                        >> >>Classes:
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> ASSINANTE:
                        >> >> >> >> >> >> @Entity
                        >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                        >> >> >> >> >> >> @Indexed
                        >> >> >> >> >> >> public class Assinante extends PersistentObject
                        >> >>implements
                        >> >> >> >> >> >> Serializable{
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> @Id
                        >> >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                        >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                        >> >> >> >> >> >> private Long id;
                        >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                        >> >> >> >> >> >> private String email;
                        >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                        >> >> >> >> >> >> private String password;
                        >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                        >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                        >> >> >> >> >> >> private String nome;
                        >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                        >> >> >> >> >> >> private String cpf;
                        >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                        >> >> >> >> >> >> private String endereco;
                        >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                        >> >> >> >> >> >> private String cidade;
                        >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                        >> >> >> >> >> >> private String estado;
                        >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                        >> >> >> >> >> >> private String dataCadastro;
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> @ContainedIn
                        >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                        >>fetch=FetchType.LAZY)
                        >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                        >> >> >> >> >> >> @IndexedEmbedded
                        >> >> >> >> >> >> private List<Video> Videos;
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> VÍDEO:
                        >> >> >> >> >> >> @Entity
                        >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                        >> >> >> >> >> >> @Indexed
                        >> >> >> >> >> >> public class Video implements Serializable{
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> @Id
                        >> >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                        >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                        >> >> >> >> >> >> private Long id;
                        >> >> >> >> >> >> @Column(name="VC_TITLE")
                        >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                        >> >> >> >> >> >> private String title;
                        >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                        >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                        >> >> >> >> >> >> private String description;
                        >> >> >> >> >> >> @Column(name="VC_URL")
                        >> >> >> >> >> >> private String url;
                        >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                        >> >> >> >> >> >> private String realPath;
                        >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                        >> >> >> >> >> >> private Long idAssinante;
                        >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                        >> >> >> >> >> >> private String dataUpload;
                        >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                        >> >> >> >> >> >> private String pathImage;
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> @IndexedEmbedded
                        >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                        >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                        >> >> >> >> >> >> updatable=false)
                        >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                        >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                        >> >> >> >> >> >> private Assinante assinante;
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> Deu erro:
                        >> >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                        >> >>Circular
                        >> >> >> >> >>reference.
                        >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                        >>entity
                        >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                        >> >> >> >> >> >>
                        >> >> >> >> >> >>
                        >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                        >> >> >> >> >> >> Victor Hogemann
                        >> >> >> >> >><victor.hogemann@...
                        >><victor.hogemann%40gmail.com><victor.hogemann%
                        >> 40gmail.com>
                        >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                        >> >> >> 40gmail.com>
                        >> >> >> >> <victor.hogemann%40gmail.com>
                        >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                        >> >> >> >> >>
                        >> >> >> >> >> >> wrote:
                        >> >> >> >> >> >> > Anderson,
                        >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                        >> >>associação
                        >> >> >> >> >> >> >bi-direcional entre
                        >> >> >> >> >> >> > Assinante e Video, assim você pode a partir do
                        >>Video
                        >> >> >>filtrar
                        >> >> >> >> >>pelo
                        >> >> >> >> >> >> >nome do
                        >> >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                        >> >>exemplo:
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                        >> >> >> >> >>Term("Video.assinante.nome",
                        >> >> >> >> >> >> >"Fulano"));
                        >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                        >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                        >> >>Video.class);
                        >> >> >> >> >> >> > return fullTextQuery.list();
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > Pelo que você escreveu a associação entre Assinante
                        >>e
                        >> >> >>Vídeo
                        >> >> >> >>é
                        >> >> >> >> >> >> >one-to-many,
                        >> >> >> >> >> >> > então não vai ser uma mudança tão traumática assim
                        >>no
                        >> >> >> >>código. O
                        >> >> >> >> >> >> >pulo-do-gato
                        >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                        >>Assinante
                        >> >>no
                        >> >> >> >>indice
                        >> >> >> >> >>de
                        >> >> >> >> >> >> >Vídeo,
                        >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                        >> >> >>@ContainedIn.
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > Em Vídeo você vai ter:
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > @IndexedEmbeded
                        >> >> >> >> >> >> > @OneToOne
                        >> >> >> >> >> >> > Assinante assinante;
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > E em Assinante vai ficar:
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > @ContainedIn
                        >> >> >> >> >> >> > @OneToMany
                        >> >> >> >> >> >> > List<Video> videos;
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search,
                        >> >>que
                        >> >> >> >> >> >>basicamente
                        >> >> >> >> >> >> >é um
                        >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                        >>hibernate
                        >> >> >> >>search.
                        >> >> >> >> >>No
                        >> >> >> >> >> >> >exemplo que
                        >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                        >> >>entidades
                        >> >> >> >> >> >>associadas:
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                        >> >> >> >> >> >><amoraes@...
                        >><amoraes%40tecmetal.com.br><amoraes%
                        >> 40tecmetal.com.br>
                        >> >><amoraes%
                        >> >> 40tecmetal.com.br>
                        >> >> >><amoraes%
                        >> >> >> 40tecmetal.com.br> <amoraes%
                        >> >> >> >> 40tecmetal.com.br><amoraes%
                        >> >> >> >>
                        >> >> >> >> >> 40tecmetal.com.br>
                        >> >> >> >> >>
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Pessoal, bom dia.
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                        >>primeiro
                        >> >>vou
                        >> >> >> >> >> >>descrever
                        >> >> >> >> >> >> >>os
                        >> >> >> >> >> >> >> atributos da minha bean:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> BEAN Assinante:
                        >> >> >> >> >> >> >> id
                        >> >> >> >> >> >> >> nome
                        >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                        >> >>Collection<Video>
                        >> >> >> >> >>Videos;)
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> BEAN Video:
                        >> >> >> >> >> >> >> id
                        >> >> >> >> >> >> >> title
                        >> >> >> >> >> >> >> description
                        >> >> >> >> >> >> >> idAssinante
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Blz, até aí tudo bem.
                        >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca
                        >>nas
                        >> >> >>duas
                        >> >> >> >> >> >>classes
                        >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                        >> >>atributo
                        >> >> >> >>"nome"
                        >> >> >> >> >>e
                        >> >> >> >> >> >>em
                        >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                        >>"description",
                        >> >> >>segue
                        >> >> >> >>o
                        >> >> >> >> >> >>método
                        >> >> >> >> >> >> >> abaixou:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> ************** MÉTODO ********************
                        >> >> >> >> >> >> >> try{
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> final Session session =
                        >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                        >> >> >> >> >> >> >> final FullTextSession ftSession =
                        >> >> >> >> >> >> >> Search.getFullTextSession(session);
                        >> >> >> >> >> >> >> final List<Assinante> assinantes =
                        >> >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                        >> >> >> >> >> >> >> final List<Video> videos =
                        >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                        >> >> >> >> >> >> >> ftSession.index(a);
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> for(Video v : videos) {
                        >> >> >> >> >> >> >> ftSession.index(v);
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> final String[] stopWords =
                        >> >> >> >> >> >> >>
                        >>{"de","do","da","dos","das","a","o","na","no","em"};
                        >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                        >> >> >> >> >> >>MultiFieldQueryParser(new
                        >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                        >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                        >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                        >>Flamengo");
                        >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                        >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                        >> >>Assinante.class);
                        >> >> >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                        >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> }catch(Exception e){
                        >> >> >> >> >> >> >> e.printStackTrace();
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> ************** FIM MÉTODO ********************
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu
                        >> >>vou
                        >> >> >> >> >>destacar
                        >> >> >> >> >> >> >>abaixo
                        >> >> >> >> >> >> >> que eu informo em que campos procurar:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                        >> >> >> >> >> >>MultiFieldQueryParser(new
                        >> >> >> >> >> >> >>
                        >>String[]{"nome","Videos.title","Videos.description"}
                        >> >>,
                        >> >> >>new
                        >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> if (list==null || list.size()==0){
                        >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                        >> >> >> >> >> >> >> }else{
                        >> >> >> >> >> >> >> for(Assinante a : list) {
                        >> >> >> >> >> >> >> System.out.println(a.getNome());
                        >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                        >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >> }
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                        >> >> >> >> >> >> >> Ex.:
                        >> >> >> >> >> >> >> Anderson Moraes
                        >> >> >> >> >> >> >> Vídeo 1
                        >> >> >> >> >> >> >> Vídeo 4
                        >> >> >> >> >> >> >> Vídeo 9
                        >> >> >> >> >> >> >> Elba Ramalho
                        >> >> >> >> >> >> >> Vídeo 3
                        >> >> >> >> >> >> >> Vídeo 7
                        >> >> >> >> >> >> >> Raul Seixas
                        >> >> >> >> >> >> >> Zé Ramalho
                        >> >> >> >> >> >> >> Vídeo 2
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no
                        >> >>caso
                        >> >> >>do
                        >> >> >> >> >>exemplo
                        >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                        >> >> >>Assinante.
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                        >> >> >>vídeos
                        >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                        >>Assinante
                        >> >>eu
                        >> >> >> >>uso
                        >> >> >> >> >>só
                        >> >> >> >> >> >>para
                        >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                        >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                        >> >> >> >>preenchido
                        >> >> >> >> >>com
                        >> >> >> >> >> >>os
                        >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                        >> >> >>recuperar
                        >> >> >> >>pelo
                        >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Na minha Action:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> No meu JSP:
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                        >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                        >>name="Busca_Videos">
                        >> >> >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                        >> >> >> >> >> >> >> <bean:write name="resulBusca"
                        >>property="description"
                        >> >>/>
                        >> >> >> >> >> >> >> </logic:iterate>
                        >> >> >> >> >> >> >> </logic:notEmpty>
                        >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                        >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                        >> >> >> >> >> >> >> </logic:empty>
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                        >>recuperar
                        >> >>em
                        >> >> >>cima
                        >> >> >> >>da
                        >> >> >> >> >> >>busca
                        >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Grato desde já,
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >> Anderson Moraes
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >>
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> >
                        >> >> >> >> >> >> > --
                        >> >> >> >> >> >> > Victor Guilherme Hogemann
                        >> >> >> >> >> >> > http://victor.hogemann.eti.br
                        >> >> >> >> >> >>
                        >> >> >> >> >> >>
                        >> >> >> >> >> >>
                        >> >> >> >> >> >
                        >> >> >> >> >> >
                        >> >> >> >> >> >
                        >> >> >> >> >> > --
                        >> >> >> >> >> > Victor Guilherme Hogemann
                        >> >> >> >> >> > http://victor.hogemann.eti.br
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >>
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> >
                        >> >> >> >> > --
                        >> >> >> >> > Victor Guilherme Hogemann
                        >> >> >> >> > http://victor.hogemann.eti.br
                        >> >> >> >>
                        >> >> >> >>
                        >> >> >> >>
                        >> >> >> >
                        >> >> >> >
                        >> >> >> >
                        >> >> >> > --
                        >> >> >> > Victor Guilherme Hogemann
                        >> >> >> > http://victor.hogemann.eti.br
                        >> >> >>
                        >> >> >>
                        >> >> >>
                        >> >> >
                        >> >> >
                        >> >> >
                        >> >> > --
                        >> >> > Victor Guilherme Hogemann
                        >> >> > http://victor.hogemann.eti.br
                        >> >>
                        >> >>
                        >> >>
                        >> >
                        >> >
                        >> >
                        >> > --
                        >> > Victor Guilherme Hogemann
                        >> > http://victor.hogemann.eti.br
                        >>
                        >>
                        >>
                        >
                        >
                        >
                        > --
                        > Victor Guilherme Hogemann
                        > http://victor.hogemann.eti.br
                      • Victor Hogemann
                        Anderson, Nesse caso, você vai utilizar só esse miolo aqui: FullTextSession fullTextSession = Search.getFullTextSession(session); Criteria crit =
                        Message 11 of 21 , Oct 5, 2009
                        • 0 Attachment
                          Anderson,

                          Nesse caso, você vai utilizar só esse miolo aqui:

                          FullTextSession fullTextSession = Search.getFullTextSession(session);

                          Criteria crit = session.createCriteria(entityClass);

                          for (Object obj : crit.list()) {

                              T entity = (T) obj;

                              fullTextSession.index(entity);

                          }


                          Sendo que session é um Session do Hibernate. Encare como se fosse um outro método qualquer de um DAO seu.

                          [ ]s

                          2009/10/5 Anderson Moraes <amoraes@...>
                           

                          Estou utilizando STRUTS, como ficaria o mesmo nesse caso???

                          On Mon, 5 Oct 2009 17:47:21 -0300


                          Victor Hogemann <victor.hogemann@...> wrote:
                          > Anderson,
                          > Desculpe... esse método está feito pra usar o suporte a Hibernate do
                          > SpringFramework. Você vai ter que alterar ele se estiver usando o
                          >Hibernate
                          > "na unha".
                          >
                          > [ ]s
                          >
                          > 2009/10/5 Anderson Moraes <amoraes@...>
                          >
                          >>
                          >>
                          >> Está dando erro em "this.getHibernateTemplate().execute(new
                          >> HibernateCallback(){", diz que os métodos getHibernateTemplate() é
                          >> indefinido e que HibernateCallback() não pode ser definido para o
                          >> tipo.
                          >>
                          >> On Mon, 5 Oct 2009 14:48:47 -0300
                          >>
                          >> Victor Hogemann <victor.hogemann@...
                          >><victor.hogemann%40gmail.com>>
                          >> wrote:
                          >> > Anderson,
                          >> > Pode fazer dentro de um main sim, e o método serve pra qualquer
                          >> >entidade
                          >> > indexada com hibernate-search... Por exemplo, basta chamar
                          >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no seu
                          >> >caso.
                          >> >
                          >> > [ ]s
                          >> >
                          >> > 2009/10/5 Anderson Moraes
                          >><amoraes@...<amoraes%40tecmetal.com.br>

                          >> >
                          >> >
                          >> >>
                          >> >>
                          >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar dentro
                          >>de
                          >> >>um
                          >> >> main mesmo???
                          >> >>
                          >> >> Esse exemplo que você me mandou serve para o meu caso ou tenho
                          >>que
                          >> >> fazer alguma modificação???
                          >> >>
                          >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                          >> >>
                          >> >> Abraço,
                          >> >>
                          >> >> Anderson
                          >> >>
                          >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                          >> >>
                          >> >> Victor Hogemann
                          >><victor.hogemann@...<victor.hogemann%40gmail.com>
                          >> >><victor.hogemann%40gmail.com>>
                          >> >> wrote:
                          >> >> > Anderson,
                          >> >> > Se você estiver fazendo uma aplicação Web pode colocar dentro
                          >>de
                          >> >>um
                          >> >> >método
                          >> >> > de um controller qualquer, ou até mesmo dentro de um servlet
                          >> >> >separado... O
                          >> >> > importante é chama-lo sem ninguém estar fazendo alterações na
                          >> >> >persistência.
                          >> >> >
                          >> >> > [ ]s
                          >> >> >
                          >> >> > 2009/10/2 Anderson Moraes
                          >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

                          >> 40tecmetal.com.br>
                          >>
                          >> >> >
                          >> >> >
                          >> >> >>
                          >> >> >>
                          >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o método
                          >> >>que
                          >> >> >>vc
                          >> >> >> me mando, como chamar...
                          >> >> >>
                          >> >> >> Desde já muito obrigado pela força que está me dando.
                          >> >> >>
                          >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                          >> >> >>
                          >> >> >> Victor Hogemann
                          >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                          >> <victor.hogemann%40gmail.com>
                          >> >> >><victor.hogemann%40gmail.com>>
                          >> >> >> wrote:
                          >> >> >> > Anderson,
                          >> >> >> > Imagine a seguinte situação... Sua aplicação está
                          >>funcionando,
                          >> >>e
                          >> >> >>de
                          >> >> >> >repente
                          >> >> >> > alguma coisa sai errada e o seu servidor capota. Beleza,
                          >>você
                          >> >>tem
                          >> >> >>o
                          >> >> >> >backup
                          >> >> >> > do seu banco de dados, mas e os índices do Hibernate Search?
                          >> >> >> >
                          >> >> >> > Claro, você poderia fazer backup desses também... mas
                          >>imagine
                          >> >>que
                          >> >> >> >não tenha
                          >> >> >> > feito. Você vai precisar reconstruir seus índices a partir
                          >>das
                          >> >> >> >entidades
                          >> >> >> > persistidas no banco, pra isso serve o método que eu te
                          >>passei.
                          >> >> >> >
                          >> >> >> > Como você alterou o mapeamento das entidades no Hibernate
                          >> >>Search,
                          >> >> >> >logo mudou
                          >> >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                          >> >> >>novamente.
                          >> >> >> >
                          >> >> >> > Sacou?
                          >> >> >> >
                          >> >> >> > 2009/10/2 Anderson Moraes
                          >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                          >> 40tecmetal.com.br><amoraes%
                          >>
                          >> >> 40tecmetal.com.br>
                          >> >>
                          >> >> >> >
                          >> >> >> >
                          >> >> >> >>
                          >> >> >> >>
                          >> >> >> >> Não entendi como eu executo essa classe, em que momento...
                          >> >> >> >>
                          >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                          >> >> >> >>
                          >> >> >> >> Victor Hogemann
                          >> >> >><victor.hogemann@...
                          >><victor.hogemann%40gmail.com><victor.hogemann%
                          >> 40gmail.com>
                          >> >> <victor.hogemann%40gmail.com>
                          >> >> >> >><victor.hogemann%40gmail.com>>
                          >> >> >> >> wrote:
                          >> >> >> >> > Anderson,
                          >> >> >> >> > Você re-indexou suas entidades? Toda vez que você muda o
                          >> >> >> >>mapeamento
                          >> >> >> >> >os
                          >> >> >> >> > índices são criados novamente, e você precisa re-indexar
                          >>as
                          >> >> >> >> >entidades que já
                          >> >> >> >> > existiam... senão vai ficar com o índice vazio. Segue um
                          >> >> >>exemplo
                          >> >> >> >>de
                          >> >> >> >> >como
                          >> >> >> >> > fazer:
                          >> >> >> >> >
                          >> >> >> >> > public void refreshIndex(final Class entityClass) {
                          >> >> >> >> >
                          >> >> >> >> > this.getHibernateTemplate().execute(new
                          >>HibernateCallback()
                          >> >>{
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> > public Object doInHibernate(Session session)
                          >> >> >> >> > throwsHibernateException, SQLException {
                          >> >> >> >>
                          >> >> >> >> >
                          >> >> >> >> > FullTextSession fullTextSession =
                          >> >> >> >> > Search.getFullTextSession(session);
                          >> >> >> >> >
                          >> >> >> >> > Criteria crit = session.createCriteria(entityClass);
                          >> >> >> >> >
                          >> >> >> >> > for (Object obj : crit.list()) {
                          >> >> >> >> >
                          >> >> >> >> > T entity = (T) obj;
                          >> >> >> >> >
                          >> >> >> >> > fullTextSession.index(entity);
                          >> >> >> >> >
                          >> >> >> >> > }
                          >> >> >> >> >
                          >> >> >> >> > return null;
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> > }
                          >> >> >> >> >
                          >> >> >> >> > });
                          >> >> >> >> >
                          >> >> >> >> > }
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> > [ ]s
                          >> >> >> >> >
                          >> >> >> >> > 2009/10/2 Anderson Moraes
                          >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                          >><amoraes%
                          >> 40tecmetal.com.br> <amoraes%
                          >> >> 40tecmetal.com.br><amoraes%
                          >> >>
                          >> >> >> 40tecmetal.com.br>
                          >> >> >>
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que fiz,
                          >> >>abaixo
                          >> >> >> >>vou
                          >> >> >> >> >> mostrar o SQL que sai no console:
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> try{
                          >> >> >> >> >>
                          >> >> >> >> >> final Session session =
                          >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                          >> >> >> >> >> final FullTextSession ftSession =
                          >> >> >> >> >> Search.getFullTextSession(session);
                          >> >> >> >> >> final List<Video> videos =
                          >> >> >> >> >> session.createCriteria(Video.class).list();
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> for(Video v : videos) {
                          >> >> >> >> >> ftSession.index(v);
                          >> >> >> >> >> }
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> final String[] stopWords =
                          >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                          >> >> >> >> >> final MultiFieldQueryParser parser = new
                          >> >> >> >> >> MultiFieldQueryParser(new
                          >> >> >> >> >> String[]{"Video.assinante.nome","Video.description"} ,
                          >>new
                          >> >> >> >> >> StopAnalyzer(stopWords));
                          >> >> >> >> >> final Query query = parser.parse("Moraes");
                          >> >> >> >> >> final FullTextQuery fullTextQuery =
                          >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                          >> >> >> >> >>
                          >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> if (list==null || list.size()==0){
                          >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                          >> >> >> >> >> }else{
                          >> >> >> >> >> for (Video v : list) {
                          >> >> >> >> >> System.out.println(" " + v.getTitle());
                          >> >> >> >> >> }
                          >> >> >> >> >> }
                          >> >> >> >> >>
                          >> >> >> >> >> }catch(Exception e){
                          >> >> >> >> >> e.printStackTrace();
                          >> >> >> >> >> }
                          >> >> >> >> >> }
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >> CONSOLE:
                          >> >> >> >> >> Hibernate:
                          >> >> >> >> >>
                          >> >> >> >> >> select
                          >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                          >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                          >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                          >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                          >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                          >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                          >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                          >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                          >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                          >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                          >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                          >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                          >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                          >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                          >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                          >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                          >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                          >> >> >> >> >> from
                          >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                          >>assinante2_
                          >> >>on
                          >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                          >> >> >> >> >>
                          >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                          >> >> >> >> >>
                          >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                          >> >> >> >> >>
                          >> >> >> >> >> Victor Hogemann
                          >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                          >> >><victor.hogemann%40gmail.com><victor.hogemann%
                          >> >> 40gmail.com>
                          >> >> >> <victor.hogemann%40gmail.com>
                          >> >> >> >> >><victor.hogemann%40gmail.com>>
                          >> >> >> >> >> wrote:
                          >> >> >> >> >> > Anderson,
                          >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                          >> >>vídeos
                          >> >> >>do
                          >> >> >> >> >> >Assinante:
                          >> >> >> >> >> >
                          >> >> >> >> >> > @ContainedIn
                          >> >> >> >> >> > @OneToMany(mappedBy="assinante", fetch=FetchType.LAZY)
                          >> >> >> >> >> > @Cascade(CascadeType.ALL)
                          >> >> >> >> >> > @IndexedEmbedded
                          >> >> >> >> >> > private List<Video> Videos;
                          >> >> >> >> >> >
                          >> >> >> >> >> >
                          >> >> >> >> >> > [ ]s
                          >> >> >> >> >> >
                          >> >> >> >> >> > 2009/10/2 Anderson Moraes
                          >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                          >><amoraes%
                          >> 40tecmetal.com.br>
                          >> >><amoraes%
                          >> >> 40tecmetal.com.br> <amoraes%
                          >> >> >> 40tecmetal.com.br><amoraes%
                          >> >> >>
                          >> >> >> >> 40tecmetal.com.br>
                          >> >> >> >>
                          >> >> >> >> >> >
                          >> >> >> >> >> >
                          >> >> >> >> >> >>
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                          >> >>Classes:
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> ASSINANTE:
                          >> >> >> >> >> >> @Entity
                          >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                          >> >> >> >> >> >> @Indexed
                          >> >> >> >> >> >> public class Assinante extends PersistentObject
                          >> >>implements
                          >> >> >> >> >> >> Serializable{
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> @Id
                          >> >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                          >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                          >> >> >> >> >> >> private Long id;
                          >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                          >> >> >> >> >> >> private String email;
                          >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                          >> >> >> >> >> >> private String password;
                          >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                          >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                          >> >> >> >> >> >> private String nome;
                          >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                          >> >> >> >> >> >> private String cpf;
                          >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                          >> >> >> >> >> >> private String endereco;
                          >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                          >> >> >> >> >> >> private String cidade;
                          >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                          >> >> >> >> >> >> private String estado;
                          >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                          >> >> >> >> >> >> private String dataCadastro;
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> @ContainedIn
                          >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                          >>fetch=FetchType.LAZY)
                          >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                          >> >> >> >> >> >> @IndexedEmbedded
                          >> >> >> >> >> >> private List<Video> Videos;
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> VÍDEO:
                          >> >> >> >> >> >> @Entity
                          >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                          >> >> >> >> >> >> @Indexed
                          >> >> >> >> >> >> public class Video implements Serializable{
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> @Id
                          >> >> >> >> >> >> @GeneratedValue(strategy = GenerationType.IDENTITY)
                          >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                          >> >> >> >> >> >> private Long id;
                          >> >> >> >> >> >> @Column(name="VC_TITLE")
                          >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                          >> >> >> >> >> >> private String title;
                          >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                          >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                          >> >> >> >> >> >> private String description;
                          >> >> >> >> >> >> @Column(name="VC_URL")
                          >> >> >> >> >> >> private String url;
                          >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                          >> >> >> >> >> >> private String realPath;
                          >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                          >> >> >> >> >> >> private Long idAssinante;
                          >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                          >> >> >> >> >> >> private String dataUpload;
                          >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                          >> >> >> >> >> >> private String pathImage;
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> @IndexedEmbedded
                          >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                          >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE", insertable=false,
                          >> >> >> >> >> >> updatable=false)
                          >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                          >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                          >> >> >> >> >> >> private Assinante assinante;
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> Deu erro:
                          >> >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                          >> >>Circular
                          >> >> >> >> >>reference.
                          >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                          >>entity
                          >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                          >> >> >> >> >> >>
                          >> >> >> >> >> >>
                          >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                          >> >> >> >> >> >> Victor Hogemann
                          >> >> >> >> >><victor.hogemann@...
                          >><victor.hogemann%40gmail.com><victor.hogemann%
                          >> 40gmail.com>
                          >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                          >> >> >> 40gmail.com>
                          >> >> >> >> <victor.hogemann%40gmail.com>
                          >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                          >> >> >> >> >>
                          >> >> >> >> >> >> wrote:
                          >> >> >> >> >> >> > Anderson,
                          >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                          >> >>associação
                          >> >> >> >> >> >> >bi-direcional entre
                          >> >> >> >> >> >> > Assinante e Video, assim você pode a partir do
                          >>Video
                          >> >> >>filtrar
                          >> >> >> >> >>pelo
                          >> >> >> >> >> >> >nome do
                          >> >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                          >> >>exemplo:
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                          >> >> >> >> >>Term("Video.assinante.nome",
                          >> >> >> >> >> >> >"Fulano"));
                          >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                          >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                          >> >>Video.class);
                          >> >> >> >> >> >> > return fullTextQuery.list();
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > Pelo que você escreveu a associação entre Assinante
                          >>e
                          >> >> >>Vídeo
                          >> >> >> >>é
                          >> >> >> >> >> >> >one-to-many,
                          >> >> >> >> >> >> > então não vai ser uma mudança tão traumática assim
                          >>no
                          >> >> >> >>código. O
                          >> >> >> >> >> >> >pulo-do-gato
                          >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                          >>Assinante
                          >> >>no
                          >> >> >> >>indice
                          >> >> >> >> >>de
                          >> >> >> >> >> >> >Vídeo,
                          >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                          >> >> >>@ContainedIn.
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > Em Vídeo você vai ter:
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > @IndexedEmbeded
                          >> >> >> >> >> >> > @OneToOne
                          >> >> >> >> >> >> > Assinante assinante;
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > E em Assinante vai ficar:
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > @ContainedIn
                          >> >> >> >> >> >> > @OneToMany
                          >> >> >> >> >> >> > List<Video> videos;
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de hibernate-search,
                          >> >>que
                          >> >> >> >> >> >>basicamente
                          >> >> >> >> >> >> >é um
                          >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                          >>hibernate
                          >> >> >> >>search.
                          >> >> >> >> >>No
                          >> >> >> >> >> >> >exemplo que
                          >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                          >> >>entidades
                          >> >> >> >> >> >>associadas:
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                          >> >> >> >> >> >><amoraes@...
                          >><amoraes%40tecmetal.com.br><amoraes%
                          >> 40tecmetal.com.br>
                          >> >><amoraes%
                          >> >> 40tecmetal.com.br>
                          >> >> >><amoraes%
                          >> >> >> 40tecmetal.com.br> <amoraes%
                          >> >> >> >> 40tecmetal.com.br><amoraes%
                          >> >> >> >>
                          >> >> >> >> >> 40tecmetal.com.br>
                          >> >> >> >> >>
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Pessoal, bom dia.
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                          >>primeiro
                          >> >>vou
                          >> >> >> >> >> >>descrever
                          >> >> >> >> >> >> >>os
                          >> >> >> >> >> >> >> atributos da minha bean:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> BEAN Assinante:
                          >> >> >> >> >> >> >> id
                          >> >> >> >> >> >> >> nome
                          >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                          >> >>Collection<Video>
                          >> >> >> >> >>Videos;)
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> BEAN Video:
                          >> >> >> >> >> >> >> id
                          >> >> >> >> >> >> >> title
                          >> >> >> >> >> >> >> description
                          >> >> >> >> >> >> >> idAssinante
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Blz, até aí tudo bem.
                          >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma busca
                          >>nas
                          >> >> >>duas
                          >> >> >> >> >> >>classes
                          >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                          >> >>atributo
                          >> >> >> >>"nome"
                          >> >> >> >> >>e
                          >> >> >> >> >> >>em
                          >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                          >>"description",
                          >> >> >>segue
                          >> >> >> >>o
                          >> >> >> >> >> >>método
                          >> >> >> >> >> >> >> abaixou:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> ************** MÉTODO ********************
                          >> >> >> >> >> >> >> try{
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> final Session session =
                          >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                          >> >> >> >> >> >> >> final FullTextSession ftSession =
                          >> >> >> >> >> >> >> Search.getFullTextSession(session);
                          >> >> >> >> >> >> >> final List<Assinante> assinantes =
                          >> >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                          >> >> >> >> >> >> >> final List<Video> videos =
                          >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                          >> >> >> >> >> >> >> ftSession.index(a);
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> for(Video v : videos) {
                          >> >> >> >> >> >> >> ftSession.index(v);
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> final String[] stopWords =
                          >> >> >> >> >> >> >>
                          >>{"de","do","da","dos","das","a","o","na","no","em"};
                          >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                          >> >> >> >> >> >>MultiFieldQueryParser(new
                          >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                          >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                          >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                          >>Flamengo");
                          >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                          >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                          >> >>Assinante.class);
                          >> >> >> >> >> >> >> final List<Assinante> list = fullTextQuery.list();
                          >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> }catch(Exception e){
                          >> >> >> >> >> >> >> e.printStackTrace();
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> ************** FIM MÉTODO ********************
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que eu
                          >> >>vou
                          >> >> >> >> >>destacar
                          >> >> >> >> >> >> >>abaixo
                          >> >> >> >> >> >> >> que eu informo em que campos procurar:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                          >> >> >> >> >> >>MultiFieldQueryParser(new
                          >> >> >> >> >> >> >>
                          >>String[]{"nome","Videos.title","Videos.description"}
                          >> >>,
                          >> >> >>new
                          >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> if (list==null || list.size()==0){
                          >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                          >> >> >> >> >> >> >> }else{
                          >> >> >> >> >> >> >> for(Assinante a : list) {
                          >> >> >> >> >> >> >> System.out.println(a.getNome());
                          >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                          >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >> }
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                          >> >> >> >> >> >> >> Ex.:
                          >> >> >> >> >> >> >> Anderson Moraes
                          >> >> >> >> >> >> >> Vídeo 1
                          >> >> >> >> >> >> >> Vídeo 4
                          >> >> >> >> >> >> >> Vídeo 9
                          >> >> >> >> >> >> >> Elba Ramalho
                          >> >> >> >> >> >> >> Vídeo 3
                          >> >> >> >> >> >> >> Vídeo 7
                          >> >> >> >> >> >> >> Raul Seixas
                          >> >> >> >> >> >> >> Zé Ramalho
                          >> >> >> >> >> >> >> Vídeo 2
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo, no
                          >> >>caso
                          >> >> >>do
                          >> >> >> >> >>exemplo
                          >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo sem
                          >> >> >>Assinante.
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente dos
                          >> >> >>vídeos
                          >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                          >>Assinante
                          >> >>eu
                          >> >> >> >>uso
                          >> >> >> >> >>só
                          >> >> >> >> >> >>para
                          >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                          >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video> será
                          >> >> >> >>preenchido
                          >> >> >> >> >>com
                          >> >> >> >> >> >>os
                          >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                          >> >> >>recuperar
                          >> >> >> >>pelo
                          >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Na minha Action:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> request.setAttribute("Busca_Videos", listVideos);
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> No meu JSP:
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                          >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                          >>name="Busca_Videos">
                          >> >> >> >> >> >> >> <bean:write name="resulBusca" property="title" />
                          >> >> >> >> >> >> >> <bean:write name="resulBusca"
                          >>property="description"
                          >> >>/>
                          >> >> >> >> >> >> >> </logic:iterate>
                          >> >> >> >> >> >> >> </logic:notEmpty>
                          >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                          >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                          >> >> >> >> >> >> >> </logic:empty>
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                          >>recuperar
                          >> >>em
                          >> >> >>cima
                          >> >> >> >>da
                          >> >> >> >> >> >>busca
                          >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Grato desde já,
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >> Anderson Moraes
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >>
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> >
                          >> >> >> >> >> >> > --
                          >> >> >> >> >> >> > Victor Guilherme Hogemann
                          >> >> >> >> >> >> > http://victor.hogemann.eti.br
                          >> >> >> >> >> >>
                          >> >> >> >> >> >>
                          >> >> >> >> >> >>
                          >> >> >> >> >> >
                          >> >> >> >> >> >
                          >> >> >> >> >> >
                          >> >> >> >> >> > --
                          >> >> >> >> >> > Victor Guilherme Hogemann
                          >> >> >> >> >> > http://victor.hogemann.eti.br
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >>
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> >
                          >> >> >> >> > --
                          >> >> >> >> > Victor Guilherme Hogemann
                          >> >> >> >> > http://victor.hogemann.eti.br
                          >> >> >> >>
                          >> >> >> >>
                          >> >> >> >>
                          >> >> >> >
                          >> >> >> >
                          >> >> >> >
                          >> >> >> > --
                          >> >> >> > Victor Guilherme Hogemann
                          >> >> >> > http://victor.hogemann.eti.br
                          >> >> >>
                          >> >> >>
                          >> >> >>
                          >> >> >
                          >> >> >
                          >> >> >
                          >> >> > --
                          >> >> > Victor Guilherme Hogemann
                          >> >> > http://victor.hogemann.eti.br
                          >> >>
                          >> >>
                          >> >>
                          >> >
                          >> >
                          >> >
                          >> > --
                          >> > Victor Guilherme Hogemann
                          >> > http://victor.hogemann.eti.br
                          >>
                          >>
                          >>
                          >
                          >
                          >
                          > --
                          > Victor Guilherme Hogemann
                          > http://victor.hogemann.eti.br




                          --
                          Victor Guilherme Hogemann
                          http://victor.hogemann.eti.br
                        • Anderson Moraes
                          Victor, minha classe ficou assim: package esseecraque.action; import org.hibernate.Criteria; import org.hibernate.Session; import
                          Message 12 of 21 , Oct 5, 2009
                          • 0 Attachment
                            Victor, minha classe ficou assim:

                            package esseecraque.action;

                            import org.hibernate.Criteria;
                            import org.hibernate.Session;
                            import org.hibernate.search.FullTextSession;
                            import org.hibernate.search.Search;

                            import esseecraque.util.HibernateUtil;

                            public class AtualizaIndice {

                            public void refreshIndex(final Class entityClass) {

                            Session session = HibernateUtil.getSessionFactory().openSession();

                            FullTextSession fullTextSession =
                            Search.getFullTextSession(session);

                            Criteria crit = session.createCriteria(entityClass);

                            for (Object obj : crit.list()) {
                            T entity = (T) obj;
                            fullTextSession.index(entity);
                            }


                            }

                            }

                            Mas tá com erro na linha "T entity = (T) obj;"
                            Diz que "T" não pode ser definido para o tipo, o que eu preciso fazer
                            para resolver esse problema?

                            Após resolver esse problema basta eu instanciar um objeto
                            AtualizaIndice e chamar o método, como abaixo?

                            AtualizaIndice ai = new AtualizaIndice();

                            ai.refreshIndex(Assinante.class);
                            ai.refreshIndex(Video.class);

                            é isso???

                            Grato mais uma vez Victor...




                            On Mon, 5 Oct 2009 18:21:50 -0300
                            Victor Hogemann <victor.hogemann@...> wrote:
                            > Anderson,
                            > Nesse caso, você vai utilizar só esse miolo aqui:
                            >
                            >FullTextSession fullTextSession = Search.getFullTextSession(session);
                            >
                            > Criteria crit = session.createCriteria(entityClass);
                            >
                            > for (Object obj : crit.list()) {
                            >
                            > T entity = (T) obj;
                            >
                            > fullTextSession.index(entity);
                            >
                            > }
                            >
                            >
                            > Sendo que session é um Session do Hibernate. Encare como se fosse um
                            >outro
                            > método qualquer de um DAO seu.
                            >
                            > [ ]s
                            >
                            > 2009/10/5 Anderson Moraes <amoraes@...>
                            >
                            >>
                            >>
                            >> Estou utilizando STRUTS, como ficaria o mesmo nesse caso???
                            >>
                            >> On Mon, 5 Oct 2009 17:47:21 -0300
                            >>
                            >> Victor Hogemann <victor.hogemann@...
                            >><victor.hogemann%40gmail.com>>
                            >> wrote:
                            >> > Anderson,
                            >> > Desculpe... esse método está feito pra usar o suporte a Hibernate
                            >>do
                            >> > SpringFramework. Você vai ter que alterar ele se estiver usando o
                            >> >Hibernate
                            >> > "na unha".
                            >> >
                            >> > [ ]s
                            >> >
                            >> > 2009/10/5 Anderson Moraes
                            >><amoraes@...<amoraes%40tecmetal.com.br>
                            >> >
                            >> >
                            >> >>
                            >> >>
                            >> >> Está dando erro em "this.getHibernateTemplate().execute(new
                            >> >> HibernateCallback(){", diz que os métodos getHibernateTemplate()
                            >>é
                            >> >> indefinido e que HibernateCallback() não pode ser definido para o
                            >> >> tipo.
                            >> >>
                            >> >> On Mon, 5 Oct 2009 14:48:47 -0300
                            >> >>
                            >> >> Victor Hogemann
                            >><victor.hogemann@...<victor.hogemann%40gmail.com>
                            >> >><victor.hogemann%40gmail.com>>
                            >> >> wrote:
                            >> >> > Anderson,
                            >> >> > Pode fazer dentro de um main sim, e o método serve pra qualquer
                            >> >> >entidade
                            >> >> > indexada com hibernate-search... Por exemplo, basta chamar
                            >> >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no
                            >>seu
                            >> >> >caso.
                            >> >> >
                            >> >> > [ ]s
                            >> >> >
                            >> >> > 2009/10/5 Anderson Moraes
                            >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                            >> 40tecmetal.com.br>
                            >>
                            >> >> >
                            >> >> >
                            >> >> >>
                            >> >> >>
                            >> >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar
                            >>dentro
                            >> >>de
                            >> >> >>um
                            >> >> >> main mesmo???
                            >> >> >>
                            >> >> >> Esse exemplo que você me mandou serve para o meu caso ou tenho
                            >> >>que
                            >> >> >> fazer alguma modificação???
                            >> >> >>
                            >> >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                            >> >> >>
                            >> >> >> Abraço,
                            >> >> >>
                            >> >> >> Anderson
                            >> >> >>
                            >> >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                            >> >> >>
                            >> >> >> Victor Hogemann
                            >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                            >> <victor.hogemann%40gmail.com>
                            >> >> >><victor.hogemann%40gmail.com>>
                            >> >> >> wrote:
                            >> >> >> > Anderson,
                            >> >> >> > Se você estiver fazendo uma aplicação Web pode colocar
                            >>dentro
                            >> >>de
                            >> >> >>um
                            >> >> >> >método
                            >> >> >> > de um controller qualquer, ou até mesmo dentro de um servlet
                            >> >> >> >separado... O
                            >> >> >> > importante é chama-lo sem ninguém estar fazendo alterações
                            >>na
                            >> >> >> >persistência.
                            >> >> >> >
                            >> >> >> > [ ]s
                            >> >> >> >
                            >> >> >> > 2009/10/2 Anderson Moraes
                            >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                            >> 40tecmetal.com.br><amoraes%
                            >>
                            >> >> 40tecmetal.com.br>
                            >> >>
                            >> >> >> >
                            >> >> >> >
                            >> >> >> >>
                            >> >> >> >>
                            >> >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o
                            >>método
                            >> >> >>que
                            >> >> >> >>vc
                            >> >> >> >> me mando, como chamar...
                            >> >> >> >>
                            >> >> >> >> Desde já muito obrigado pela força que está me dando.
                            >> >> >> >>
                            >> >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                            >> >> >> >>
                            >> >> >> >> Victor Hogemann
                            >> >> >><victor.hogemann@...
                            >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> 40gmail.com>
                            >> >> <victor.hogemann%40gmail.com>
                            >> >> >> >><victor.hogemann%40gmail.com>>
                            >> >> >> >> wrote:
                            >> >> >> >> > Anderson,
                            >> >> >> >> > Imagine a seguinte situação... Sua aplicação está
                            >> >>funcionando,
                            >> >> >>e
                            >> >> >> >>de
                            >> >> >> >> >repente
                            >> >> >> >> > alguma coisa sai errada e o seu servidor capota. Beleza,
                            >> >>você
                            >> >> >>tem
                            >> >> >> >>o
                            >> >> >> >> >backup
                            >> >> >> >> > do seu banco de dados, mas e os índices do Hibernate
                            >>Search?
                            >> >> >> >> >
                            >> >> >> >> > Claro, você poderia fazer backup desses também... mas
                            >> >>imagine
                            >> >> >>que
                            >> >> >> >> >não tenha
                            >> >> >> >> > feito. Você vai precisar reconstruir seus índices a
                            >>partir
                            >> >>das
                            >> >> >> >> >entidades
                            >> >> >> >> > persistidas no banco, pra isso serve o método que eu te
                            >> >>passei.
                            >> >> >> >> >
                            >> >> >> >> > Como você alterou o mapeamento das entidades no Hibernate
                            >> >> >>Search,
                            >> >> >> >> >logo mudou
                            >> >> >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                            >> >> >> >>novamente.
                            >> >> >> >> >
                            >> >> >> >> > Sacou?
                            >> >> >> >> >
                            >> >> >> >> > 2009/10/2 Anderson Moraes
                            >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                            >><amoraes%
                            >> 40tecmetal.com.br> <amoraes%
                            >> >> 40tecmetal.com.br><amoraes%
                            >> >>
                            >> >> >> 40tecmetal.com.br>
                            >> >> >>
                            >> >> >> >> >
                            >> >> >> >> >
                            >> >> >> >> >>
                            >> >> >> >> >>
                            >> >> >> >> >> Não entendi como eu executo essa classe, em que
                            >>momento...
                            >> >> >> >> >>
                            >> >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                            >> >> >> >> >>
                            >> >> >> >> >> Victor Hogemann
                            >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                            >> >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> >> 40gmail.com>
                            >> >> >> <victor.hogemann%40gmail.com>
                            >> >> >> >> >><victor.hogemann%40gmail.com>>
                            >> >> >> >> >> wrote:
                            >> >> >> >> >> > Anderson,
                            >> >> >> >> >> > Você re-indexou suas entidades? Toda vez que você muda
                            >>o
                            >> >> >> >> >>mapeamento
                            >> >> >> >> >> >os
                            >> >> >> >> >> > índices são criados novamente, e você precisa
                            >>re-indexar
                            >> >>as
                            >> >> >> >> >> >entidades que já
                            >> >> >> >> >> > existiam... senão vai ficar com o índice vazio. Segue
                            >>um
                            >> >> >> >>exemplo
                            >> >> >> >> >>de
                            >> >> >> >> >> >como
                            >> >> >> >> >> > fazer:
                            >> >> >> >> >> >
                            >> >> >> >> >> > public void refreshIndex(final Class entityClass) {
                            >> >> >> >> >> >
                            >> >> >> >> >> > this.getHibernateTemplate().execute(new
                            >> >>HibernateCallback()
                            >> >> >>{
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> > public Object doInHibernate(Session session)
                            >> >> >> >> >> > throwsHibernateException, SQLException {
                            >> >> >> >> >>
                            >> >> >> >> >> >
                            >> >> >> >> >> > FullTextSession fullTextSession =
                            >> >> >> >> >> > Search.getFullTextSession(session);
                            >> >> >> >> >> >
                            >> >> >> >> >> > Criteria crit = session.createCriteria(entityClass);
                            >> >> >> >> >> >
                            >> >> >> >> >> > for (Object obj : crit.list()) {
                            >> >> >> >> >> >
                            >> >> >> >> >> > T entity = (T) obj;
                            >> >> >> >> >> >
                            >> >> >> >> >> > fullTextSession.index(entity);
                            >> >> >> >> >> >
                            >> >> >> >> >> > }
                            >> >> >> >> >> >
                            >> >> >> >> >> > return null;
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> > }
                            >> >> >> >> >> >
                            >> >> >> >> >> > });
                            >> >> >> >> >> >
                            >> >> >> >> >> > }
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> > [ ]s
                            >> >> >> >> >> >
                            >> >> >> >> >> > 2009/10/2 Anderson Moraes
                            >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                            >><amoraes%
                            >> 40tecmetal.com.br>
                            >> >><amoraes%
                            >> >> 40tecmetal.com.br> <amoraes%
                            >> >> >> 40tecmetal.com.br><amoraes%
                            >> >> >>
                            >> >> >> >> 40tecmetal.com.br>
                            >> >> >> >>
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que
                            >>fiz,
                            >> >> >>abaixo
                            >> >> >> >> >>vou
                            >> >> >> >> >> >> mostrar o SQL que sai no console:
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> try{
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> final Session session =
                            >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                            >> >> >> >> >> >> final FullTextSession ftSession =
                            >> >> >> >> >> >> Search.getFullTextSession(session);
                            >> >> >> >> >> >> final List<Video> videos =
                            >> >> >> >> >> >> session.createCriteria(Video.class).list();
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> for(Video v : videos) {
                            >> >> >> >> >> >> ftSession.index(v);
                            >> >> >> >> >> >> }
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> final String[] stopWords =
                            >> >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                            >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                            >> >> >> >> >> >> MultiFieldQueryParser(new
                            >> >> >> >> >> >> String[]{"Video.assinante.nome","Video.description"}
                            >>,
                            >> >>new
                            >> >> >> >> >> >> StopAnalyzer(stopWords));
                            >> >> >> >> >> >> final Query query = parser.parse("Moraes");
                            >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                            >> >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> if (list==null || list.size()==0){
                            >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                            >> >> >> >> >> >> }else{
                            >> >> >> >> >> >> for (Video v : list) {
                            >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                            >> >> >> >> >> >> }
                            >> >> >> >> >> >> }
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> }catch(Exception e){
                            >> >> >> >> >> >> e.printStackTrace();
                            >> >> >> >> >> >> }
                            >> >> >> >> >> >> }
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> CONSOLE:
                            >> >> >> >> >> >> Hibernate:
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> select
                            >> >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                            >> >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                            >> >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                            >> >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                            >> >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                            >> >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                            >> >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                            >> >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                            >> >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                            >> >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                            >> >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                            >> >> >> >> >> >> from
                            >> >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                            >> >>assinante2_
                            >> >> >>on
                            >> >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> Victor Hogemann
                            >> >> >> >> >><victor.hogemann@...
                            >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> 40gmail.com>
                            >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> >> >> 40gmail.com>
                            >> >> >> >> <victor.hogemann%40gmail.com>
                            >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                            >> >> >> >> >> >> wrote:
                            >> >> >> >> >> >> > Anderson,
                            >> >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                            >> >> >>vídeos
                            >> >> >> >>do
                            >> >> >> >> >> >> >Assinante:
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> > @ContainedIn
                            >> >> >> >> >> >> > @OneToMany(mappedBy="assinante",
                            >>fetch=FetchType.LAZY)
                            >> >> >> >> >> >> > @Cascade(CascadeType.ALL)
                            >> >> >> >> >> >> > @IndexedEmbedded
                            >> >> >> >> >> >> > private List<Video> Videos;
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> > [ ]s
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                            >> >> >> >> >> >><amoraes@...
                            >><amoraes%40tecmetal.com.br><amoraes%
                            >> 40tecmetal.com.br>
                            >> >><amoraes%
                            >> >> 40tecmetal.com.br>
                            >> >> >><amoraes%
                            >> >> >> 40tecmetal.com.br> <amoraes%
                            >> >> >> >> 40tecmetal.com.br><amoraes%
                            >> >> >> >>
                            >> >> >> >> >> 40tecmetal.com.br>
                            >> >> >> >> >>
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                            >> >> >>Classes:
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> ASSINANTE:
                            >> >> >> >> >> >> >> @Entity
                            >> >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                            >> >> >> >> >> >> >> @Indexed
                            >> >> >> >> >> >> >> public class Assinante extends PersistentObject
                            >> >> >>implements
                            >> >> >> >> >> >> >> Serializable{
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> @Id
                            >> >> >> >> >> >> >> @GeneratedValue(strategy =
                            >>GenerationType.IDENTITY)
                            >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                            >> >> >> >> >> >> >> private Long id;
                            >> >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                            >> >> >> >> >> >> >> private String email;
                            >> >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                            >> >> >> >> >> >> >> private String password;
                            >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                            >> >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                            >> >> >> >> >> >> >> private String nome;
                            >> >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                            >> >> >> >> >> >> >> private String cpf;
                            >> >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                            >> >> >> >> >> >> >> private String endereco;
                            >> >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                            >> >> >> >> >> >> >> private String cidade;
                            >> >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                            >> >> >> >> >> >> >> private String estado;
                            >> >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                            >> >> >> >> >> >> >> private String dataCadastro;
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> @ContainedIn
                            >> >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                            >> >>fetch=FetchType.LAZY)
                            >> >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                            >> >> >> >> >> >> >> @IndexedEmbedded
                            >> >> >> >> >> >> >> private List<Video> Videos;
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> VÍDEO:
                            >> >> >> >> >> >> >> @Entity
                            >> >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                            >> >> >> >> >> >> >> @Indexed
                            >> >> >> >> >> >> >> public class Video implements Serializable{
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> @Id
                            >> >> >> >> >> >> >> @GeneratedValue(strategy =
                            >>GenerationType.IDENTITY)
                            >> >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                            >> >> >> >> >> >> >> private Long id;
                            >> >> >> >> >> >> >> @Column(name="VC_TITLE")
                            >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                            >> >> >> >> >> >> >> private String title;
                            >> >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                            >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                            >> >> >> >> >> >> >> private String description;
                            >> >> >> >> >> >> >> @Column(name="VC_URL")
                            >> >> >> >> >> >> >> private String url;
                            >> >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                            >> >> >> >> >> >> >> private String realPath;
                            >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                            >> >> >> >> >> >> >> private Long idAssinante;
                            >> >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                            >> >> >> >> >> >> >> private String dataUpload;
                            >> >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                            >> >> >> >> >> >> >> private String pathImage;
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> @IndexedEmbedded
                            >> >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                            >> >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE",
                            >>insertable=false,
                            >> >> >> >> >> >> >> updatable=false)
                            >> >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                            >> >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                            >> >> >> >> >> >> >> private Assinante assinante;
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> Deu erro:
                            >> >> >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                            >> >> >>Circular
                            >> >> >> >> >> >>reference.
                            >> >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                            >> >>entity
                            >> >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                            >> >> >> >> >> >> >> Victor Hogemann
                            >> >> >> >> >> >><victor.hogemann@...
                            >><victor.hogemann%40gmail.com>
                            >> >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> >> 40gmail.com>
                            >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                            >> >> >> >> 40gmail.com>
                            >> >> >> >> >> <victor.hogemann%40gmail.com>
                            >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> >> wrote:
                            >> >> >> >> >> >> >> > Anderson,
                            >> >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                            >> >> >>associação
                            >> >> >> >> >> >> >> >bi-direcional entre
                            >> >> >> >> >> >> >> > Assinante e Video, assim você pode a partir do
                            >> >>Video
                            >> >> >> >>filtrar
                            >> >> >> >> >> >>pelo
                            >> >> >> >> >> >> >> >nome do
                            >> >> >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                            >> >> >>exemplo:
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                            >> >> >> >> >> >>Term("Video.assinante.nome",
                            >> >> >> >> >> >> >> >"Fulano"));
                            >> >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                            >> >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                            >> >> >>Video.class);
                            >> >> >> >> >> >> >> > return fullTextQuery.list();
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > Pelo que você escreveu a associação entre
                            >>Assinante
                            >> >>e
                            >> >> >> >>Vídeo
                            >> >> >> >> >>é
                            >> >> >> >> >> >> >> >one-to-many,
                            >> >> >> >> >> >> >> > então não vai ser uma mudança tão traumática
                            >>assim
                            >> >>no
                            >> >> >> >> >>código. O
                            >> >> >> >> >> >> >> >pulo-do-gato
                            >> >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                            >> >>Assinante
                            >> >> >>no
                            >> >> >> >> >>indice
                            >> >> >> >> >> >>de
                            >> >> >> >> >> >> >> >Vídeo,
                            >> >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                            >> >> >> >>@ContainedIn.
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > Em Vídeo você vai ter:
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > @IndexedEmbeded
                            >> >> >> >> >> >> >> > @OneToOne
                            >> >> >> >> >> >> >> > Assinante assinante;
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > E em Assinante vai ficar:
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > @ContainedIn
                            >> >> >> >> >> >> >> > @OneToMany
                            >> >> >> >> >> >> >> > List<Video> videos;
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de
                            >>hibernate-search,
                            >> >> >>que
                            >> >> >> >> >> >> >>basicamente
                            >> >> >> >> >> >> >> >é um
                            >> >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                            >> >>hibernate
                            >> >> >> >> >>search.
                            >> >> >> >> >> >>No
                            >> >> >> >> >> >> >> >exemplo que
                            >> >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                            >> >> >>entidades
                            >> >> >> >> >> >> >>associadas:
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                            >> >> >> >> >> >> >><amoraes@...
                            >><amoraes%40tecmetal.com.br>
                            >> >><amoraes%40tecmetal.com.br><amoraes%
                            >> >> 40tecmetal.com.br>
                            >> >> >><amoraes%
                            >> >> >> 40tecmetal.com.br>
                            >> >> >> >><amoraes%
                            >> >> >> >> 40tecmetal.com.br> <amoraes%
                            >> >> >> >> >> 40tecmetal.com.br><amoraes%
                            >> >> >> >> >>
                            >> >> >> >> >> >> 40tecmetal.com.br>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Pessoal, bom dia.
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                            >> >>primeiro
                            >> >> >>vou
                            >> >> >> >> >> >> >>descrever
                            >> >> >> >> >> >> >> >>os
                            >> >> >> >> >> >> >> >> atributos da minha bean:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> BEAN Assinante:
                            >> >> >> >> >> >> >> >> id
                            >> >> >> >> >> >> >> >> nome
                            >> >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                            >> >> >>Collection<Video>
                            >> >> >> >> >> >>Videos;)
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> BEAN Video:
                            >> >> >> >> >> >> >> >> id
                            >> >> >> >> >> >> >> >> title
                            >> >> >> >> >> >> >> >> description
                            >> >> >> >> >> >> >> >> idAssinante
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Blz, até aí tudo bem.
                            >> >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma
                            >>busca
                            >> >>nas
                            >> >> >> >>duas
                            >> >> >> >> >> >> >>classes
                            >> >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                            >> >> >>atributo
                            >> >> >> >> >>"nome"
                            >> >> >> >> >> >>e
                            >> >> >> >> >> >> >>em
                            >> >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                            >> >>"description",
                            >> >> >> >>segue
                            >> >> >> >> >>o
                            >> >> >> >> >> >> >>método
                            >> >> >> >> >> >> >> >> abaixou:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> ************** MÉTODO ********************
                            >> >> >> >> >> >> >> >> try{
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> final Session session =
                            >> >> >> >> >> >> >> >>
                            >>HibernateUtil.getSessionFactory().openSession();
                            >> >> >> >> >> >> >> >> final FullTextSession ftSession =
                            >> >> >> >> >> >> >> >> Search.getFullTextSession(session);
                            >> >> >> >> >> >> >> >> final List<Assinante> assinantes =
                            >> >> >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                            >> >> >> >> >> >> >> >> final List<Video> videos =
                            >> >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                            >> >> >> >> >> >> >> >> ftSession.index(a);
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> for(Video v : videos) {
                            >> >> >> >> >> >> >> >> ftSession.index(v);
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> final String[] stopWords =
                            >> >> >> >> >> >> >> >>
                            >> >>{"de","do","da","dos","das","a","o","na","no","em"};
                            >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                            >> >> >> >> >> >> >>MultiFieldQueryParser(new
                            >> >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                            >> >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                            >> >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                            >> >>Flamengo");
                            >> >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                            >> >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                            >> >> >>Assinante.class);
                            >> >> >> >> >> >> >> >> final List<Assinante> list =
                            >>fullTextQuery.list();
                            >> >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> }catch(Exception e){
                            >> >> >> >> >> >> >> >> e.printStackTrace();
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> ************** FIM MÉTODO ********************
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que
                            >>eu
                            >> >> >>vou
                            >> >> >> >> >> >>destacar
                            >> >> >> >> >> >> >> >>abaixo
                            >> >> >> >> >> >> >> >> que eu informo em que campos procurar:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                            >> >> >> >> >> >> >>MultiFieldQueryParser(new
                            >> >> >> >> >> >> >> >>
                            >> >>String[]{"nome","Videos.title","Videos.description"}
                            >> >> >>,
                            >> >> >> >>new
                            >> >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> if (list==null || list.size()==0){
                            >> >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                            >> >> >> >> >> >> >> >> }else{
                            >> >> >> >> >> >> >> >> for(Assinante a : list) {
                            >> >> >> >> >> >> >> >> System.out.println(a.getNome());
                            >> >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                            >> >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >> }
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                            >> >> >> >> >> >> >> >> Ex.:
                            >> >> >> >> >> >> >> >> Anderson Moraes
                            >> >> >> >> >> >> >> >> Vídeo 1
                            >> >> >> >> >> >> >> >> Vídeo 4
                            >> >> >> >> >> >> >> >> Vídeo 9
                            >> >> >> >> >> >> >> >> Elba Ramalho
                            >> >> >> >> >> >> >> >> Vídeo 3
                            >> >> >> >> >> >> >> >> Vídeo 7
                            >> >> >> >> >> >> >> >> Raul Seixas
                            >> >> >> >> >> >> >> >> Zé Ramalho
                            >> >> >> >> >> >> >> >> Vídeo 2
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo,
                            >>no
                            >> >> >>caso
                            >> >> >> >>do
                            >> >> >> >> >> >>exemplo
                            >> >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo
                            >>sem
                            >> >> >> >>Assinante.
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente
                            >>dos
                            >> >> >> >>vídeos
                            >> >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                            >> >>Assinante
                            >> >> >>eu
                            >> >> >> >> >>uso
                            >> >> >> >> >> >>só
                            >> >> >> >> >> >> >>para
                            >> >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                            >> >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video>
                            >>será
                            >> >> >> >> >>preenchido
                            >> >> >> >> >> >>com
                            >> >> >> >> >> >> >>os
                            >> >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                            >> >> >> >>recuperar
                            >> >> >> >> >>pelo
                            >> >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Na minha Action:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> request.setAttribute("Busca_Videos",
                            >>listVideos);
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> No meu JSP:
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                            >> >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                            >> >>name="Busca_Videos">
                            >> >> >> >> >> >> >> >> <bean:write name="resulBusca" property="title"
                            >>/>
                            >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                            >> >>property="description"
                            >> >> >>/>
                            >> >> >> >> >> >> >> >> </logic:iterate>
                            >> >> >> >> >> >> >> >> </logic:notEmpty>
                            >> >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                            >> >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                            >> >> >> >> >> >> >> >> </logic:empty>
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                            >> >>recuperar
                            >> >> >>em
                            >> >> >> >>cima
                            >> >> >> >> >>da
                            >> >> >> >> >> >> >>busca
                            >> >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Grato desde já,
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >> Anderson Moraes
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> >
                            >> >> >> >> >> >> >> > --
                            >> >> >> >> >> >> >> > Victor Guilherme Hogemann
                            >> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >>
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> >
                            >> >> >> >> >> >> > --
                            >> >> >> >> >> >> > Victor Guilherme Hogemann
                            >> >> >> >> >> >> > http://victor.hogemann.eti.br
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >>
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> >
                            >> >> >> >> >> > --
                            >> >> >> >> >> > Victor Guilherme Hogemann
                            >> >> >> >> >> > http://victor.hogemann.eti.br
                            >> >> >> >> >>
                            >> >> >> >> >>
                            >> >> >> >> >>
                            >> >> >> >> >
                            >> >> >> >> >
                            >> >> >> >> >
                            >> >> >> >> > --
                            >> >> >> >> > Victor Guilherme Hogemann
                            >> >> >> >> > http://victor.hogemann.eti.br
                            >> >> >> >>
                            >> >> >> >>
                            >> >> >> >>
                            >> >> >> >
                            >> >> >> >
                            >> >> >> >
                            >> >> >> > --
                            >> >> >> > Victor Guilherme Hogemann
                            >> >> >> > http://victor.hogemann.eti.br
                            >> >> >>
                            >> >> >>
                            >> >> >>
                            >> >> >
                            >> >> >
                            >> >> >
                            >> >> > --
                            >> >> > Victor Guilherme Hogemann
                            >> >> > http://victor.hogemann.eti.br
                            >> >>
                            >> >>
                            >> >>
                            >> >
                            >> >
                            >> >
                            >> > --
                            >> > Victor Guilherme Hogemann
                            >> > http://victor.hogemann.eti.br
                            >>
                            >>
                            >>
                            >
                            >
                            >
                            > --
                            > Victor Guilherme Hogemann
                            > http://victor.hogemann.eti.br
                          • Victor Hogemann
                            Cara... Remove o casting de : * T entity = (T) obj;* //APAGUE ESSA LINHA E salva direto o objeto que você pega na iteração: fullTextSession.index(obj);
                            Message 13 of 21 , Oct 6, 2009
                            • 0 Attachment
                              Cara...

                              Remove o casting de :

                              T entity = (T) obj;
                               //APAGUE ESSA LINHA

                              E salva direto o objeto que você pega na iteração:

                              fullTextSession.index(obj); //REINDEXA OBJ DIRETAMENTE, SEM O CASTING

                              O T é um resquício do código original que eu te mandei, que usava generics pra deixar as coisas mais elegantes...

                              [ ]s

                              2009/10/5 Anderson Moraes <amoraes@...>
                               

                              Victor, minha classe ficou assim:

                              package esseecraque.action;

                              import org.hibernate.Criteria;
                              import org.hibernate.Session;
                              import org.hibernate.search.FullTextSession;
                              import org.hibernate.search.Search;

                              import esseecraque.util.HibernateUtil;

                              public class AtualizaIndice {



                              public void refreshIndex(final Class entityClass) {

                              Session session = HibernateUtil.getSessionFactory().openSession();

                              FullTextSession fullTextSession =
                              Search.getFullTextSession(session);

                              Criteria crit = session.createCriteria(entityClass);

                              for (Object obj : crit.list()) {
                              T entity = (T) obj;
                              fullTextSession.index(entity);
                              }

                              }

                              }

                              Mas tá com erro na linha "T entity = (T) obj;"
                              Diz que "T" não pode ser definido para o tipo, o que eu preciso fazer
                              para resolver esse problema?

                              Após resolver esse problema basta eu instanciar um objeto
                              AtualizaIndice e chamar o método, como abaixo?

                              AtualizaIndice ai = new AtualizaIndice();

                              ai.refreshIndex(Assinante.class);
                              ai.refreshIndex(Video.class);

                              é isso???

                              Grato mais uma vez Victor...

                              On Mon, 5 Oct 2009 18:21:50 -0300

                              Victor Hogemann <victor.hogemann@...> wrote:
                              > Anderson,
                              > Nesse caso, você vai utilizar só esse miolo aqui:
                              >
                              >FullTextSession fullTextSession = Search.getFullTextSession(session);
                              >
                              > Criteria crit = session.createCriteria(entityClass);
                              >
                              > for (Object obj : crit.list()) {
                              >
                              > T entity = (T) obj;
                              >
                              > fullTextSession.index(entity);
                              >
                              > }
                              >
                              >
                              > Sendo que session é um Session do Hibernate. Encare como se fosse um
                              >outro
                              > método qualquer de um DAO seu.
                              >
                              > [ ]s
                              >
                              > 2009/10/5 Anderson Moraes <amoraes@...>
                              >
                              >>
                              >>
                              >> Estou utilizando STRUTS, como ficaria o mesmo nesse caso???
                              >>
                              >> On Mon, 5 Oct 2009 17:47:21 -0300
                              >>
                              >> Victor Hogemann <victor.hogemann@...
                              >><victor.hogemann%40gmail.com>>
                              >> wrote:
                              >> > Anderson,
                              >> > Desculpe... esse método está feito pra usar o suporte a Hibernate
                              >>do
                              >> > SpringFramework. Você vai ter que alterar ele se estiver usando o
                              >> >Hibernate
                              >> > "na unha".
                              >> >
                              >> > [ ]s
                              >> >
                              >> > 2009/10/5 Anderson Moraes
                              >><amoraes@...<amoraes%40tecmetal.com.br>

                              >> >
                              >> >
                              >> >>
                              >> >>
                              >> >> Está dando erro em "this.getHibernateTemplate().execute(new
                              >> >> HibernateCallback(){", diz que os métodos getHibernateTemplate()
                              >>é
                              >> >> indefinido e que HibernateCallback() não pode ser definido para o
                              >> >> tipo.
                              >> >>
                              >> >> On Mon, 5 Oct 2009 14:48:47 -0300
                              >> >>
                              >> >> Victor Hogemann
                              >><victor.hogemann@...<victor.hogemann%40gmail.com>
                              >> >><victor.hogemann%40gmail.com>>
                              >> >> wrote:
                              >> >> > Anderson,
                              >> >> > Pode fazer dentro de um main sim, e o método serve pra qualquer
                              >> >> >entidade
                              >> >> > indexada com hibernate-search... Por exemplo, basta chamar
                              >> >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no
                              >>seu
                              >> >> >caso.
                              >> >> >
                              >> >> > [ ]s
                              >> >> >
                              >> >> > 2009/10/5 Anderson Moraes
                              >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%

                              >> 40tecmetal.com.br>
                              >>
                              >> >> >
                              >> >> >
                              >> >> >>
                              >> >> >>
                              >> >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar
                              >>dentro
                              >> >>de
                              >> >> >>um
                              >> >> >> main mesmo???
                              >> >> >>
                              >> >> >> Esse exemplo que você me mandou serve para o meu caso ou tenho
                              >> >>que
                              >> >> >> fazer alguma modificação???
                              >> >> >>
                              >> >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela força...
                              >> >> >>
                              >> >> >> Abraço,
                              >> >> >>
                              >> >> >> Anderson
                              >> >> >>
                              >> >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                              >> >> >>
                              >> >> >> Victor Hogemann
                              >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                              >> <victor.hogemann%40gmail.com>
                              >> >> >><victor.hogemann%40gmail.com>>
                              >> >> >> wrote:
                              >> >> >> > Anderson,
                              >> >> >> > Se você estiver fazendo uma aplicação Web pode colocar
                              >>dentro
                              >> >>de
                              >> >> >>um
                              >> >> >> >método
                              >> >> >> > de um controller qualquer, ou até mesmo dentro de um servlet
                              >> >> >> >separado... O
                              >> >> >> > importante é chama-lo sem ninguém estar fazendo alterações
                              >>na
                              >> >> >> >persistência.
                              >> >> >> >
                              >> >> >> > [ ]s
                              >> >> >> >
                              >> >> >> > 2009/10/2 Anderson Moraes
                              >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                              >> 40tecmetal.com.br><amoraes%
                              >>
                              >> >> 40tecmetal.com.br>
                              >> >>
                              >> >> >> >
                              >> >> >> >
                              >> >> >> >>
                              >> >> >> >>
                              >> >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o
                              >>método
                              >> >> >>que
                              >> >> >> >>vc
                              >> >> >> >> me mando, como chamar...
                              >> >> >> >>
                              >> >> >> >> Desde já muito obrigado pela força que está me dando.
                              >> >> >> >>
                              >> >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                              >> >> >> >>
                              >> >> >> >> Victor Hogemann
                              >> >> >><victor.hogemann@...
                              >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> 40gmail.com>
                              >> >> <victor.hogemann%40gmail.com>
                              >> >> >> >><victor.hogemann%40gmail.com>>
                              >> >> >> >> wrote:
                              >> >> >> >> > Anderson,
                              >> >> >> >> > Imagine a seguinte situação... Sua aplicação está
                              >> >>funcionando,
                              >> >> >>e
                              >> >> >> >>de
                              >> >> >> >> >repente
                              >> >> >> >> > alguma coisa sai errada e o seu servidor capota. Beleza,
                              >> >>você
                              >> >> >>tem
                              >> >> >> >>o
                              >> >> >> >> >backup
                              >> >> >> >> > do seu banco de dados, mas e os índices do Hibernate
                              >>Search?
                              >> >> >> >> >
                              >> >> >> >> > Claro, você poderia fazer backup desses também... mas
                              >> >>imagine
                              >> >> >>que
                              >> >> >> >> >não tenha
                              >> >> >> >> > feito. Você vai precisar reconstruir seus índices a
                              >>partir
                              >> >>das
                              >> >> >> >> >entidades
                              >> >> >> >> > persistidas no banco, pra isso serve o método que eu te
                              >> >>passei.
                              >> >> >> >> >
                              >> >> >> >> > Como você alterou o mapeamento das entidades no Hibernate
                              >> >> >>Search,
                              >> >> >> >> >logo mudou
                              >> >> >> >> > a estrutura do índice, e aí é necessário re-indexar tudo
                              >> >> >> >>novamente.
                              >> >> >> >> >
                              >> >> >> >> > Sacou?
                              >> >> >> >> >
                              >> >> >> >> > 2009/10/2 Anderson Moraes
                              >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                              >><amoraes%
                              >> 40tecmetal.com.br> <amoraes%
                              >> >> 40tecmetal.com.br><amoraes%
                              >> >>
                              >> >> >> 40tecmetal.com.br>
                              >> >> >>
                              >> >> >> >> >
                              >> >> >> >> >
                              >> >> >> >> >>
                              >> >> >> >> >>
                              >> >> >> >> >> Não entendi como eu executo essa classe, em que
                              >>momento...
                              >> >> >> >> >>
                              >> >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                              >> >> >> >> >>
                              >> >> >> >> >> Victor Hogemann
                              >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                              >> >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> >> 40gmail.com>
                              >> >> >> <victor.hogemann%40gmail.com>
                              >> >> >> >> >><victor.hogemann%40gmail.com>>
                              >> >> >> >> >> wrote:
                              >> >> >> >> >> > Anderson,
                              >> >> >> >> >> > Você re-indexou suas entidades? Toda vez que você muda
                              >>o
                              >> >> >> >> >>mapeamento
                              >> >> >> >> >> >os
                              >> >> >> >> >> > índices são criados novamente, e você precisa
                              >>re-indexar
                              >> >>as
                              >> >> >> >> >> >entidades que já
                              >> >> >> >> >> > existiam... senão vai ficar com o índice vazio. Segue
                              >>um
                              >> >> >> >>exemplo
                              >> >> >> >> >>de
                              >> >> >> >> >> >como
                              >> >> >> >> >> > fazer:
                              >> >> >> >> >> >
                              >> >> >> >> >> > public void refreshIndex(final Class entityClass) {
                              >> >> >> >> >> >
                              >> >> >> >> >> > this.getHibernateTemplate().execute(new
                              >> >>HibernateCallback()
                              >> >> >>{
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> > public Object doInHibernate(Session session)
                              >> >> >> >> >> > throwsHibernateException, SQLException {
                              >> >> >> >> >>
                              >> >> >> >> >> >
                              >> >> >> >> >> > FullTextSession fullTextSession =
                              >> >> >> >> >> > Search.getFullTextSession(session);
                              >> >> >> >> >> >
                              >> >> >> >> >> > Criteria crit = session.createCriteria(entityClass);
                              >> >> >> >> >> >
                              >> >> >> >> >> > for (Object obj : crit.list()) {
                              >> >> >> >> >> >
                              >> >> >> >> >> > T entity = (T) obj;
                              >> >> >> >> >> >
                              >> >> >> >> >> > fullTextSession.index(entity);
                              >> >> >> >> >> >
                              >> >> >> >> >> > }
                              >> >> >> >> >> >
                              >> >> >> >> >> > return null;
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> > }
                              >> >> >> >> >> >
                              >> >> >> >> >> > });
                              >> >> >> >> >> >
                              >> >> >> >> >> > }
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> > [ ]s
                              >> >> >> >> >> >
                              >> >> >> >> >> > 2009/10/2 Anderson Moraes
                              >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                              >><amoraes%
                              >> 40tecmetal.com.br>
                              >> >><amoraes%
                              >> >> 40tecmetal.com.br> <amoraes%
                              >> >> >> 40tecmetal.com.br><amoraes%
                              >> >> >>
                              >> >> >> >> 40tecmetal.com.br>
                              >> >> >> >>
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que
                              >>fiz,
                              >> >> >>abaixo
                              >> >> >> >> >>vou
                              >> >> >> >> >> >> mostrar o SQL que sai no console:
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> try{
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> final Session session =
                              >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                              >> >> >> >> >> >> final FullTextSession ftSession =
                              >> >> >> >> >> >> Search.getFullTextSession(session);
                              >> >> >> >> >> >> final List<Video> videos =
                              >> >> >> >> >> >> session.createCriteria(Video.class).list();
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> for(Video v : videos) {
                              >> >> >> >> >> >> ftSession.index(v);
                              >> >> >> >> >> >> }
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> final String[] stopWords =
                              >> >> >> >> >> >> {"de","do","da","dos","das","a","o","na","no","em"};
                              >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                              >> >> >> >> >> >> MultiFieldQueryParser(new
                              >> >> >> >> >> >> String[]{"Video.assinante.nome","Video.description"}
                              >>,
                              >> >>new
                              >> >> >> >> >> >> StopAnalyzer(stopWords));
                              >> >> >> >> >> >> final Query query = parser.parse("Moraes");
                              >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                              >> >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> if (list==null || list.size()==0){
                              >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                              >> >> >> >> >> >> }else{
                              >> >> >> >> >> >> for (Video v : list) {
                              >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                              >> >> >> >> >> >> }
                              >> >> >> >> >> >> }
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> }catch(Exception e){
                              >> >> >> >> >> >> e.printStackTrace();
                              >> >> >> >> >> >> }
                              >> >> >> >> >> >> }
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> CONSOLE:
                              >> >> >> >> >> >> Hibernate:
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> select
                              >> >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                              >> >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                              >> >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                              >> >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                              >> >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                              >> >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                              >> >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                              >> >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                              >> >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                              >> >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                              >> >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                              >> >> >> >> >> >> from
                              >> >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                              >> >>assinante2_
                              >> >> >>on
                              >> >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome Moraes.
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> Victor Hogemann
                              >> >> >> >> >><victor.hogemann@...
                              >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> 40gmail.com>
                              >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> >> >> 40gmail.com>
                              >> >> >> >> <victor.hogemann%40gmail.com>
                              >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                              >> >> >> >> >> >> wrote:
                              >> >> >> >> >> >> > Anderson,
                              >> >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista de
                              >> >> >>vídeos
                              >> >> >> >>do
                              >> >> >> >> >> >> >Assinante:
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> > @ContainedIn
                              >> >> >> >> >> >> > @OneToMany(mappedBy="assinante",
                              >>fetch=FetchType.LAZY)
                              >> >> >> >> >> >> > @Cascade(CascadeType.ALL)
                              >> >> >> >> >> >> > @IndexedEmbedded
                              >> >> >> >> >> >> > private List<Video> Videos;
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> > [ ]s
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                              >> >> >> >> >> >><amoraes@...
                              >><amoraes%40tecmetal.com.br><amoraes%
                              >> 40tecmetal.com.br>
                              >> >><amoraes%
                              >> >> 40tecmetal.com.br>
                              >> >> >><amoraes%
                              >> >> >> 40tecmetal.com.br> <amoraes%
                              >> >> >> >> 40tecmetal.com.br><amoraes%
                              >> >> >> >>
                              >> >> >> >> >> 40tecmetal.com.br>
                              >> >> >> >> >>
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> Não consegui acertar meu método, segue as minhas
                              >> >> >>Classes:
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> ASSINANTE:
                              >> >> >> >> >> >> >> @Entity
                              >> >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                              >> >> >> >> >> >> >> @Indexed
                              >> >> >> >> >> >> >> public class Assinante extends PersistentObject
                              >> >> >>implements
                              >> >> >> >> >> >> >> Serializable{
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> @Id
                              >> >> >> >> >> >> >> @GeneratedValue(strategy =
                              >>GenerationType.IDENTITY)
                              >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                              >> >> >> >> >> >> >> private Long id;
                              >> >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                              >> >> >> >> >> >> >> private String email;
                              >> >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                              >> >> >> >> >> >> >> private String password;
                              >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                              >> >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                              >> >> >> >> >> >> >> private String nome;
                              >> >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                              >> >> >> >> >> >> >> private String cpf;
                              >> >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                              >> >> >> >> >> >> >> private String endereco;
                              >> >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                              >> >> >> >> >> >> >> private String cidade;
                              >> >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                              >> >> >> >> >> >> >> private String estado;
                              >> >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                              >> >> >> >> >> >> >> private String dataCadastro;
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> @ContainedIn
                              >> >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                              >> >>fetch=FetchType.LAZY)
                              >> >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                              >> >> >> >> >> >> >> @IndexedEmbedded
                              >> >> >> >> >> >> >> private List<Video> Videos;
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> VÍDEO:
                              >> >> >> >> >> >> >> @Entity
                              >> >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                              >> >> >> >> >> >> >> @Indexed
                              >> >> >> >> >> >> >> public class Video implements Serializable{
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> @Id
                              >> >> >> >> >> >> >> @GeneratedValue(strategy =
                              >>GenerationType.IDENTITY)
                              >> >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                              >> >> >> >> >> >> >> private Long id;
                              >> >> >> >> >> >> >> @Column(name="VC_TITLE")
                              >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                              >> >> >> >> >> >> >> private String title;
                              >> >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                              >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                              >> >> >> >> >> >> >> private String description;
                              >> >> >> >> >> >> >> @Column(name="VC_URL")
                              >> >> >> >> >> >> >> private String url;
                              >> >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                              >> >> >> >> >> >> >> private String realPath;
                              >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                              >> >> >> >> >> >> >> private Long idAssinante;
                              >> >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                              >> >> >> >> >> >> >> private String dataUpload;
                              >> >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                              >> >> >> >> >> >> >> private String pathImage;
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> @IndexedEmbedded
                              >> >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                              >> >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE",
                              >>insertable=false,
                              >> >> >> >> >> >> >> updatable=false)
                              >> >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                              >> >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                              >> >> >> >> >> >> >> private Assinante assinante;
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> Deu erro:
                              >> >> >> >> >> >> >> Caused by: org.hibernate.search.SearchException:
                              >> >> >>Circular
                              >> >> >> >> >> >>reference.
                              >> >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                              >> >>entity
                              >> >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                              >> >> >> >> >> >> >> Victor Hogemann
                              >> >> >> >> >> >><victor.hogemann@...
                              >><victor.hogemann%40gmail.com>
                              >> >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> >> 40gmail.com>
                              >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                              >> >> >> >> 40gmail.com>
                              >> >> >> >> >> <victor.hogemann%40gmail.com>
                              >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> >> wrote:
                              >> >> >> >> >> >> >> > Anderson,
                              >> >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                              >> >> >>associação
                              >> >> >> >> >> >> >> >bi-direcional entre
                              >> >> >> >> >> >> >> > Assinante e Video, assim você pode a partir do
                              >> >>Video
                              >> >> >> >>filtrar
                              >> >> >> >> >> >>pelo
                              >> >> >> >> >> >> >> >nome do
                              >> >> >> >> >> >> >> > assinante usando somente uma query Lucene... Por
                              >> >> >>exemplo:
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                              >> >> >> >> >> >>Term("Video.assinante.nome",
                              >> >> >> >> >> >> >> >"Fulano"));
                              >> >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                              >> >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                              >> >> >>Video.class);
                              >> >> >> >> >> >> >> > return fullTextQuery.list();
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > Pelo que você escreveu a associação entre
                              >>Assinante
                              >> >>e
                              >> >> >> >>Vídeo
                              >> >> >> >> >>é
                              >> >> >> >> >> >> >> >one-to-many,
                              >> >> >> >> >> >> >> > então não vai ser uma mudança tão traumática
                              >>assim
                              >> >>no
                              >> >> >> >> >>código. O
                              >> >> >> >> >> >> >> >pulo-do-gato
                              >> >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                              >> >>Assinante
                              >> >> >>no
                              >> >> >> >> >>indice
                              >> >> >> >> >> >>de
                              >> >> >> >> >> >> >> >Vídeo,
                              >> >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                              >> >> >> >>@ContainedIn.
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > Em Vídeo você vai ter:
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > @IndexedEmbeded
                              >> >> >> >> >> >> >> > @OneToOne
                              >> >> >> >> >> >> >> > Assinante assinante;
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > E em Assinante vai ficar:
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > @ContainedIn
                              >> >> >> >> >> >> >> > @OneToMany
                              >> >> >> >> >> >> >> > List<Video> videos;
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de
                              >>hibernate-search,
                              >> >> >>que
                              >> >> >> >> >> >> >>basicamente
                              >> >> >> >> >> >> >> >é um
                              >> >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                              >> >>hibernate
                              >> >> >> >> >>search.
                              >> >> >> >> >> >>No
                              >> >> >> >> >> >> >> >exemplo que
                              >> >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                              >> >> >>entidades
                              >> >> >> >> >> >> >>associadas:
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                              >> >> >> >> >> >> >><amoraes@...
                              >><amoraes%40tecmetal.com.br>
                              >> >><amoraes%40tecmetal.com.br><amoraes%
                              >> >> 40tecmetal.com.br>
                              >> >> >><amoraes%
                              >> >> >> 40tecmetal.com.br>
                              >> >> >> >><amoraes%
                              >> >> >> >> 40tecmetal.com.br> <amoraes%
                              >> >> >> >> >> 40tecmetal.com.br><amoraes%
                              >> >> >> >> >>
                              >> >> >> >> >> >> 40tecmetal.com.br>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Pessoal, bom dia.
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                              >> >>primeiro
                              >> >> >>vou
                              >> >> >> >> >> >> >>descrever
                              >> >> >> >> >> >> >> >>os
                              >> >> >> >> >> >> >> >> atributos da minha bean:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> BEAN Assinante:
                              >> >> >> >> >> >> >> >> id
                              >> >> >> >> >> >> >> >> nome
                              >> >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                              >> >> >>Collection<Video>
                              >> >> >> >> >> >>Videos;)
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> BEAN Video:
                              >> >> >> >> >> >> >> >> id
                              >> >> >> >> >> >> >> >> title
                              >> >> >> >> >> >> >> >> description
                              >> >> >> >> >> >> >> >> idAssinante
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Blz, até aí tudo bem.
                              >> >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma
                              >>busca
                              >> >>nas
                              >> >> >> >>duas
                              >> >> >> >> >> >> >>classes
                              >> >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco no
                              >> >> >>atributo
                              >> >> >> >> >>"nome"
                              >> >> >> >> >> >>e
                              >> >> >> >> >> >> >>em
                              >> >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                              >> >>"description",
                              >> >> >> >>segue
                              >> >> >> >> >>o
                              >> >> >> >> >> >> >>método
                              >> >> >> >> >> >> >> >> abaixou:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> ************** MÉTODO ********************
                              >> >> >> >> >> >> >> >> try{
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> final Session session =
                              >> >> >> >> >> >> >> >>
                              >>HibernateUtil.getSessionFactory().openSession();
                              >> >> >> >> >> >> >> >> final FullTextSession ftSession =
                              >> >> >> >> >> >> >> >> Search.getFullTextSession(session);
                              >> >> >> >> >> >> >> >> final List<Assinante> assinantes =
                              >> >> >> >> >> >> >> >> session.createCriteria(Assinante.class).list();
                              >> >> >> >> >> >> >> >> final List<Video> videos =
                              >> >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                              >> >> >> >> >> >> >> >> ftSession.index(a);
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> for(Video v : videos) {
                              >> >> >> >> >> >> >> >> ftSession.index(v);
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> final String[] stopWords =
                              >> >> >> >> >> >> >> >>
                              >> >>{"de","do","da","dos","das","a","o","na","no","em"};
                              >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                              >> >> >> >> >> >> >>MultiFieldQueryParser(new
                              >> >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                              >> >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                              >> >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                              >> >>Flamengo");
                              >> >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                              >> >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                              >> >> >>Assinante.class);
                              >> >> >> >> >> >> >> >> final List<Assinante> list =
                              >>fullTextQuery.list();
                              >> >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> }catch(Exception e){
                              >> >> >> >> >> >> >> >> e.printStackTrace();
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> ************** FIM MÉTODO ********************
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha que
                              >>eu
                              >> >> >>vou
                              >> >> >> >> >> >>destacar
                              >> >> >> >> >> >> >> >>abaixo
                              >> >> >> >> >> >> >> >> que eu informo em que campos procurar:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                              >> >> >> >> >> >> >>MultiFieldQueryParser(new
                              >> >> >> >> >> >> >> >>
                              >> >>String[]{"nome","Videos.title","Videos.description"}
                              >> >> >>,
                              >> >> >> >>new
                              >> >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> if (list==null || list.size()==0){
                              >> >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                              >> >> >> >> >> >> >> >> }else{
                              >> >> >> >> >> >> >> >> for(Assinante a : list) {
                              >> >> >> >> >> >> >> >> System.out.println(a.getNome());
                              >> >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                              >> >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >> }
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus Vídeos.
                              >> >> >> >> >> >> >> >> Ex.:
                              >> >> >> >> >> >> >> >> Anderson Moraes
                              >> >> >> >> >> >> >> >> Vídeo 1
                              >> >> >> >> >> >> >> >> Vídeo 4
                              >> >> >> >> >> >> >> >> Vídeo 9
                              >> >> >> >> >> >> >> >> Elba Ramalho
                              >> >> >> >> >> >> >> >> Vídeo 3
                              >> >> >> >> >> >> >> >> Vídeo 7
                              >> >> >> >> >> >> >> >> Raul Seixas
                              >> >> >> >> >> >> >> >> Zé Ramalho
                              >> >> >> >> >> >> >> >> Vídeo 2
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem vídeo,
                              >>no
                              >> >> >>caso
                              >> >> >> >>do
                              >> >> >> >> >> >>exemplo
                              >> >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo
                              >>sem
                              >> >> >> >>Assinante.
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List somente
                              >>dos
                              >> >> >> >>vídeos
                              >> >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                              >> >>Assinante
                              >> >> >>eu
                              >> >> >> >> >>uso
                              >> >> >> >> >> >>só
                              >> >> >> >> >> >> >>para
                              >> >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                              >> >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu list<Video>
                              >>será
                              >> >> >> >> >>preenchido
                              >> >> >> >> >> >>com
                              >> >> >> >> >> >> >>os
                              >> >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão para
                              >> >> >> >>recuperar
                              >> >> >> >> >>pelo
                              >> >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Na minha Action:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> request.setAttribute("Busca_Videos",
                              >>listVideos);
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> No meu JSP:
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                              >> >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                              >> >>name="Busca_Videos">
                              >> >> >> >> >> >> >> >> <bean:write name="resulBusca" property="title"
                              >>/>
                              >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                              >> >>property="description"
                              >> >> >>/>
                              >> >> >> >> >> >> >> >> </logic:iterate>
                              >> >> >> >> >> >> >> >> </logic:notEmpty>
                              >> >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                              >> >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                              >> >> >> >> >> >> >> >> </logic:empty>
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                              >> >>recuperar
                              >> >> >>em
                              >> >> >> >>cima
                              >> >> >> >> >>da
                              >> >> >> >> >> >> >>busca
                              >> >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Grato desde já,
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >> Anderson Moraes
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> >
                              >> >> >> >> >> >> >> > --
                              >> >> >> >> >> >> >> > Victor Guilherme Hogemann
                              >> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >>
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> >
                              >> >> >> >> >> >> > --
                              >> >> >> >> >> >> > Victor Guilherme Hogemann
                              >> >> >> >> >> >> > http://victor.hogemann.eti.br
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >>
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> >
                              >> >> >> >> >> > --
                              >> >> >> >> >> > Victor Guilherme Hogemann
                              >> >> >> >> >> > http://victor.hogemann.eti.br
                              >> >> >> >> >>
                              >> >> >> >> >>
                              >> >> >> >> >>
                              >> >> >> >> >
                              >> >> >> >> >
                              >> >> >> >> >
                              >> >> >> >> > --
                              >> >> >> >> > Victor Guilherme Hogemann
                              >> >> >> >> > http://victor.hogemann.eti.br
                              >> >> >> >>
                              >> >> >> >>
                              >> >> >> >>
                              >> >> >> >
                              >> >> >> >
                              >> >> >> >
                              >> >> >> > --
                              >> >> >> > Victor Guilherme Hogemann
                              >> >> >> > http://victor.hogemann.eti.br
                              >> >> >>
                              >> >> >>
                              >> >> >>
                              >> >> >
                              >> >> >
                              >> >> >
                              >> >> > --
                              >> >> > Victor Guilherme Hogemann
                              >> >> > http://victor.hogemann.eti.br
                              >> >>
                              >> >>
                              >> >>
                              >> >
                              >> >
                              >> >
                              >> > --
                              >> > Victor Guilherme Hogemann
                              >> > http://victor.hogemann.eti.br
                              >>
                              >>
                              >>
                              >
                              >
                              >
                              > --
                              > Victor Guilherme Hogemann
                              > http://victor.hogemann.eti.br




                              --
                              Victor Guilherme Hogemann
                              http://victor.hogemann.eti.br
                            • Anderson Moraes
                              Victor, eu executei a classe da seguinte forma: public class AtualizaIndice { public void refreshIndex(final Class entityClass) { Session session =
                              Message 14 of 21 , Oct 6, 2009
                              • 0 Attachment
                                Victor, eu executei a classe da seguinte forma:

                                public class AtualizaIndice {

                                public void refreshIndex(final Class entityClass) {

                                Session session = HibernateUtil.getSessionFactory().openSession();

                                FullTextSession fullTextSession =
                                Search.getFullTextSession(session);

                                Criteria crit = session.createCriteria(entityClass);

                                for (Object obj : crit.list()) {
                                fullTextSession.index(obj);
                                }

                                }

                                public static void main(final String[] args) throws Exception {

                                AtualizaIndice ai = new AtualizaIndice();

                                ai.refreshIndex(Assinante.class);
                                ai.refreshIndex(Video.class);

                                }

                                }


                                Depois eu realizai o seguinte teste:

                                public class AppBuscaTest {


                                @SuppressWarnings("unchecked")
                                public static void main(final String[] args) throws Exception {

                                try{

                                final Session session =
                                HibernateUtil.getSessionFactory().openSession();
                                final FullTextSession ftSession =
                                Search.getFullTextSession(session);
                                final List<Video> videos =
                                session.createCriteria(Video.class).list();

                                for(Video v : videos) {
                                ftSession.index(v);
                                }


                                final String[] stopWords =
                                {"de","do","da","dos","das","a","o","na","no","em"};
                                final MultiFieldQueryParser parser = new
                                MultiFieldQueryParser(new
                                String[]{"Video.assinante.nome","Video.title"} , new
                                StopAnalyzer(stopWords));
                                final Query query = parser.parse("Moraes");
                                final FullTextQuery fullTextQuery =
                                ftSession.createFullTextQuery(query, Video.class);

                                final List<Video> list = fullTextQuery.list();


                                HibernateUtil.getSessionFactory().close();


                                if (list==null || list.size()==0){
                                System.out.println("Nenhum Vídeo encontrado.");
                                }else{

                                for (Video v : list) {
                                System.out.println(" " + v.getTitle());
                                }

                                }

                                }catch(Exception e){
                                e.printStackTrace();
                                }
                                }


                                }

                                Mas não retorna nada, dá a mensagem: Nenhum Vídeo encontrado.

                                Errei alguma coisa???

                                Grato.

                                On Tue, 6 Oct 2009 12:40:20 -0300
                                Victor Hogemann <victor.hogemann@...> wrote:
                                > Cara...
                                > Remove o casting de :
                                >
                                > *
                                > T entity = (T) obj;* //APAGUE ESSA LINHA
                                >
                                > E salva direto o objeto que você pega na iteração:
                                >
                                > fullTextSession.index(obj); //REINDEXA OBJ DIRETAMENTE, SEM O
                                >CASTING
                                >
                                >
                                > O *T* é um resquício do código original que eu te mandei, que usava
                                >generics
                                > pra deixar as coisas mais elegantes...
                                >
                                > [ ]s
                                >
                                > 2009/10/5 Anderson Moraes <amoraes@...>
                                >
                                >>
                                >>
                                >> Victor, minha classe ficou assim:
                                >>
                                >> package esseecraque.action;
                                >>
                                >> import org.hibernate.Criteria;
                                >> import org.hibernate.Session;
                                >> import org.hibernate.search.FullTextSession;
                                >> import org.hibernate.search.Search;
                                >>
                                >> import esseecraque.util.HibernateUtil;
                                >>
                                >> public class AtualizaIndice {
                                >>
                                >>
                                >> public void refreshIndex(final Class entityClass) {
                                >>
                                >> Session session = HibernateUtil.getSessionFactory().openSession();
                                >>
                                >> FullTextSession fullTextSession =
                                >> Search.getFullTextSession(session);
                                >>
                                >> Criteria crit = session.createCriteria(entityClass);
                                >>
                                >> for (Object obj : crit.list()) {
                                >> T entity = (T) obj;
                                >> fullTextSession.index(entity);
                                >> }
                                >>
                                >> }
                                >>
                                >> }
                                >>
                                >> Mas tá com erro na linha "T entity = (T) obj;"
                                >> Diz que "T" não pode ser definido para o tipo, o que eu preciso
                                >>fazer
                                >> para resolver esse problema?
                                >>
                                >> Após resolver esse problema basta eu instanciar um objeto
                                >> AtualizaIndice e chamar o método, como abaixo?
                                >>
                                >> AtualizaIndice ai = new AtualizaIndice();
                                >>
                                >> ai.refreshIndex(Assinante.class);
                                >> ai.refreshIndex(Video.class);
                                >>
                                >> é isso???
                                >>
                                >> Grato mais uma vez Victor...
                                >>
                                >> On Mon, 5 Oct 2009 18:21:50 -0300
                                >> Victor Hogemann <victor.hogemann@...
                                >><victor.hogemann%40gmail.com>>
                                >> wrote:
                                >> > Anderson,
                                >> > Nesse caso, você vai utilizar só esse miolo aqui:
                                >> >
                                >> >FullTextSession fullTextSession =
                                >>Search.getFullTextSession(session);
                                >> >
                                >> > Criteria crit = session.createCriteria(entityClass);
                                >> >
                                >> > for (Object obj : crit.list()) {
                                >> >
                                >> > T entity = (T) obj;
                                >> >
                                >> > fullTextSession.index(entity);
                                >> >
                                >> > }
                                >> >
                                >> >
                                >> > Sendo que session é um Session do Hibernate. Encare como se fosse
                                >>um
                                >> >outro
                                >> > método qualquer de um DAO seu.
                                >> >
                                >> > [ ]s
                                >> >
                                >> > 2009/10/5 Anderson Moraes
                                >><amoraes@...<amoraes%40tecmetal.com.br>
                                >> >
                                >> >
                                >> >>
                                >> >>
                                >> >> Estou utilizando STRUTS, como ficaria o mesmo nesse caso???
                                >> >>
                                >> >> On Mon, 5 Oct 2009 17:47:21 -0300
                                >> >>
                                >> >> Victor Hogemann
                                >><victor.hogemann@...<victor.hogemann%40gmail.com>
                                >> >><victor.hogemann%40gmail.com>>
                                >> >> wrote:
                                >> >> > Anderson,
                                >> >> > Desculpe... esse método está feito pra usar o suporte a
                                >>Hibernate
                                >> >>do
                                >> >> > SpringFramework. Você vai ter que alterar ele se estiver usando
                                >>o
                                >> >> >Hibernate
                                >> >> > "na unha".
                                >> >> >
                                >> >> > [ ]s
                                >> >> >
                                >> >> > 2009/10/5 Anderson Moraes
                                >> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                                >> 40tecmetal.com.br>
                                >> >> >
                                >> >> >
                                >> >> >>
                                >> >> >>
                                >> >> >> Está dando erro em "this.getHibernateTemplate().execute(new
                                >> >> >> HibernateCallback(){", diz que os métodos
                                >>getHibernateTemplate()
                                >> >>é
                                >> >> >> indefinido e que HibernateCallback() não pode ser definido
                                >>para o
                                >> >> >> tipo.
                                >> >> >>
                                >> >> >> On Mon, 5 Oct 2009 14:48:47 -0300
                                >> >> >>
                                >> >> >> Victor Hogemann
                                >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                >> <victor.hogemann%40gmail.com>
                                >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> wrote:
                                >> >> >> > Anderson,
                                >> >> >> > Pode fazer dentro de um main sim, e o método serve pra
                                >>qualquer
                                >> >> >> >entidade
                                >> >> >> > indexada com hibernate-search... Por exemplo, basta chamar
                                >> >> >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no
                                >> >>seu
                                >> >> >> >caso.
                                >> >> >> >
                                >> >> >> > [ ]s
                                >> >> >> >
                                >> >> >> > 2009/10/5 Anderson Moraes
                                >> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                                >> 40tecmetal.com.br><amoraes%
                                >>
                                >> >> 40tecmetal.com.br>
                                >> >>
                                >> >> >> >
                                >> >> >> >
                                >> >> >> >>
                                >> >> >> >>
                                >> >> >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar
                                >> >>dentro
                                >> >> >>de
                                >> >> >> >>um
                                >> >> >> >> main mesmo???
                                >> >> >> >>
                                >> >> >> >> Esse exemplo que você me mandou serve para o meu caso ou
                                >>tenho
                                >> >> >>que
                                >> >> >> >> fazer alguma modificação???
                                >> >> >> >>
                                >> >> >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela
                                >>força...
                                >> >> >> >>
                                >> >> >> >> Abraço,
                                >> >> >> >>
                                >> >> >> >> Anderson
                                >> >> >> >>
                                >> >> >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                                >> >> >> >>
                                >> >> >> >> Victor Hogemann
                                >> >> >><victor.hogemann@...
                                >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> 40gmail.com>
                                >> >> <victor.hogemann%40gmail.com>
                                >> >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> >> wrote:
                                >> >> >> >> > Anderson,
                                >> >> >> >> > Se você estiver fazendo uma aplicação Web pode colocar
                                >> >>dentro
                                >> >> >>de
                                >> >> >> >>um
                                >> >> >> >> >método
                                >> >> >> >> > de um controller qualquer, ou até mesmo dentro de um
                                >>servlet
                                >> >> >> >> >separado... O
                                >> >> >> >> > importante é chama-lo sem ninguém estar fazendo
                                >>alterações
                                >> >>na
                                >> >> >> >> >persistência.
                                >> >> >> >> >
                                >> >> >> >> > [ ]s
                                >> >> >> >> >
                                >> >> >> >> > 2009/10/2 Anderson Moraes
                                >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                >><amoraes%
                                >> 40tecmetal.com.br> <amoraes%
                                >> >> 40tecmetal.com.br><amoraes%
                                >> >>
                                >> >> >> 40tecmetal.com.br>
                                >> >> >>
                                >> >> >> >> >
                                >> >> >> >> >
                                >> >> >> >> >>
                                >> >> >> >> >>
                                >> >> >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o
                                >> >>método
                                >> >> >> >>que
                                >> >> >> >> >>vc
                                >> >> >> >> >> me mando, como chamar...
                                >> >> >> >> >>
                                >> >> >> >> >> Desde já muito obrigado pela força que está me dando.
                                >> >> >> >> >>
                                >> >> >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                                >> >> >> >> >>
                                >> >> >> >> >> Victor Hogemann
                                >> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> 40gmail.com>
                                >> >> >> <victor.hogemann%40gmail.com>
                                >> >> >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> >> >> wrote:
                                >> >> >> >> >> > Anderson,
                                >> >> >> >> >> > Imagine a seguinte situação... Sua aplicação está
                                >> >> >>funcionando,
                                >> >> >> >>e
                                >> >> >> >> >>de
                                >> >> >> >> >> >repente
                                >> >> >> >> >> > alguma coisa sai errada e o seu servidor capota.
                                >>Beleza,
                                >> >> >>você
                                >> >> >> >>tem
                                >> >> >> >> >>o
                                >> >> >> >> >> >backup
                                >> >> >> >> >> > do seu banco de dados, mas e os índices do Hibernate
                                >> >>Search?
                                >> >> >> >> >> >
                                >> >> >> >> >> > Claro, você poderia fazer backup desses também... mas
                                >> >> >>imagine
                                >> >> >> >>que
                                >> >> >> >> >> >não tenha
                                >> >> >> >> >> > feito. Você vai precisar reconstruir seus índices a
                                >> >>partir
                                >> >> >>das
                                >> >> >> >> >> >entidades
                                >> >> >> >> >> > persistidas no banco, pra isso serve o método que eu
                                >>te
                                >> >> >>passei.
                                >> >> >> >> >> >
                                >> >> >> >> >> > Como você alterou o mapeamento das entidades no
                                >>Hibernate
                                >> >> >> >>Search,
                                >> >> >> >> >> >logo mudou
                                >> >> >> >> >> > a estrutura do índice, e aí é necessário re-indexar
                                >>tudo
                                >> >> >> >> >>novamente.
                                >> >> >> >> >> >
                                >> >> >> >> >> > Sacou?
                                >> >> >> >> >> >
                                >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                >> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                >><amoraes%
                                >> 40tecmetal.com.br>
                                >> >><amoraes%
                                >> >> 40tecmetal.com.br> <amoraes%
                                >> >> >> 40tecmetal.com.br><amoraes%
                                >> >> >>
                                >> >> >> >> 40tecmetal.com.br>
                                >> >> >> >>
                                >> >> >> >> >> >
                                >> >> >> >> >> >
                                >> >> >> >> >> >>
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> Não entendi como eu executo essa classe, em que
                                >> >>momento...
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> Victor Hogemann
                                >> >> >> >> >><victor.hogemann@...
                                >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> 40gmail.com>
                                >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> >> 40gmail.com>
                                >> >> >> >> <victor.hogemann%40gmail.com>
                                >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> >> >> >> wrote:
                                >> >> >> >> >> >> > Anderson,
                                >> >> >> >> >> >> > Você re-indexou suas entidades? Toda vez que você
                                >>muda
                                >> >>o
                                >> >> >> >> >> >>mapeamento
                                >> >> >> >> >> >> >os
                                >> >> >> >> >> >> > índices são criados novamente, e você precisa
                                >> >>re-indexar
                                >> >> >>as
                                >> >> >> >> >> >> >entidades que já
                                >> >> >> >> >> >> > existiam... senão vai ficar com o índice vazio.
                                >>Segue
                                >> >>um
                                >> >> >> >> >>exemplo
                                >> >> >> >> >> >>de
                                >> >> >> >> >> >> >como
                                >> >> >> >> >> >> > fazer:
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > public void refreshIndex(final Class entityClass) {
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > this.getHibernateTemplate().execute(new
                                >> >> >>HibernateCallback()
                                >> >> >> >>{
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > public Object doInHibernate(Session session)
                                >> >> >> >> >> >> > throwsHibernateException, SQLException {
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > FullTextSession fullTextSession =
                                >> >> >> >> >> >> > Search.getFullTextSession(session);
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > Criteria crit =
                                >>session.createCriteria(entityClass);
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > for (Object obj : crit.list()) {
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > T entity = (T) obj;
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > fullTextSession.index(entity);
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > }
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > return null;
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > }
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > });
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > }
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > [ ]s
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                >> >> >> >> >> >><amoraes@...
                                >><amoraes%40tecmetal.com.br><amoraes%
                                >> 40tecmetal.com.br>
                                >> >><amoraes%
                                >> >> 40tecmetal.com.br>
                                >> >> >><amoraes%
                                >> >> >> 40tecmetal.com.br> <amoraes%
                                >> >> >> >> 40tecmetal.com.br><amoraes%
                                >> >> >> >>
                                >> >> >> >> >> 40tecmetal.com.br>
                                >> >> >> >> >>
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que
                                >> >>fiz,
                                >> >> >> >>abaixo
                                >> >> >> >> >> >>vou
                                >> >> >> >> >> >> >> mostrar o SQL que sai no console:
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> try{
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> final Session session =
                                >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                                >> >> >> >> >> >> >> final FullTextSession ftSession =
                                >> >> >> >> >> >> >> Search.getFullTextSession(session);
                                >> >> >> >> >> >> >> final List<Video> videos =
                                >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> for(Video v : videos) {
                                >> >> >> >> >> >> >> ftSession.index(v);
                                >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> final String[] stopWords =
                                >> >> >> >> >> >> >>
                                >>{"de","do","da","dos","das","a","o","na","no","em"};
                                >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                >> >> >> >> >> >> >> MultiFieldQueryParser(new
                                >> >> >> >> >> >> >>
                                >>String[]{"Video.assinante.nome","Video.description"}
                                >> >>,
                                >> >> >>new
                                >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                                >> >> >> >> >> >> >> final Query query = parser.parse("Moraes");
                                >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                                >> >> >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> if (list==null || list.size()==0){
                                >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                                >> >> >> >> >> >> >> }else{
                                >> >> >> >> >> >> >> for (Video v : list) {
                                >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                                >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> }catch(Exception e){
                                >> >> >> >> >> >> >> e.printStackTrace();
                                >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> CONSOLE:
                                >> >> >> >> >> >> >> Hibernate:
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> select
                                >> >> >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                                >> >> >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                                >> >> >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                                >> >> >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                                >> >> >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                                >> >> >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                                >> >> >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                                >> >> >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                                >> >> >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                                >> >> >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                                >> >> >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                                >> >> >> >> >> >> >> from
                                >> >> >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                                >> >> >>assinante2_
                                >> >> >> >>on
                                >> >> >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome
                                >>Moraes.
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> Victor Hogemann
                                >> >> >> >> >> >><victor.hogemann@...
                                >><victor.hogemann%40gmail.com>
                                >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> 40gmail.com>
                                >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> >> >> 40gmail.com>
                                >> >> >> >> >> <victor.hogemann%40gmail.com>
                                >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> >> >> >> >> wrote:
                                >> >> >> >> >> >> >> > Anderson,
                                >> >> >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista
                                >>de
                                >> >> >> >>vídeos
                                >> >> >> >> >>do
                                >> >> >> >> >> >> >> >Assinante:
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> > @ContainedIn
                                >> >> >> >> >> >> >> > @OneToMany(mappedBy="assinante",
                                >> >>fetch=FetchType.LAZY)
                                >> >> >> >> >> >> >> > @Cascade(CascadeType.ALL)
                                >> >> >> >> >> >> >> > @IndexedEmbedded
                                >> >> >> >> >> >> >> > private List<Video> Videos;
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> > [ ]s
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                >> >> >> >> >> >> >><amoraes@...
                                >><amoraes%40tecmetal.com.br>
                                >> >><amoraes%40tecmetal.com.br><amoraes%
                                >> >> 40tecmetal.com.br>
                                >> >> >><amoraes%
                                >> >> >> 40tecmetal.com.br>
                                >> >> >> >><amoraes%
                                >> >> >> >> 40tecmetal.com.br> <amoraes%
                                >> >> >> >> >> 40tecmetal.com.br><amoraes%
                                >> >> >> >> >>
                                >> >> >> >> >> >> 40tecmetal.com.br>
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> Não consegui acertar meu método, segue as
                                >>minhas
                                >> >> >> >>Classes:
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> ASSINANTE:
                                >> >> >> >> >> >> >> >> @Entity
                                >> >> >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                                >> >> >> >> >> >> >> >> @Indexed
                                >> >> >> >> >> >> >> >> public class Assinante extends PersistentObject
                                >> >> >> >>implements
                                >> >> >> >> >> >> >> >> Serializable{
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> @Id
                                >> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                >> >>GenerationType.IDENTITY)
                                >> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                >> >> >> >> >> >> >> >> private Long id;
                                >> >> >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String email;
                                >> >> >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String password;
                                >> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                >> >> >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String nome;
                                >> >> >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String cpf;
                                >> >> >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String endereco;
                                >> >> >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String cidade;
                                >> >> >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String estado;
                                >> >> >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                                >> >> >> >> >> >> >> >> private String dataCadastro;
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> @ContainedIn
                                >> >> >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                                >> >> >>fetch=FetchType.LAZY)
                                >> >> >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                                >> >> >> >> >> >> >> >> @IndexedEmbedded
                                >> >> >> >> >> >> >> >> private List<Video> Videos;
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> VÍDEO:
                                >> >> >> >> >> >> >> >> @Entity
                                >> >> >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                                >> >> >> >> >> >> >> >> @Indexed
                                >> >> >> >> >> >> >> >> public class Video implements Serializable{
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> @Id
                                >> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                >> >>GenerationType.IDENTITY)
                                >> >> >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                                >> >> >> >> >> >> >> >> private Long id;
                                >> >> >> >> >> >> >> >> @Column(name="VC_TITLE")
                                >> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                >> >> >> >> >> >> >> >> private String title;
                                >> >> >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                                >> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                >> >> >> >> >> >> >> >> private String description;
                                >> >> >> >> >> >> >> >> @Column(name="VC_URL")
                                >> >> >> >> >> >> >> >> private String url;
                                >> >> >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                                >> >> >> >> >> >> >> >> private String realPath;
                                >> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                >> >> >> >> >> >> >> >> private Long idAssinante;
                                >> >> >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                                >> >> >> >> >> >> >> >> private String dataUpload;
                                >> >> >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                                >> >> >> >> >> >> >> >> private String pathImage;
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> @IndexedEmbedded
                                >> >> >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                                >> >> >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE",
                                >> >>insertable=false,
                                >> >> >> >> >> >> >> >> updatable=false)
                                >> >> >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                                >> >> >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                                >> >> >> >> >> >> >> >> private Assinante assinante;
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> Deu erro:
                                >> >> >> >> >> >> >> >> Caused by:
                                >>org.hibernate.search.SearchException:
                                >> >> >> >>Circular
                                >> >> >> >> >> >> >>reference.
                                >> >> >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                                >> >> >>entity
                                >> >> >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                                >> >> >> >> >> >> >> >> Victor Hogemann
                                >> >> >> >> >> >> >><victor.hogemann@...
                                >><victor.hogemann%40gmail.com>
                                >> >><victor.hogemann%40gmail.com>
                                >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> >> 40gmail.com>
                                >> >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                >> >> >> >> >> 40gmail.com>
                                >> >> >> >> >> >> <victor.hogemann%40gmail.com>
                                >> >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> wrote:
                                >> >> >> >> >> >> >> >> > Anderson,
                                >> >> >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                                >> >> >> >>associação
                                >> >> >> >> >> >> >> >> >bi-direcional entre
                                >> >> >> >> >> >> >> >> > Assinante e Video, assim você pode a partir
                                >>do
                                >> >> >>Video
                                >> >> >> >> >>filtrar
                                >> >> >> >> >> >> >>pelo
                                >> >> >> >> >> >> >> >> >nome do
                                >> >> >> >> >> >> >> >> > assinante usando somente uma query Lucene...
                                >>Por
                                >> >> >> >>exemplo:
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                                >> >> >> >> >> >> >>Term("Video.assinante.nome",
                                >> >> >> >> >> >> >> >> >"Fulano"));
                                >> >> >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                                >> >> >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                                >> >> >> >>Video.class);
                                >> >> >> >> >> >> >> >> > return fullTextQuery.list();
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > Pelo que você escreveu a associação entre
                                >> >>Assinante
                                >> >> >>e
                                >> >> >> >> >>Vídeo
                                >> >> >> >> >> >>é
                                >> >> >> >> >> >> >> >> >one-to-many,
                                >> >> >> >> >> >> >> >> > então não vai ser uma mudança tão traumática
                                >> >>assim
                                >> >> >>no
                                >> >> >> >> >> >>código. O
                                >> >> >> >> >> >> >> >> >pulo-do-gato
                                >> >> >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                                >> >> >>Assinante
                                >> >> >> >>no
                                >> >> >> >> >> >>indice
                                >> >> >> >> >> >> >>de
                                >> >> >> >> >> >> >> >> >Vídeo,
                                >> >> >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                                >> >> >> >> >>@ContainedIn.
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > Em Vídeo você vai ter:
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > @IndexedEmbeded
                                >> >> >> >> >> >> >> >> > @OneToOne
                                >> >> >> >> >> >> >> >> > Assinante assinante;
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > E em Assinante vai ficar:
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > @ContainedIn
                                >> >> >> >> >> >> >> >> > @OneToMany
                                >> >> >> >> >> >> >> >> > List<Video> videos;
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de
                                >> >>hibernate-search,
                                >> >> >> >>que
                                >> >> >> >> >> >> >> >>basicamente
                                >> >> >> >> >> >> >> >> >é um
                                >> >> >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                                >> >> >>hibernate
                                >> >> >> >> >> >>search.
                                >> >> >> >> >> >> >>No
                                >> >> >> >> >> >> >> >> >exemplo que
                                >> >> >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                                >> >> >> >>entidades
                                >> >> >> >> >> >> >> >>associadas:
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >>
                                >>>>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                >> >> >> >> >> >> >> >><amoraes@...
                                >><amoraes%40tecmetal.com.br>
                                >> >><amoraes%40tecmetal.com.br>
                                >> >> >><amoraes%40tecmetal.com.br><amoraes%
                                >> >> >> 40tecmetal.com.br>
                                >> >> >> >><amoraes%
                                >> >> >> >> 40tecmetal.com.br>
                                >> >> >> >> >><amoraes%
                                >> >> >> >> >> 40tecmetal.com.br> <amoraes%
                                >> >> >> >> >> >> 40tecmetal.com.br><amoraes%
                                >> >> >> >> >> >>
                                >> >> >> >> >> >> >> 40tecmetal.com.br>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Pessoal, bom dia.
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                                >> >> >>primeiro
                                >> >> >> >>vou
                                >> >> >> >> >> >> >> >>descrever
                                >> >> >> >> >> >> >> >> >>os
                                >> >> >> >> >> >> >> >> >> atributos da minha bean:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> BEAN Assinante:
                                >> >> >> >> >> >> >> >> >> id
                                >> >> >> >> >> >> >> >> >> nome
                                >> >> >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                                >> >> >> >>Collection<Video>
                                >> >> >> >> >> >> >>Videos;)
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> BEAN Video:
                                >> >> >> >> >> >> >> >> >> id
                                >> >> >> >> >> >> >> >> >> title
                                >> >> >> >> >> >> >> >> >> description
                                >> >> >> >> >> >> >> >> >> idAssinante
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Blz, até aí tudo bem.
                                >> >> >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma
                                >> >>busca
                                >> >> >>nas
                                >> >> >> >> >>duas
                                >> >> >> >> >> >> >> >>classes
                                >> >> >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco
                                >>no
                                >> >> >> >>atributo
                                >> >> >> >> >> >>"nome"
                                >> >> >> >> >> >> >>e
                                >> >> >> >> >> >> >> >>em
                                >> >> >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                                >> >> >>"description",
                                >> >> >> >> >>segue
                                >> >> >> >> >> >>o
                                >> >> >> >> >> >> >> >>método
                                >> >> >> >> >> >> >> >> >> abaixou:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> ************** MÉTODO ********************
                                >> >> >> >> >> >> >> >> >> try{
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> final Session session =
                                >> >> >> >> >> >> >> >> >>
                                >> >>HibernateUtil.getSessionFactory().openSession();
                                >> >> >> >> >> >> >> >> >> final FullTextSession ftSession =
                                >> >> >> >> >> >> >> >> >> Search.getFullTextSession(session);
                                >> >> >> >> >> >> >> >> >> final List<Assinante> assinantes =
                                >> >> >> >> >> >> >> >> >>
                                >>session.createCriteria(Assinante.class).list();
                                >> >> >> >> >> >> >> >> >> final List<Video> videos =
                                >> >> >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                                >> >> >> >> >> >> >> >> >> ftSession.index(a);
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> for(Video v : videos) {
                                >> >> >> >> >> >> >> >> >> ftSession.index(v);
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> final String[] stopWords =
                                >> >> >> >> >> >> >> >> >>
                                >> >> >>{"de","do","da","dos","das","a","o","na","no","em"};
                                >> >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                >> >> >> >> >> >> >> >>MultiFieldQueryParser(new
                                >> >> >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                                >> >> >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                                >> >> >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                                >> >> >>Flamengo");
                                >> >> >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                                >> >> >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                                >> >> >> >>Assinante.class);
                                >> >> >> >> >> >> >> >> >> final List<Assinante> list =
                                >> >>fullTextQuery.list();
                                >> >> >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> }catch(Exception e){
                                >> >> >> >> >> >> >> >> >> e.printStackTrace();
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> ************** FIM MÉTODO
                                >>********************
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha
                                >>que
                                >> >>eu
                                >> >> >> >>vou
                                >> >> >> >> >> >> >>destacar
                                >> >> >> >> >> >> >> >> >>abaixo
                                >> >> >> >> >> >> >> >> >> que eu informo em que campos procurar:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                >> >> >> >> >> >> >> >>MultiFieldQueryParser(new
                                >> >> >> >> >> >> >> >> >>
                                >> >> >>String[]{"nome","Videos.title","Videos.description"}
                                >> >> >> >>,
                                >> >> >> >> >>new
                                >> >> >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> if (list==null || list.size()==0){
                                >> >> >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo
                                >>encontrado.");
                                >> >> >> >> >> >> >> >> >> }else{
                                >> >> >> >> >> >> >> >> >> for(Assinante a : list) {
                                >> >> >> >> >> >> >> >> >> System.out.println(a.getNome());
                                >> >> >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                                >> >> >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >> }
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus
                                >>Vídeos.
                                >> >> >> >> >> >> >> >> >> Ex.:
                                >> >> >> >> >> >> >> >> >> Anderson Moraes
                                >> >> >> >> >> >> >> >> >> Vídeo 1
                                >> >> >> >> >> >> >> >> >> Vídeo 4
                                >> >> >> >> >> >> >> >> >> Vídeo 9
                                >> >> >> >> >> >> >> >> >> Elba Ramalho
                                >> >> >> >> >> >> >> >> >> Vídeo 3
                                >> >> >> >> >> >> >> >> >> Vídeo 7
                                >> >> >> >> >> >> >> >> >> Raul Seixas
                                >> >> >> >> >> >> >> >> >> Zé Ramalho
                                >> >> >> >> >> >> >> >> >> Vídeo 2
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem
                                >>vídeo,
                                >> >>no
                                >> >> >> >>caso
                                >> >> >> >> >>do
                                >> >> >> >> >> >> >>exemplo
                                >> >> >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo
                                >> >>sem
                                >> >> >> >> >>Assinante.
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List
                                >>somente
                                >> >>dos
                                >> >> >> >> >>vídeos
                                >> >> >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                                >> >> >>Assinante
                                >> >> >> >>eu
                                >> >> >> >> >> >>uso
                                >> >> >> >> >> >> >>só
                                >> >> >> >> >> >> >> >>para
                                >> >> >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                                >> >> >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu
                                >>list<Video>
                                >> >>será
                                >> >> >> >> >> >>preenchido
                                >> >> >> >> >> >> >>com
                                >> >> >> >> >> >> >> >>os
                                >> >> >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão
                                >>para
                                >> >> >> >> >>recuperar
                                >> >> >> >> >> >>pelo
                                >> >> >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Na minha Action:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> request.setAttribute("Busca_Videos",
                                >> >>listVideos);
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> No meu JSP:
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                                >> >> >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                                >> >> >>name="Busca_Videos">
                                >> >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                                >>property="title"
                                >> >>/>
                                >> >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                                >> >> >>property="description"
                                >> >> >> >>/>
                                >> >> >> >> >> >> >> >> >> </logic:iterate>
                                >> >> >> >> >> >> >> >> >> </logic:notEmpty>
                                >> >> >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                                >> >> >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                                >> >> >> >> >> >> >> >> >> </logic:empty>
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                                >> >> >>recuperar
                                >> >> >> >>em
                                >> >> >> >> >>cima
                                >> >> >> >> >> >>da
                                >> >> >> >> >> >> >> >>busca
                                >> >> >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Grato desde já,
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >> Anderson Moraes
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >> > --
                                >> >> >> >> >> >> >> >> > Victor Guilherme Hogemann
                                >> >> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> >
                                >> >> >> >> >> >> >> > --
                                >> >> >> >> >> >> >> > Victor Guilherme Hogemann
                                >> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >>
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> >
                                >> >> >> >> >> >> > --
                                >> >> >> >> >> >> > Victor Guilherme Hogemann
                                >> >> >> >> >> >> > http://victor.hogemann.eti.br
                                >> >> >> >> >> >>
                                >> >> >> >> >> >>
                                >> >> >> >> >> >>
                                >> >> >> >> >> >
                                >> >> >> >> >> >
                                >> >> >> >> >> >
                                >> >> >> >> >> > --
                                >> >> >> >> >> > Victor Guilherme Hogemann
                                >> >> >> >> >> > http://victor.hogemann.eti.br
                                >> >> >> >> >>
                                >> >> >> >> >>
                                >> >> >> >> >>
                                >> >> >> >> >
                                >> >> >> >> >
                                >> >> >> >> >
                                >> >> >> >> > --
                                >> >> >> >> > Victor Guilherme Hogemann
                                >> >> >> >> > http://victor.hogemann.eti.br
                                >> >> >> >>
                                >> >> >> >>
                                >> >> >> >>
                                >> >> >> >
                                >> >> >> >
                                >> >> >> >
                                >> >> >> > --
                                >> >> >> > Victor Guilherme Hogemann
                                >> >> >> > http://victor.hogemann.eti.br
                                >> >> >>
                                >> >> >>
                                >> >> >>
                                >> >> >
                                >> >> >
                                >> >> >
                                >> >> > --
                                >> >> > Victor Guilherme Hogemann
                                >> >> > http://victor.hogemann.eti.br
                                >> >>
                                >> >>
                                >> >>
                                >> >
                                >> >
                                >> >
                                >> > --
                                >> > Victor Guilherme Hogemann
                                >> > http://victor.hogemann.eti.br
                                >>
                                >>
                                >>
                                >
                                >
                                >
                                > --
                                > Victor Guilherme Hogemann
                                > http://victor.hogemann.eti.br
                              • Anderson Moraes
                                Victor, dá mais essa força aí... Grato desde já... On Tue, 06 Oct 2009 13:03:22 -0300
                                Message 15 of 21 , Oct 7, 2009
                                • 0 Attachment
                                  Victor, dá mais essa força aí...

                                  Grato desde já...

                                  On Tue, 06 Oct 2009 13:03:22 -0300
                                  "Anderson Moraes" <amoraes@...> wrote:
                                  > Victor, eu executei a classe da seguinte forma:
                                  >
                                  > public class AtualizaIndice {
                                  >
                                  > public void refreshIndex(final Class entityClass) {
                                  >
                                  > Session session =
                                  >HibernateUtil.getSessionFactory().openSession();
                                  >
                                  > FullTextSession fullTextSession =
                                  > Search.getFullTextSession(session);
                                  >
                                  > Criteria crit = session.createCriteria(entityClass);
                                  >
                                  > for (Object obj : crit.list()) {
                                  > fullTextSession.index(obj);
                                  > }
                                  >
                                  > }
                                  >
                                  > public static void main(final String[] args) throws Exception {
                                  >
                                  > AtualizaIndice ai = new AtualizaIndice();
                                  >
                                  > ai.refreshIndex(Assinante.class);
                                  > ai.refreshIndex(Video.class);
                                  >
                                  > }
                                  >
                                  > }
                                  >
                                  >
                                  > Depois eu realizai o seguinte teste:
                                  >
                                  > public class AppBuscaTest {
                                  >
                                  >
                                  > @SuppressWarnings("unchecked")
                                  > public static void main(final String[] args) throws Exception {
                                  >
                                  > try{
                                  >
                                  > final Session session =
                                  > HibernateUtil.getSessionFactory().openSession();
                                  > final FullTextSession ftSession =
                                  > Search.getFullTextSession(session);
                                  > final List<Video> videos =
                                  > session.createCriteria(Video.class).list();
                                  >
                                  > for(Video v : videos) {
                                  > ftSession.index(v);
                                  > }
                                  >
                                  >
                                  > final String[] stopWords =
                                  > {"de","do","da","dos","das","a","o","na","no","em"};
                                  > final MultiFieldQueryParser parser = new
                                  > MultiFieldQueryParser(new
                                  > String[]{"Video.assinante.nome","Video.title"} , new
                                  > StopAnalyzer(stopWords));
                                  > final Query query = parser.parse("Moraes");
                                  > final FullTextQuery fullTextQuery =
                                  > ftSession.createFullTextQuery(query, Video.class);
                                  >
                                  > final List<Video> list = fullTextQuery.list();
                                  >
                                  >
                                  > HibernateUtil.getSessionFactory().close();
                                  >
                                  >
                                  > if (list==null || list.size()==0){
                                  > System.out.println("Nenhum Vídeo encontrado.");
                                  > }else{
                                  >
                                  > for (Video v : list) {
                                  > System.out.println(" " + v.getTitle());
                                  > }
                                  >
                                  > }
                                  >
                                  > }catch(Exception e){
                                  > e.printStackTrace();
                                  > }
                                  > }
                                  >
                                  >
                                  > }
                                  >
                                  > Mas não retorna nada, dá a mensagem: Nenhum Vídeo encontrado.
                                  >
                                  > Errei alguma coisa???
                                  >
                                  > Grato.
                                  >
                                  > On Tue, 6 Oct 2009 12:40:20 -0300
                                  > Victor Hogemann <victor.hogemann@...> wrote:
                                  >> Cara...
                                  >> Remove o casting de :
                                  >>
                                  >> *
                                  >> T entity = (T) obj;* //APAGUE ESSA LINHA
                                  >>
                                  >> E salva direto o objeto que você pega na iteração:
                                  >>
                                  >> fullTextSession.index(obj); //REINDEXA OBJ DIRETAMENTE, SEM O
                                  >>CASTING
                                  >>
                                  >>
                                  >> O *T* é um resquício do código original que eu te mandei, que usava
                                  >>generics
                                  >> pra deixar as coisas mais elegantes...
                                  >>
                                  >> [ ]s
                                  >>
                                  >> 2009/10/5 Anderson Moraes <amoraes@...>
                                  >>
                                  >>>
                                  >>>
                                  >>> Victor, minha classe ficou assim:
                                  >>>
                                  >>> package esseecraque.action;
                                  >>>
                                  >>> import org.hibernate.Criteria;
                                  >>> import org.hibernate.Session;
                                  >>> import org.hibernate.search.FullTextSession;
                                  >>> import org.hibernate.search.Search;
                                  >>>
                                  >>> import esseecraque.util.HibernateUtil;
                                  >>>
                                  >>> public class AtualizaIndice {
                                  >>>
                                  >>>
                                  >>> public void refreshIndex(final Class entityClass) {
                                  >>>
                                  >>> Session session = HibernateUtil.getSessionFactory().openSession();
                                  >>>
                                  >>> FullTextSession fullTextSession =
                                  >>> Search.getFullTextSession(session);
                                  >>>
                                  >>> Criteria crit = session.createCriteria(entityClass);
                                  >>>
                                  >>> for (Object obj : crit.list()) {
                                  >>> T entity = (T) obj;
                                  >>> fullTextSession.index(entity);
                                  >>> }
                                  >>>
                                  >>> }
                                  >>>
                                  >>> }
                                  >>>
                                  >>> Mas tá com erro na linha "T entity = (T) obj;"
                                  >>> Diz que "T" não pode ser definido para o tipo, o que eu preciso
                                  >>>fazer
                                  >>> para resolver esse problema?
                                  >>>
                                  >>> Após resolver esse problema basta eu instanciar um objeto
                                  >>> AtualizaIndice e chamar o método, como abaixo?
                                  >>>
                                  >>> AtualizaIndice ai = new AtualizaIndice();
                                  >>>
                                  >>> ai.refreshIndex(Assinante.class);
                                  >>> ai.refreshIndex(Video.class);
                                  >>>
                                  >>> é isso???
                                  >>>
                                  >>> Grato mais uma vez Victor...
                                  >>>
                                  >>> On Mon, 5 Oct 2009 18:21:50 -0300
                                  >>> Victor Hogemann <victor.hogemann@...
                                  >>><victor.hogemann%40gmail.com>>
                                  >>> wrote:
                                  >>> > Anderson,
                                  >>> > Nesse caso, você vai utilizar só esse miolo aqui:
                                  >>> >
                                  >>> >FullTextSession fullTextSession =
                                  >>>Search.getFullTextSession(session);
                                  >>> >
                                  >>> > Criteria crit = session.createCriteria(entityClass);
                                  >>> >
                                  >>> > for (Object obj : crit.list()) {
                                  >>> >
                                  >>> > T entity = (T) obj;
                                  >>> >
                                  >>> > fullTextSession.index(entity);
                                  >>> >
                                  >>> > }
                                  >>> >
                                  >>> >
                                  >>> > Sendo que session é um Session do Hibernate. Encare como se fosse
                                  >>>um
                                  >>> >outro
                                  >>> > método qualquer de um DAO seu.
                                  >>> >
                                  >>> > [ ]s
                                  >>> >
                                  >>> > 2009/10/5 Anderson Moraes
                                  >>><amoraes@...<amoraes%40tecmetal.com.br>
                                  >>> >
                                  >>> >
                                  >>> >>
                                  >>> >>
                                  >>> >> Estou utilizando STRUTS, como ficaria o mesmo nesse caso???
                                  >>> >>
                                  >>> >> On Mon, 5 Oct 2009 17:47:21 -0300
                                  >>> >>
                                  >>> >> Victor Hogemann
                                  >>><victor.hogemann@...<victor.hogemann%40gmail.com>
                                  >>> >><victor.hogemann%40gmail.com>>
                                  >>> >> wrote:
                                  >>> >> > Anderson,
                                  >>> >> > Desculpe... esse método está feito pra usar o suporte a
                                  >>>Hibernate
                                  >>> >>do
                                  >>> >> > SpringFramework. Você vai ter que alterar ele se estiver usando
                                  >>>o
                                  >>> >> >Hibernate
                                  >>> >> > "na unha".
                                  >>> >> >
                                  >>> >> > [ ]s
                                  >>> >> >
                                  >>> >> > 2009/10/5 Anderson Moraes
                                  >>> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                                  >>> 40tecmetal.com.br>
                                  >>> >> >
                                  >>> >> >
                                  >>> >> >>
                                  >>> >> >>
                                  >>> >> >> Está dando erro em "this.getHibernateTemplate().execute(new
                                  >>> >> >> HibernateCallback(){", diz que os métodos
                                  >>>getHibernateTemplate()
                                  >>> >>é
                                  >>> >> >> indefinido e que HibernateCallback() não pode ser definido
                                  >>>para o
                                  >>> >> >> tipo.
                                  >>> >> >>
                                  >>> >> >> On Mon, 5 Oct 2009 14:48:47 -0300
                                  >>> >> >>
                                  >>> >> >> Victor Hogemann
                                  >>> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                  >>> <victor.hogemann%40gmail.com>
                                  >>> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> wrote:
                                  >>> >> >> > Anderson,
                                  >>> >> >> > Pode fazer dentro de um main sim, e o método serve pra
                                  >>>qualquer
                                  >>> >> >> >entidade
                                  >>> >> >> > indexada com hibernate-search... Por exemplo, basta chamar
                                  >>> >> >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no
                                  >>> >>seu
                                  >>> >> >> >caso.
                                  >>> >> >> >
                                  >>> >> >> > [ ]s
                                  >>> >> >> >
                                  >>> >> >> > 2009/10/5 Anderson Moraes
                                  >>> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                                  >>> 40tecmetal.com.br><amoraes%
                                  >>>
                                  >>> >> 40tecmetal.com.br>
                                  >>> >>
                                  >>> >> >> >
                                  >>> >> >> >
                                  >>> >> >> >>
                                  >>> >> >> >>
                                  >>> >> >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar
                                  >>> >>dentro
                                  >>> >> >>de
                                  >>> >> >> >>um
                                  >>> >> >> >> main mesmo???
                                  >>> >> >> >>
                                  >>> >> >> >> Esse exemplo que você me mandou serve para o meu caso ou
                                  >>>tenho
                                  >>> >> >>que
                                  >>> >> >> >> fazer alguma modificação???
                                  >>> >> >> >>
                                  >>> >> >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela
                                  >>>força...
                                  >>> >> >> >>
                                  >>> >> >> >> Abraço,
                                  >>> >> >> >>
                                  >>> >> >> >> Anderson
                                  >>> >> >> >>
                                  >>> >> >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                                  >>> >> >> >>
                                  >>> >> >> >> Victor Hogemann
                                  >>> >> >><victor.hogemann@...
                                  >>><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> 40gmail.com>
                                  >>> >> <victor.hogemann%40gmail.com>
                                  >>> >> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> >> wrote:
                                  >>> >> >> >> > Anderson,
                                  >>> >> >> >> > Se você estiver fazendo uma aplicação Web pode colocar
                                  >>> >>dentro
                                  >>> >> >>de
                                  >>> >> >> >>um
                                  >>> >> >> >> >método
                                  >>> >> >> >> > de um controller qualquer, ou até mesmo dentro de um
                                  >>>servlet
                                  >>> >> >> >> >separado... O
                                  >>> >> >> >> > importante é chama-lo sem ninguém estar fazendo
                                  >>>alterações
                                  >>> >>na
                                  >>> >> >> >> >persistência.
                                  >>> >> >> >> >
                                  >>> >> >> >> > [ ]s
                                  >>> >> >> >> >
                                  >>> >> >> >> > 2009/10/2 Anderson Moraes
                                  >>> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                  >>><amoraes%
                                  >>> 40tecmetal.com.br> <amoraes%
                                  >>> >> 40tecmetal.com.br><amoraes%
                                  >>> >>
                                  >>> >> >> 40tecmetal.com.br>
                                  >>> >> >>
                                  >>> >> >> >> >
                                  >>> >> >> >> >
                                  >>> >> >> >> >>
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o
                                  >>> >>método
                                  >>> >> >> >>que
                                  >>> >> >> >> >>vc
                                  >>> >> >> >> >> me mando, como chamar...
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> Desde já muito obrigado pela força que está me dando.
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> Victor Hogemann
                                  >>> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                  >>> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> 40gmail.com>
                                  >>> >> >> <victor.hogemann%40gmail.com>
                                  >>> >> >> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> >> >> wrote:
                                  >>> >> >> >> >> > Anderson,
                                  >>> >> >> >> >> > Imagine a seguinte situação... Sua aplicação está
                                  >>> >> >>funcionando,
                                  >>> >> >> >>e
                                  >>> >> >> >> >>de
                                  >>> >> >> >> >> >repente
                                  >>> >> >> >> >> > alguma coisa sai errada e o seu servidor capota.
                                  >>>Beleza,
                                  >>> >> >>você
                                  >>> >> >> >>tem
                                  >>> >> >> >> >>o
                                  >>> >> >> >> >> >backup
                                  >>> >> >> >> >> > do seu banco de dados, mas e os índices do Hibernate
                                  >>> >>Search?
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> > Claro, você poderia fazer backup desses também... mas
                                  >>> >> >>imagine
                                  >>> >> >> >>que
                                  >>> >> >> >> >> >não tenha
                                  >>> >> >> >> >> > feito. Você vai precisar reconstruir seus índices a
                                  >>> >>partir
                                  >>> >> >>das
                                  >>> >> >> >> >> >entidades
                                  >>> >> >> >> >> > persistidas no banco, pra isso serve o método que eu
                                  >>>te
                                  >>> >> >>passei.
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> > Como você alterou o mapeamento das entidades no
                                  >>>Hibernate
                                  >>> >> >> >>Search,
                                  >>> >> >> >> >> >logo mudou
                                  >>> >> >> >> >> > a estrutura do índice, e aí é necessário re-indexar
                                  >>>tudo
                                  >>> >> >> >> >>novamente.
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> > Sacou?
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> > 2009/10/2 Anderson Moraes
                                  >>> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                  >>><amoraes%
                                  >>> 40tecmetal.com.br>
                                  >>> >><amoraes%
                                  >>> >> 40tecmetal.com.br> <amoraes%
                                  >>> >> >> 40tecmetal.com.br><amoraes%
                                  >>> >> >>
                                  >>> >> >> >> 40tecmetal.com.br>
                                  >>> >> >> >>
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> Não entendi como eu executo essa classe, em que
                                  >>> >>momento...
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> Victor Hogemann
                                  >>> >> >> >> >><victor.hogemann@...
                                  >>><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> 40gmail.com>
                                  >>> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> >> 40gmail.com>
                                  >>> >> >> >> <victor.hogemann%40gmail.com>
                                  >>> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> >> >> >> wrote:
                                  >>> >> >> >> >> >> > Anderson,
                                  >>> >> >> >> >> >> > Você re-indexou suas entidades? Toda vez que você
                                  >>>muda
                                  >>> >>o
                                  >>> >> >> >> >> >>mapeamento
                                  >>> >> >> >> >> >> >os
                                  >>> >> >> >> >> >> > índices são criados novamente, e você precisa
                                  >>> >>re-indexar
                                  >>> >> >>as
                                  >>> >> >> >> >> >> >entidades que já
                                  >>> >> >> >> >> >> > existiam... senão vai ficar com o índice vazio.
                                  >>>Segue
                                  >>> >>um
                                  >>> >> >> >> >>exemplo
                                  >>> >> >> >> >> >>de
                                  >>> >> >> >> >> >> >como
                                  >>> >> >> >> >> >> > fazer:
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > public void refreshIndex(final Class entityClass) {
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > this.getHibernateTemplate().execute(new
                                  >>> >> >>HibernateCallback()
                                  >>> >> >> >>{
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > public Object doInHibernate(Session session)
                                  >>> >> >> >> >> >> > throwsHibernateException, SQLException {
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > FullTextSession fullTextSession =
                                  >>> >> >> >> >> >> > Search.getFullTextSession(session);
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > Criteria crit =
                                  >>>session.createCriteria(entityClass);
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > for (Object obj : crit.list()) {
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > T entity = (T) obj;
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > fullTextSession.index(entity);
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > }
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > return null;
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > }
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > });
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > }
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > [ ]s
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                  >>> >> >> >> >> >><amoraes@...
                                  >>><amoraes%40tecmetal.com.br><amoraes%
                                  >>> 40tecmetal.com.br>
                                  >>> >><amoraes%
                                  >>> >> 40tecmetal.com.br>
                                  >>> >> >><amoraes%
                                  >>> >> >> 40tecmetal.com.br> <amoraes%
                                  >>> >> >> >> 40tecmetal.com.br><amoraes%
                                  >>> >> >> >>
                                  >>> >> >> >> >> 40tecmetal.com.br>
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que
                                  >>> >>fiz,
                                  >>> >> >> >>abaixo
                                  >>> >> >> >> >> >>vou
                                  >>> >> >> >> >> >> >> mostrar o SQL que sai no console:
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> try{
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> final Session session =
                                  >>> >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                                  >>> >> >> >> >> >> >> final FullTextSession ftSession =
                                  >>> >> >> >> >> >> >> Search.getFullTextSession(session);
                                  >>> >> >> >> >> >> >> final List<Video> videos =
                                  >>> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> for(Video v : videos) {
                                  >>> >> >> >> >> >> >> ftSession.index(v);
                                  >>> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> final String[] stopWords =
                                  >>> >> >> >> >> >> >>
                                  >>>{"de","do","da","dos","das","a","o","na","no","em"};
                                  >>> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                  >>> >> >> >> >> >> >> MultiFieldQueryParser(new
                                  >>> >> >> >> >> >> >>
                                  >>>String[]{"Video.assinante.nome","Video.description"}
                                  >>> >>,
                                  >>> >> >>new
                                  >>> >> >> >> >> >> >> StopAnalyzer(stopWords));
                                  >>> >> >> >> >> >> >> final Query query = parser.parse("Moraes");
                                  >>> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                                  >>> >> >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> if (list==null || list.size()==0){
                                  >>> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                                  >>> >> >> >> >> >> >> }else{
                                  >>> >> >> >> >> >> >> for (Video v : list) {
                                  >>> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                                  >>> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> }catch(Exception e){
                                  >>> >> >> >> >> >> >> e.printStackTrace();
                                  >>> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> CONSOLE:
                                  >>> >> >> >> >> >> >> Hibernate:
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> select
                                  >>> >> >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                                  >>> >> >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                                  >>> >> >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                                  >>> >> >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                                  >>> >> >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                                  >>> >> >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                                  >>> >> >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                                  >>> >> >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                                  >>> >> >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                                  >>> >> >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                                  >>> >> >> >> >> >> >> from
                                  >>> >> >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                                  >>> >> >>assinante2_
                                  >>> >> >> >>on
                                  >>> >> >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome
                                  >>>Moraes.
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> Victor Hogemann
                                  >>> >> >> >> >> >><victor.hogemann@...
                                  >>><victor.hogemann%40gmail.com>
                                  >>> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> 40gmail.com>
                                  >>> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> >> >> 40gmail.com>
                                  >>> >> >> >> >> <victor.hogemann%40gmail.com>
                                  >>> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> >> >> >> >> wrote:
                                  >>> >> >> >> >> >> >> > Anderson,
                                  >>> >> >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista
                                  >>>de
                                  >>> >> >> >>vídeos
                                  >>> >> >> >> >>do
                                  >>> >> >> >> >> >> >> >Assinante:
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> > @ContainedIn
                                  >>> >> >> >> >> >> >> > @OneToMany(mappedBy="assinante",
                                  >>> >>fetch=FetchType.LAZY)
                                  >>> >> >> >> >> >> >> > @Cascade(CascadeType.ALL)
                                  >>> >> >> >> >> >> >> > @IndexedEmbedded
                                  >>> >> >> >> >> >> >> > private List<Video> Videos;
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> > [ ]s
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                  >>> >> >> >> >> >> >><amoraes@...
                                  >>><amoraes%40tecmetal.com.br>
                                  >>> >><amoraes%40tecmetal.com.br><amoraes%
                                  >>> >> 40tecmetal.com.br>
                                  >>> >> >><amoraes%
                                  >>> >> >> 40tecmetal.com.br>
                                  >>> >> >> >><amoraes%
                                  >>> >> >> >> 40tecmetal.com.br> <amoraes%
                                  >>> >> >> >> >> 40tecmetal.com.br><amoraes%
                                  >>> >> >> >> >>
                                  >>> >> >> >> >> >> 40tecmetal.com.br>
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> Não consegui acertar meu método, segue as
                                  >>>minhas
                                  >>> >> >> >>Classes:
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> ASSINANTE:
                                  >>> >> >> >> >> >> >> >> @Entity
                                  >>> >> >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> @Indexed
                                  >>> >> >> >> >> >> >> >> public class Assinante extends PersistentObject
                                  >>> >> >> >>implements
                                  >>> >> >> >> >> >> >> >> Serializable{
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> @Id
                                  >>> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                  >>> >>GenerationType.IDENTITY)
                                  >>> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private Long id;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String email;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String password;
                                  >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String nome;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String cpf;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String endereco;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String cidade;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String estado;
                                  >>> >> >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private String dataCadastro;
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> @ContainedIn
                                  >>> >> >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                                  >>> >> >>fetch=FetchType.LAZY)
                                  >>> >> >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                                  >>> >> >> >> >> >> >> >> @IndexedEmbedded
                                  >>> >> >> >> >> >> >> >> private List<Video> Videos;
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> VÍDEO:
                                  >>> >> >> >> >> >> >> >> @Entity
                                  >>> >> >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                                  >>> >> >> >> >> >> >> >> @Indexed
                                  >>> >> >> >> >> >> >> >> public class Video implements Serializable{
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> @Id
                                  >>> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                  >>> >>GenerationType.IDENTITY)
                                  >>> >> >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                                  >>> >> >> >> >> >> >> >> private Long id;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_TITLE")
                                  >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                  >>> >> >> >> >> >> >> >> private String title;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                                  >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                  >>> >> >> >> >> >> >> >> private String description;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_URL")
                                  >>> >> >> >> >> >> >> >> private String url;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                                  >>> >> >> >> >> >> >> >> private String realPath;
                                  >>> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                  >>> >> >> >> >> >> >> >> private Long idAssinante;
                                  >>> >> >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                                  >>> >> >> >> >> >> >> >> private String dataUpload;
                                  >>> >> >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                                  >>> >> >> >> >> >> >> >> private String pathImage;
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> @IndexedEmbedded
                                  >>> >> >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                                  >>> >> >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE",
                                  >>> >>insertable=false,
                                  >>> >> >> >> >> >> >> >> updatable=false)
                                  >>> >> >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                                  >>> >> >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                                  >>> >> >> >> >> >> >> >> private Assinante assinante;
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> Deu erro:
                                  >>> >> >> >> >> >> >> >> Caused by:
                                  >>>org.hibernate.search.SearchException:
                                  >>> >> >> >>Circular
                                  >>> >> >> >> >> >> >>reference.
                                  >>> >> >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                                  >>> >> >>entity
                                  >>> >> >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                                  >>> >> >> >> >> >> >> >> Victor Hogemann
                                  >>> >> >> >> >> >> >><victor.hogemann@...
                                  >>><victor.hogemann%40gmail.com>
                                  >>> >><victor.hogemann%40gmail.com>
                                  >>> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> >> 40gmail.com>
                                  >>> >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                  >>> >> >> >> >> 40gmail.com>
                                  >>> >> >> >> >> >> <victor.hogemann%40gmail.com>
                                  >>> >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> wrote:
                                  >>> >> >> >> >> >> >> >> > Anderson,
                                  >>> >> >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                                  >>> >> >> >>associação
                                  >>> >> >> >> >> >> >> >> >bi-direcional entre
                                  >>> >> >> >> >> >> >> >> > Assinante e Video, assim você pode a partir
                                  >>>do
                                  >>> >> >>Video
                                  >>> >> >> >> >>filtrar
                                  >>> >> >> >> >> >> >>pelo
                                  >>> >> >> >> >> >> >> >> >nome do
                                  >>> >> >> >> >> >> >> >> > assinante usando somente uma query Lucene...
                                  >>>Por
                                  >>> >> >> >>exemplo:
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                                  >>> >> >> >> >> >> >>Term("Video.assinante.nome",
                                  >>> >> >> >> >> >> >> >> >"Fulano"));
                                  >>> >> >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                                  >>> >> >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                                  >>> >> >> >>Video.class);
                                  >>> >> >> >> >> >> >> >> > return fullTextQuery.list();
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > Pelo que você escreveu a associação entre
                                  >>> >>Assinante
                                  >>> >> >>e
                                  >>> >> >> >> >>Vídeo
                                  >>> >> >> >> >> >>é
                                  >>> >> >> >> >> >> >> >> >one-to-many,
                                  >>> >> >> >> >> >> >> >> > então não vai ser uma mudança tão traumática
                                  >>> >>assim
                                  >>> >> >>no
                                  >>> >> >> >> >> >>código. O
                                  >>> >> >> >> >> >> >> >> >pulo-do-gato
                                  >>> >> >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                                  >>> >> >>Assinante
                                  >>> >> >> >>no
                                  >>> >> >> >> >> >>indice
                                  >>> >> >> >> >> >> >>de
                                  >>> >> >> >> >> >> >> >> >Vídeo,
                                  >>> >> >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                                  >>> >> >> >> >>@ContainedIn.
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > Em Vídeo você vai ter:
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > @IndexedEmbeded
                                  >>> >> >> >> >> >> >> >> > @OneToOne
                                  >>> >> >> >> >> >> >> >> > Assinante assinante;
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > E em Assinante vai ficar:
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > @ContainedIn
                                  >>> >> >> >> >> >> >> >> > @OneToMany
                                  >>> >> >> >> >> >> >> >> > List<Video> videos;
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de
                                  >>> >>hibernate-search,
                                  >>> >> >> >>que
                                  >>> >> >> >> >> >> >> >>basicamente
                                  >>> >> >> >> >> >> >> >> >é um
                                  >>> >> >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                                  >>> >> >>hibernate
                                  >>> >> >> >> >> >>search.
                                  >>> >> >> >> >> >> >>No
                                  >>> >> >> >> >> >> >> >> >exemplo que
                                  >>> >> >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                                  >>> >> >> >>entidades
                                  >>> >> >> >> >> >> >> >>associadas:
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >>
                                  >>>>>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                  >>> >> >> >> >> >> >> >><amoraes@...
                                  >>><amoraes%40tecmetal.com.br>
                                  >>> >><amoraes%40tecmetal.com.br>
                                  >>> >> >><amoraes%40tecmetal.com.br><amoraes%
                                  >>> >> >> 40tecmetal.com.br>
                                  >>> >> >> >><amoraes%
                                  >>> >> >> >> 40tecmetal.com.br>
                                  >>> >> >> >> >><amoraes%
                                  >>> >> >> >> >> 40tecmetal.com.br> <amoraes%
                                  >>> >> >> >> >> >> 40tecmetal.com.br><amoraes%
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> 40tecmetal.com.br>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Pessoal, bom dia.
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                                  >>> >> >>primeiro
                                  >>> >> >> >>vou
                                  >>> >> >> >> >> >> >> >>descrever
                                  >>> >> >> >> >> >> >> >> >>os
                                  >>> >> >> >> >> >> >> >> >> atributos da minha bean:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> BEAN Assinante:
                                  >>> >> >> >> >> >> >> >> >> id
                                  >>> >> >> >> >> >> >> >> >> nome
                                  >>> >> >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                                  >>> >> >> >>Collection<Video>
                                  >>> >> >> >> >> >> >>Videos;)
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> BEAN Video:
                                  >>> >> >> >> >> >> >> >> >> id
                                  >>> >> >> >> >> >> >> >> >> title
                                  >>> >> >> >> >> >> >> >> >> description
                                  >>> >> >> >> >> >> >> >> >> idAssinante
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Blz, até aí tudo bem.
                                  >>> >> >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma
                                  >>> >>busca
                                  >>> >> >>nas
                                  >>> >> >> >> >>duas
                                  >>> >> >> >> >> >> >> >>classes
                                  >>> >> >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco
                                  >>>no
                                  >>> >> >> >>atributo
                                  >>> >> >> >> >> >>"nome"
                                  >>> >> >> >> >> >> >>e
                                  >>> >> >> >> >> >> >> >>em
                                  >>> >> >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                                  >>> >> >>"description",
                                  >>> >> >> >> >>segue
                                  >>> >> >> >> >> >>o
                                  >>> >> >> >> >> >> >> >>método
                                  >>> >> >> >> >> >> >> >> >> abaixou:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> ************** MÉTODO ********************
                                  >>> >> >> >> >> >> >> >> >> try{
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> final Session session =
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >>HibernateUtil.getSessionFactory().openSession();
                                  >>> >> >> >> >> >> >> >> >> final FullTextSession ftSession =
                                  >>> >> >> >> >> >> >> >> >> Search.getFullTextSession(session);
                                  >>> >> >> >> >> >> >> >> >> final List<Assinante> assinantes =
                                  >>> >> >> >> >> >> >> >> >>
                                  >>>session.createCriteria(Assinante.class).list();
                                  >>> >> >> >> >> >> >> >> >> final List<Video> videos =
                                  >>> >> >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                                  >>> >> >> >> >> >> >> >> >> ftSession.index(a);
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> for(Video v : videos) {
                                  >>> >> >> >> >> >> >> >> >> ftSession.index(v);
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> final String[] stopWords =
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >>{"de","do","da","dos","das","a","o","na","no","em"};
                                  >>> >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                  >>> >> >> >> >> >> >> >>MultiFieldQueryParser(new
                                  >>> >> >> >> >> >> >> >> >> String[]{"nome","Videos.description"} , new
                                  >>> >> >> >> >> >> >> >> >>StopAnalyzer(stopWords));
                                  >>> >> >> >> >> >> >> >> >> final Query query = parser.parse("Moraes
                                  >>> >> >>Flamengo");
                                  >>> >> >> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                                  >>> >> >> >> >> >> >> >> >> ftSession.createFullTextQuery(query,
                                  >>> >> >> >>Assinante.class);
                                  >>> >> >> >> >> >> >> >> >> final List<Assinante> list =
                                  >>> >>fullTextQuery.list();
                                  >>> >> >> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> }catch(Exception e){
                                  >>> >> >> >> >> >> >> >> >> e.printStackTrace();
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> ************** FIM MÉTODO
                                  >>>********************
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Ele funciona perfeitamente, repare na linha
                                  >>>que
                                  >>> >>eu
                                  >>> >> >> >>vou
                                  >>> >> >> >> >> >> >>destacar
                                  >>> >> >> >> >> >> >> >> >>abaixo
                                  >>> >> >> >> >> >> >> >> >> que eu informo em que campos procurar:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                  >>> >> >> >> >> >> >> >>MultiFieldQueryParser(new
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >>String[]{"nome","Videos.title","Videos.description"}
                                  >>> >> >> >>,
                                  >>> >> >> >> >>new
                                  >>> >> >> >> >> >> >> >> >> StopAnalyzer(stopWords));
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Então, se eu fizer conforme abaixo:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> if (list==null || list.size()==0){
                                  >>> >> >> >> >> >> >> >> >> System.out.println("Nenhum Vídeo
                                  >>>encontrado.");
                                  >>> >> >> >> >> >> >> >> >> }else{
                                  >>> >> >> >> >> >> >> >> >> for(Assinante a : list) {
                                  >>> >> >> >> >> >> >> >> >> System.out.println(a.getNome());
                                  >>> >> >> >> >> >> >> >> >> for (Video v : a.getVideos()) {
                                  >>> >> >> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >> }
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Ele me lista o Nome do Assinante e seus
                                  >>>Vídeos.
                                  >>> >> >> >> >> >> >> >> >> Ex.:
                                  >>> >> >> >> >> >> >> >> >> Anderson Moraes
                                  >>> >> >> >> >> >> >> >> >> Vídeo 1
                                  >>> >> >> >> >> >> >> >> >> Vídeo 4
                                  >>> >> >> >> >> >> >> >> >> Vídeo 9
                                  >>> >> >> >> >> >> >> >> >> Elba Ramalho
                                  >>> >> >> >> >> >> >> >> >> Vídeo 3
                                  >>> >> >> >> >> >> >> >> >> Vídeo 7
                                  >>> >> >> >> >> >> >> >> >> Raul Seixas
                                  >>> >> >> >> >> >> >> >> >> Zé Ramalho
                                  >>> >> >> >> >> >> >> >> >> Vídeo 2
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> OBS.: Repare que pode ter Assinante sem
                                  >>>vídeo,
                                  >>> >>no
                                  >>> >> >> >>caso
                                  >>> >> >> >> >>do
                                  >>> >> >> >> >> >> >>exemplo
                                  >>> >> >> >> >> >> >> >> >> acima "Raul Seixas", mas nunca terá um Vídeo
                                  >>> >>sem
                                  >>> >> >> >> >>Assinante.
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Blz, agora vamos ao que eu quero.
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Eu quero recuperar dessa busca um List
                                  >>>somente
                                  >>> >>dos
                                  >>> >> >> >> >>vídeos
                                  >>> >> >> >> >> >> >> >> >> (List<Video>), independente do Assinante, o
                                  >>> >> >>Assinante
                                  >>> >> >> >>eu
                                  >>> >> >> >> >> >>uso
                                  >>> >> >> >> >> >> >>só
                                  >>> >> >> >> >> >> >> >>para
                                  >>> >> >> >> >> >> >> >> >> buscar pelo nome, por exemplo:
                                  >>> >> >> >> >> >> >> >> >> Se eu buscar por "Ramalho", o meu
                                  >>>list<Video>
                                  >>> >>será
                                  >>> >> >> >> >> >>preenchido
                                  >>> >> >> >> >> >> >>com
                                  >>> >> >> >> >> >> >> >>os
                                  >>> >> >> >> >> >> >> >> >> vídeos de Elba Ramalho e Zé Ramalho.
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Esse List de Vídeos eu vou jogar na sessão
                                  >>>para
                                  >>> >> >> >> >>recuperar
                                  >>> >> >> >> >> >>pelo
                                  >>> >> >> >> >> >> >> >> >> Iterate, conforme exemplo abaixo:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Na minha Action:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> request.setAttribute("Busca_Videos",
                                  >>> >>listVideos);
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> No meu JSP:
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> <logic:notEmpty name="Busca_Videos">
                                  >>> >> >> >> >> >> >> >> >> <logic:iterate id="resulBusca"
                                  >>> >> >>name="Busca_Videos">
                                  >>> >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                                  >>>property="title"
                                  >>> >>/>
                                  >>> >> >> >> >> >> >> >> >> <bean:write name="resulBusca"
                                  >>> >> >>property="description"
                                  >>> >> >> >>/>
                                  >>> >> >> >> >> >> >> >> >> </logic:iterate>
                                  >>> >> >> >> >> >> >> >> >> </logic:notEmpty>
                                  >>> >> >> >> >> >> >> >> >> <logic:empty name="Busca_Video">
                                  >>> >> >> >> >> >> >> >> >> <b>Nenhum vídeo encontrado.</b>
                                  >>> >> >> >> >> >> >> >> >> </logic:empty>
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> O meu problema é que eu não estou sabendo
                                  >>> >> >>recuperar
                                  >>> >> >> >>em
                                  >>> >> >> >> >>cima
                                  >>> >> >> >> >> >>da
                                  >>> >> >> >> >> >> >> >>busca
                                  >>> >> >> >> >> >> >> >> >> que eu fiz um LIST só de Vídeos.
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Alguém pode me ajudar com isso???
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Grato desde já,
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >> Anderson Moraes
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >> > --
                                  >>> >> >> >> >> >> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >> > --
                                  >>> >> >> >> >> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> >> >> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >>
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> >
                                  >>> >> >> >> >> >> > --
                                  >>> >> >> >> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> >> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >>
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> >
                                  >>> >> >> >> >> > --
                                  >>> >> >> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >> >> >>
                                  >>> >> >> >> >>
                                  >>> >> >> >> >>
                                  >>> >> >> >> >
                                  >>> >> >> >> >
                                  >>> >> >> >> >
                                  >>> >> >> >> > --
                                  >>> >> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >> >>
                                  >>> >> >> >>
                                  >>> >> >> >>
                                  >>> >> >> >
                                  >>> >> >> >
                                  >>> >> >> >
                                  >>> >> >> > --
                                  >>> >> >> > Victor Guilherme Hogemann
                                  >>> >> >> > http://victor.hogemann.eti.br
                                  >>> >> >>
                                  >>> >> >>
                                  >>> >> >>
                                  >>> >> >
                                  >>> >> >
                                  >>> >> >
                                  >>> >> > --
                                  >>> >> > Victor Guilherme Hogemann
                                  >>> >> > http://victor.hogemann.eti.br
                                  >>> >>
                                  >>> >>
                                  >>> >>
                                  >>> >
                                  >>> >
                                  >>> >
                                  >>> > --
                                  >>> > Victor Guilherme Hogemann
                                  >>> > http://victor.hogemann.eti.br
                                  >>>
                                  >>>
                                  >>>
                                  >>
                                  >>
                                  >>
                                  >> --
                                  >> Victor Guilherme Hogemann
                                  >> http://victor.hogemann.eti.br
                                  >
                                • Victor Hogemann
                                  Anderson, Desculpa não poder te dar mais atenção cara, mas meu tempo pra responder esses emails de lista de discussão está escasso. Já te dei as dicas
                                  Message 16 of 21 , Oct 10, 2009
                                  • 0 Attachment
                                    Anderson,

                                    Desculpa não poder te dar mais atenção cara, mas meu tempo pra responder esses emails de lista de discussão está escasso. Já te dei as dicas que eu podia via email, mais que isso só se eu pegar o seu código e colocar pra rodar aqui e ficar debugando até funcionar... Agora é contigo.

                                    Mas aqui vai uma dica, se o esforço pra usar determinada tecnologia é maior que o ganho, as vezes é melhor seguir pelo caminho mais fácil. No teu caso, dependendo da quantidade de registros que você espera ter, acredito que uma otimização no banco de dados e a criação de índices nas colunas certas vai te dar ganhos tão bons quanto os do hibernate-search.

                                    [ ]s

                                    2009/10/7 Anderson Moraes <amoraes@...>
                                     

                                    Victor, dá mais essa força aí...

                                    Grato desde já...



                                    On Tue, 06 Oct 2009 13:03:22 -0300
                                    "Anderson Moraes" <amoraes@...> wrote:
                                    > Victor, eu executei a classe da seguinte forma:
                                    >
                                    > public class AtualizaIndice {
                                    >
                                    > public void refreshIndex(final Class entityClass) {
                                    >
                                    > Session session =
                                    >HibernateUtil.getSessionFactory().openSession();
                                    >
                                    > FullTextSession fullTextSession =
                                    > Search.getFullTextSession(session);
                                    >
                                    > Criteria crit = session.createCriteria(entityClass);
                                    >
                                    > for (Object obj : crit.list()) {
                                    > fullTextSession.index(obj);
                                    > }
                                    >
                                    > }
                                    >
                                    > public static void main(final String[] args) throws Exception {
                                    >
                                    > AtualizaIndice ai = new AtualizaIndice();
                                    >
                                    > ai.refreshIndex(Assinante.class);
                                    > ai.refreshIndex(Video.class);
                                    >
                                    > }
                                    >
                                    > }
                                    >
                                    >
                                    > Depois eu realizai o seguinte teste:
                                    >
                                    > public class AppBuscaTest {
                                    >
                                    >
                                    > @SuppressWarnings("unchecked")
                                    > public static void main(final String[] args) throws Exception {
                                    >
                                    > try{
                                    >
                                    > final Session session =
                                    > HibernateUtil.getSessionFactory().openSession();
                                    > final FullTextSession ftSession =
                                    > Search.getFullTextSession(session);
                                    > final List<Video> videos =
                                    > session.createCriteria(Video.class).list();
                                    >
                                    > for(Video v : videos) {
                                    > ftSession.index(v);
                                    > }
                                    >
                                    >
                                    > final String[] stopWords =
                                    > {"de","do","da","dos","das","a","o","na","no","em"};
                                    > final MultiFieldQueryParser parser = new
                                    > MultiFieldQueryParser(new
                                    > String[]{"Video.assinante.nome","Video.title"} , new
                                    > StopAnalyzer(stopWords));
                                    > final Query query = parser.parse("Moraes");
                                    > final FullTextQuery fullTextQuery =
                                    > ftSession.createFullTextQuery(query, Video.class);
                                    >
                                    > final List<Video> list = fullTextQuery.list();
                                    >
                                    >
                                    > HibernateUtil.getSessionFactory().close();
                                    >
                                    >
                                    > if (list==null || list.size()==0){
                                    > System.out.println("Nenhum Vídeo encontrado.");
                                    > }else{
                                    >
                                    > for (Video v : list) {
                                    > System.out.println(" " + v.getTitle());
                                    > }
                                    >
                                    > }
                                    >
                                    > }catch(Exception e){
                                    > e.printStackTrace();
                                    > }
                                    > }
                                    >
                                    >
                                    > }
                                    >
                                    > Mas não retorna nada, dá a mensagem: Nenhum Vídeo encontrado.
                                    >
                                    > Errei alguma coisa???
                                    >
                                    > Grato.
                                    >
                                    > On Tue, 6 Oct 2009 12:40:20 -0300
                                    > Victor Hogemann <victor.hogemann@...> wrote:
                                    >> Cara...
                                    >> Remove o casting de :
                                    >>
                                    >> *
                                    >> T entity = (T) obj;* //APAGUE ESSA LINHA
                                    >>
                                    >> E salva direto o objeto que você pega na iteração:
                                    >>
                                    >> fullTextSession.index(obj); //REINDEXA OBJ DIRETAMENTE, SEM O
                                    >>CASTING
                                    >>
                                    >>
                                    >> O *T* é um resquício do código original que eu te mandei, que usava
                                    >>generics
                                    >> pra deixar as coisas mais elegantes...
                                    >>
                                    >> [ ]s
                                    >>
                                    >> 2009/10/5 Anderson Moraes <amoraes@...>
                                    >>
                                    >>>
                                    >>>
                                    >>> Victor, minha classe ficou assim:
                                    >>>
                                    >>> package esseecraque.action;
                                    >>>
                                    >>> import org.hibernate.Criteria;
                                    >>> import org.hibernate.Session;
                                    >>> import org.hibernate.search.FullTextSession;
                                    >>> import org.hibernate.search.Search;
                                    >>>
                                    >>> import esseecraque.util.HibernateUtil;
                                    >>>
                                    >>> public class AtualizaIndice {
                                    >>>
                                    >>>
                                    >>> public void refreshIndex(final Class entityClass) {
                                    >>>
                                    >>> Session session = HibernateUtil.getSessionFactory().openSession();
                                    >>>
                                    >>> FullTextSession fullTextSession =
                                    >>> Search.getFullTextSession(session);
                                    >>>
                                    >>> Criteria crit = session.createCriteria(entityClass);
                                    >>>
                                    >>> for (Object obj : crit.list()) {
                                    >>> T entity = (T) obj;
                                    >>> fullTextSession.index(entity);
                                    >>> }
                                    >>>
                                    >>> }
                                    >>>
                                    >>> }
                                    >>>
                                    >>> Mas tá com erro na linha "T entity = (T) obj;"
                                    >>> Diz que "T" não pode ser definido para o tipo, o que eu preciso
                                    >>>fazer
                                    >>> para resolver esse problema?
                                    >>>
                                    >>> Após resolver esse problema basta eu instanciar um objeto
                                    >>> AtualizaIndice e chamar o método, como abaixo?
                                    >>>
                                    >>> AtualizaIndice ai = new AtualizaIndice();
                                    >>>
                                    >>> ai.refreshIndex(Assinante.class);
                                    >>> ai.refreshIndex(Video.class);
                                    >>>
                                    >>> é isso???
                                    >>>
                                    >>> Grato mais uma vez Victor...
                                    >>>
                                    >>> On Mon, 5 Oct 2009 18:21:50 -0300
                                    >>> Victor Hogemann <victor.hogemann@...
                                    >>><victor.hogemann%40gmail.com>>
                                    >>> wrote:
                                    >>> > Anderson,
                                    >>> > Nesse caso, você vai utilizar só esse miolo aqui:
                                    >>> >
                                    >>> >FullTextSession fullTextSession =
                                    >>>Search.getFullTextSession(session);
                                    >>> >
                                    >>> > Criteria crit = session.createCriteria(entityClass);
                                    >>> >
                                    >>> > for (Object obj : crit.list()) {
                                    >>> >
                                    >>> > T entity = (T) obj;
                                    >>> >
                                    >>> > fullTextSession.index(entity);
                                    >>> >
                                    >>> > }
                                    >>> >
                                    >>> >
                                    >>> > Sendo que session é um Session do Hibernate. Encare como se fosse
                                    >>>um
                                    >>> >outro
                                    >>> > método qualquer de um DAO seu.
                                    >>> >
                                    >>> > [ ]s
                                    >>> >
                                    >>> > 2009/10/5 Anderson Moraes
                                    >>><amoraes@...<amoraes%40tecmetal.com.br>
                                    >>> >
                                    >>> >
                                    >>> >>
                                    >>> >>
                                    >>> >> Estou utilizando STRUTS, como ficaria o mesmo nesse caso???
                                    >>> >>
                                    >>> >> On Mon, 5 Oct 2009 17:47:21 -0300
                                    >>> >>
                                    >>> >> Victor Hogemann
                                    >>><victor.hogemann@...<victor.hogemann%40gmail.com>
                                    >>> >><victor.hogemann%40gmail.com>>
                                    >>> >> wrote:
                                    >>> >> > Anderson,
                                    >>> >> > Desculpe... esse método está feito pra usar o suporte a
                                    >>>Hibernate
                                    >>> >>do
                                    >>> >> > SpringFramework. Você vai ter que alterar ele se estiver usando
                                    >>>o
                                    >>> >> >Hibernate
                                    >>> >> > "na unha".
                                    >>> >> >
                                    >>> >> > [ ]s
                                    >>> >> >
                                    >>> >> > 2009/10/5 Anderson Moraes
                                    >>> >><amoraes@... <amoraes%40tecmetal.com.br><amoraes%
                                    >>> 40tecmetal.com.br>
                                    >>> >> >
                                    >>> >> >
                                    >>> >> >>
                                    >>> >> >>
                                    >>> >> >> Está dando erro em "this.getHibernateTemplate().execute(new
                                    >>> >> >> HibernateCallback(){", diz que os métodos
                                    >>>getHibernateTemplate()
                                    >>> >>é
                                    >>> >> >> indefinido e que HibernateCallback() não pode ser definido
                                    >>>para o
                                    >>> >> >> tipo.
                                    >>> >> >>
                                    >>> >> >> On Mon, 5 Oct 2009 14:48:47 -0300
                                    >>> >> >>
                                    >>> >> >> Victor Hogemann
                                    >>> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                    >>> <victor.hogemann%40gmail.com>
                                    >>> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> wrote:
                                    >>> >> >> > Anderson,
                                    >>> >> >> > Pode fazer dentro de um main sim, e o método serve pra
                                    >>>qualquer
                                    >>> >> >> >entidade
                                    >>> >> >> > indexada com hibernate-search... Por exemplo, basta chamar
                                    >>> >> >> > refreshIndex(Assinante.class) e refreshIndex(Video.class) no
                                    >>> >>seu
                                    >>> >> >> >caso.
                                    >>> >> >> >
                                    >>> >> >> > [ ]s
                                    >>> >> >> >
                                    >>> >> >> > 2009/10/5 Anderson Moraes
                                    >>> >> >><amoraes@... <amoraes%40tecmetal.com.br> <amoraes%
                                    >>> 40tecmetal.com.br><amoraes%
                                    >>>
                                    >>> >> 40tecmetal.com.br>
                                    >>> >>
                                    >>> >> >> >
                                    >>> >> >> >
                                    >>> >> >> >>
                                    >>> >> >> >>
                                    >>> >> >> >> Vou tentar fazer aqui, eu poço criar essa classe e chamar
                                    >>> >>dentro
                                    >>> >> >>de
                                    >>> >> >> >>um
                                    >>> >> >> >> main mesmo???
                                    >>> >> >> >>
                                    >>> >> >> >> Esse exemplo que você me mandou serve para o meu caso ou
                                    >>>tenho
                                    >>> >> >>que
                                    >>> >> >> >> fazer alguma modificação???
                                    >>> >> >> >>
                                    >>> >> >> >> Mais uma vez volto a lhe agradecer Victor, vlw pela
                                    >>>força...
                                    >>> >> >> >>
                                    >>> >> >> >> Abraço,
                                    >>> >> >> >>
                                    >>> >> >> >> Anderson
                                    >>> >> >> >>
                                    >>> >> >> >> On Mon, 5 Oct 2009 11:08:55 -0300
                                    >>> >> >> >>
                                    >>> >> >> >> Victor Hogemann
                                    >>> >> >><victor.hogemann@...
                                    >>><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> 40gmail.com>
                                    >>> >> <victor.hogemann%40gmail.com>
                                    >>> >> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> >> wrote:
                                    >>> >> >> >> > Anderson,
                                    >>> >> >> >> > Se você estiver fazendo uma aplicação Web pode colocar
                                    >>> >>dentro
                                    >>> >> >>de
                                    >>> >> >> >>um
                                    >>> >> >> >> >método
                                    >>> >> >> >> > de um controller qualquer, ou até mesmo dentro de um
                                    >>>servlet
                                    >>> >> >> >> >separado... O
                                    >>> >> >> >> > importante é chama-lo sem ninguém estar fazendo
                                    >>>alterações
                                    >>> >>na
                                    >>> >> >> >> >persistência.
                                    >>> >> >> >> >
                                    >>> >> >> >> > [ ]s
                                    >>> >> >> >> >
                                    >>> >> >> >> > 2009/10/2 Anderson Moraes
                                    >>> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                    >>><amoraes%
                                    >>> 40tecmetal.com.br> <amoraes%
                                    >>> >> 40tecmetal.com.br><amoraes%
                                    >>> >>
                                    >>> >> >> 40tecmetal.com.br>
                                    >>> >> >>
                                    >>> >> >> >> >
                                    >>> >> >> >> >
                                    >>> >> >> >> >>
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> Entendi sim, eu só não sei como fazer isso, como usar o
                                    >>> >>método
                                    >>> >> >> >>que
                                    >>> >> >> >> >>vc
                                    >>> >> >> >> >> me mando, como chamar...
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> Desde já muito obrigado pela força que está me dando.
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> On Fri, 2 Oct 2009 19:18:58 -0300
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> Victor Hogemann
                                    >>> >> >> >><victor.hogemann@... <victor.hogemann%40gmail.com>
                                    >>> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> 40gmail.com>
                                    >>> >> >> <victor.hogemann%40gmail.com>
                                    >>> >> >> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> >> >> wrote:
                                    >>> >> >> >> >> > Anderson,
                                    >>> >> >> >> >> > Imagine a seguinte situação... Sua aplicação está
                                    >>> >> >>funcionando,
                                    >>> >> >> >>e
                                    >>> >> >> >> >>de
                                    >>> >> >> >> >> >repente
                                    >>> >> >> >> >> > alguma coisa sai errada e o seu servidor capota.
                                    >>>Beleza,
                                    >>> >> >>você
                                    >>> >> >> >>tem
                                    >>> >> >> >> >>o
                                    >>> >> >> >> >> >backup
                                    >>> >> >> >> >> > do seu banco de dados, mas e os índices do Hibernate
                                    >>> >>Search?
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> > Claro, você poderia fazer backup desses também... mas
                                    >>> >> >>imagine
                                    >>> >> >> >>que
                                    >>> >> >> >> >> >não tenha
                                    >>> >> >> >> >> > feito. Você vai precisar reconstruir seus índices a
                                    >>> >>partir
                                    >>> >> >>das
                                    >>> >> >> >> >> >entidades
                                    >>> >> >> >> >> > persistidas no banco, pra isso serve o método que eu
                                    >>>te
                                    >>> >> >>passei.
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> > Como você alterou o mapeamento das entidades no
                                    >>>Hibernate
                                    >>> >> >> >>Search,
                                    >>> >> >> >> >> >logo mudou
                                    >>> >> >> >> >> > a estrutura do índice, e aí é necessário re-indexar
                                    >>>tudo
                                    >>> >> >> >> >>novamente.
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> > Sacou?
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> > 2009/10/2 Anderson Moraes
                                    >>> >> >> >> >><amoraes@... <amoraes%40tecmetal.com.br>
                                    >>><amoraes%
                                    >>> 40tecmetal.com.br>
                                    >>> >><amoraes%
                                    >>> >> 40tecmetal.com.br> <amoraes%
                                    >>> >> >> 40tecmetal.com.br><amoraes%
                                    >>> >> >>
                                    >>> >> >> >> 40tecmetal.com.br>
                                    >>> >> >> >>
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> >
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> Não entendi como eu executo essa classe, em que
                                    >>> >>momento...
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> On Fri, 2 Oct 2009 16:50:33 -0300
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> Victor Hogemann
                                    >>> >> >> >> >><victor.hogemann@...
                                    >>><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> 40gmail.com>
                                    >>> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> >> 40gmail.com>
                                    >>> >> >> >> <victor.hogemann%40gmail.com>
                                    >>> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> >> >> >> wrote:
                                    >>> >> >> >> >> >> > Anderson,
                                    >>> >> >> >> >> >> > Você re-indexou suas entidades? Toda vez que você
                                    >>>muda
                                    >>> >>o
                                    >>> >> >> >> >> >>mapeamento
                                    >>> >> >> >> >> >> >os
                                    >>> >> >> >> >> >> > índices são criados novamente, e você precisa
                                    >>> >>re-indexar
                                    >>> >> >>as
                                    >>> >> >> >> >> >> >entidades que já
                                    >>> >> >> >> >> >> > existiam... senão vai ficar com o índice vazio.
                                    >>>Segue
                                    >>> >>um
                                    >>> >> >> >> >>exemplo
                                    >>> >> >> >> >> >>de
                                    >>> >> >> >> >> >> >como
                                    >>> >> >> >> >> >> > fazer:
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > public void refreshIndex(final Class entityClass) {
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > this.getHibernateTemplate().execute(new
                                    >>> >> >>HibernateCallback()
                                    >>> >> >> >>{
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > public Object doInHibernate(Session session)
                                    >>> >> >> >> >> >> > throwsHibernateException, SQLException {
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > FullTextSession fullTextSession =
                                    >>> >> >> >> >> >> > Search.getFullTextSession(session);
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > Criteria crit =
                                    >>>session.createCriteria(entityClass);
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > for (Object obj : crit.list()) {
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > T entity = (T) obj;
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > fullTextSession.index(entity);
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > }
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > return null;
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > }
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > });
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > }
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > [ ]s
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                    >>> >> >> >> >> >><amoraes@...
                                    >>><amoraes%40tecmetal.com.br><amoraes%
                                    >>> 40tecmetal.com.br>
                                    >>> >><amoraes%
                                    >>> >> 40tecmetal.com.br>
                                    >>> >> >><amoraes%
                                    >>> >> >> 40tecmetal.com.br> <amoraes%
                                    >>> >> >> >> 40tecmetal.com.br><amoraes%
                                    >>> >> >> >>
                                    >>> >> >> >> >> 40tecmetal.com.br>
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> Agora foi, mas não acho nada, de uma olhada no que
                                    >>> >>fiz,
                                    >>> >> >> >>abaixo
                                    >>> >> >> >> >> >>vou
                                    >>> >> >> >> >> >> >> mostrar o SQL que sai no console:
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> try{
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> final Session session =
                                    >>> >> >> >> >> >> >> HibernateUtil.getSessionFactory().openSession();
                                    >>> >> >> >> >> >> >> final FullTextSession ftSession =
                                    >>> >> >> >> >> >> >> Search.getFullTextSession(session);
                                    >>> >> >> >> >> >> >> final List<Video> videos =
                                    >>> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> for(Video v : videos) {
                                    >>> >> >> >> >> >> >> ftSession.index(v);
                                    >>> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> final String[] stopWords =
                                    >>> >> >> >> >> >> >>
                                    >>>{"de","do","da","dos","das","a","o","na","no","em"};
                                    >>> >> >> >> >> >> >> final MultiFieldQueryParser parser = new
                                    >>> >> >> >> >> >> >> MultiFieldQueryParser(new
                                    >>> >> >> >> >> >> >>
                                    >>>String[]{"Video.assinante.nome","Video.description"}
                                    >>> >>,
                                    >>> >> >>new
                                    >>> >> >> >> >> >> >> StopAnalyzer(stopWords));
                                    >>> >> >> >> >> >> >> final Query query = parser.parse("Moraes");
                                    >>> >> >> >> >> >> >> final FullTextQuery fullTextQuery =
                                    >>> >> >> >> >> >> >> ftSession.createFullTextQuery(query, Video.class);
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> final List<Video> list = fullTextQuery.list();
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> HibernateUtil.getSessionFactory().close();
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> if (list==null || list.size()==0){
                                    >>> >> >> >> >> >> >> System.out.println("Nenhum Vídeo encontrado.");
                                    >>> >> >> >> >> >> >> }else{
                                    >>> >> >> >> >> >> >> for (Video v : list) {
                                    >>> >> >> >> >> >> >> System.out.println(" " + v.getTitle());
                                    >>> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> }catch(Exception e){
                                    >>> >> >> >> >> >> >> e.printStackTrace();
                                    >>> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> CONSOLE:
                                    >>> >> >> >> >> >> >> Hibernate:
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> select
                                    >>> >> >> >> >> >> >> this_.NR_ID_VIDEO_PK as NR1_1_1_,
                                    >>> >> >> >> >> >> >> this_.NR_ID_ASSINANTE as NR4_1_1_,
                                    >>> >> >> >> >> >> >> this_.DT_DATE_UPLOAD as DT2_1_1_,
                                    >>> >> >> >> >> >> >> this_.VC_DESCRIPTION as VC3_1_1_,
                                    >>> >> >> >> >> >> >> this_.VC_PATH_IMAGE as VC5_1_1_,
                                    >>> >> >> >> >> >> >> this_.VC_REAL_PATH as VC6_1_1_,
                                    >>> >> >> >> >> >> >> this_.VC_TITLE as VC7_1_1_,
                                    >>> >> >> >> >> >> >> this_.VC_URL as VC8_1_1_,
                                    >>> >> >> >> >> >> >> assinante2_.NR_ID_ASSINANTE as NR1_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_CIDADE_ASSINANTE as VC2_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_CPF_ASSINANTE as VC3_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.DT_DATA_CAD_ASSINANTE as DT4_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_EMAIL_ASSINANTE as VC5_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_ENDERECO_ASSINANTE as VC6_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_ESTADO_ASSINANTE as VC7_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_NOME_ASSINANTE as VC8_0_0_,
                                    >>> >> >> >> >> >> >> assinante2_.VC_PASSWORD_ASSINANTE as VC9_0_0_
                                    >>> >> >> >> >> >> >> from
                                    >>> >> >> >> >> >> >> TBL_VIDEO this_ left outer join TBL_ASSINANTE
                                    >>> >> >>assinante2_
                                    >>> >> >> >>on
                                    >>> >> >> >> >> >> >> this_.NR_ID_ASSINANTE=assinante2_.NR_ID_ASSINANTE
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> OBS.: Existem 4 Assinantes com o sobre nome
                                    >>>Moraes.
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> On Fri, 2 Oct 2009 15:40:15 -0300
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> Victor Hogemann
                                    >>> >> >> >> >> >><victor.hogemann@...
                                    >>><victor.hogemann%40gmail.com>
                                    >>> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> 40gmail.com>
                                    >>> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> >> >> 40gmail.com>
                                    >>> >> >> >> >> <victor.hogemann%40gmail.com>
                                    >>> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> >> >> >> >> wrote:
                                    >>> >> >> >> >> >> >> > Anderson,
                                    >>> >> >> >> >> >> >> > Você precisa remover o @IndexedEmbedded da lista
                                    >>>de
                                    >>> >> >> >>vídeos
                                    >>> >> >> >> >>do
                                    >>> >> >> >> >> >> >> >Assinante:
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> > @ContainedIn
                                    >>> >> >> >> >> >> >> > @OneToMany(mappedBy="assinante",
                                    >>> >>fetch=FetchType.LAZY)
                                    >>> >> >> >> >> >> >> > @Cascade(CascadeType.ALL)
                                    >>> >> >> >> >> >> >> > @IndexedEmbedded
                                    >>> >> >> >> >> >> >> > private List<Video> Videos;
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> > [ ]s
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                    >>> >> >> >> >> >> >><amoraes@...
                                    >>><amoraes%40tecmetal.com.br>
                                    >>> >><amoraes%40tecmetal.com.br><amoraes%
                                    >>> >> 40tecmetal.com.br>
                                    >>> >> >><amoraes%
                                    >>> >> >> 40tecmetal.com.br>
                                    >>> >> >> >><amoraes%
                                    >>> >> >> >> 40tecmetal.com.br> <amoraes%
                                    >>> >> >> >> >> 40tecmetal.com.br><amoraes%
                                    >>> >> >> >> >>
                                    >>> >> >> >> >> >> 40tecmetal.com.br>
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> Não consegui acertar meu método, segue as
                                    >>>minhas
                                    >>> >> >> >>Classes:
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> ASSINANTE:
                                    >>> >> >> >> >> >> >> >> @Entity
                                    >>> >> >> >> >> >> >> >> @Table(name = "TBL_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> @Indexed
                                    >>> >> >> >> >> >> >> >> public class Assinante extends PersistentObject
                                    >>> >> >> >>implements
                                    >>> >> >> >> >> >> >> >> Serializable{
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> @Id
                                    >>> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                    >>> >>GenerationType.IDENTITY)
                                    >>> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private Long id;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_EMAIL_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String email;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_PASSWORD_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String password;
                                    >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_NOME_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String nome;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_CPF_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String cpf;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_ENDERECO_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String endereco;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_CIDADE_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String cidade;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_ESTADO_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String estado;
                                    >>> >> >> >> >> >> >> >> @Column(name="DT_DATA_CAD_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private String dataCadastro;
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> @ContainedIn
                                    >>> >> >> >> >> >> >> >> @OneToMany(mappedBy="assinante",
                                    >>> >> >>fetch=FetchType.LAZY)
                                    >>> >> >> >> >> >> >> >> @Cascade(CascadeType.ALL)
                                    >>> >> >> >> >> >> >> >> @IndexedEmbedded
                                    >>> >> >> >> >> >> >> >> private List<Video> Videos;
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> VÍDEO:
                                    >>> >> >> >> >> >> >> >> @Entity
                                    >>> >> >> >> >> >> >> >> @Table(name = "TBL_VIDEO")
                                    >>> >> >> >> >> >> >> >> @Indexed
                                    >>> >> >> >> >> >> >> >> public class Video implements Serializable{
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> @Id
                                    >>> >> >> >> >> >> >> >> @GeneratedValue(strategy =
                                    >>> >>GenerationType.IDENTITY)
                                    >>> >> >> >> >> >> >> >> @Column(name="NR_ID_VIDEO_PK")
                                    >>> >> >> >> >> >> >> >> private Long id;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_TITLE")
                                    >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                    >>> >> >> >> >> >> >> >> private String title;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_DESCRIPTION")
                                    >>> >> >> >> >> >> >> >> @Field(index=Index.TOKENIZED, store=Store.YES)
                                    >>> >> >> >> >> >> >> >> private String description;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_URL")
                                    >>> >> >> >> >> >> >> >> private String url;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_REAL_PATH")
                                    >>> >> >> >> >> >> >> >> private String realPath;
                                    >>> >> >> >> >> >> >> >> @Column(name="NR_ID_ASSINANTE")
                                    >>> >> >> >> >> >> >> >> private Long idAssinante;
                                    >>> >> >> >> >> >> >> >> @Column(name="DT_DATE_UPLOAD")
                                    >>> >> >> >> >> >> >> >> private String dataUpload;
                                    >>> >> >> >> >> >> >> >> @Column(name="VC_PATH_IMAGE")
                                    >>> >> >> >> >> >> >> >> private String pathImage;
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> @IndexedEmbedded
                                    >>> >> >> >> >> >> >> >> @OneToOne(fetch=FetchType.EAGER)
                                    >>> >> >> >> >> >> >> >> @JoinColumn(name="NR_ID_ASSINANTE",
                                    >>> >>insertable=false,
                                    >>> >> >> >> >> >> >> >> updatable=false)
                                    >>> >> >> >> >> >> >> >> @Fetch(FetchMode.JOIN)
                                    >>> >> >> >> >> >> >> >> @Cascade(CascadeType.SAVE_UPDATE)
                                    >>> >> >> >> >> >> >> >> private Assinante assinante;
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> Deu erro:
                                    >>> >> >> >> >> >> >> >> Caused by:
                                    >>>org.hibernate.search.SearchException:
                                    >>> >> >> >>Circular
                                    >>> >> >> >> >> >> >>reference.
                                    >>> >> >> >> >> >> >> >> Duplicate use of esseecraque.bean.Video in root
                                    >>> >> >>entity
                                    >>> >> >> >> >> >> >> >> esseecraque.bean.Video#assinante.Videos.
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> On Fri, 2 Oct 2009 14:01:29 -0300
                                    >>> >> >> >> >> >> >> >> Victor Hogemann
                                    >>> >> >> >> >> >> >><victor.hogemann@...
                                    >>><victor.hogemann%40gmail.com>
                                    >>> >><victor.hogemann%40gmail.com>
                                    >>> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> >> 40gmail.com>
                                    >>> >> >> >> >><victor.hogemann%40gmail.com><victor.hogemann%
                                    >>> >> >> >> >> 40gmail.com>
                                    >>> >> >> >> >> >> <victor.hogemann%40gmail.com>
                                    >>> >> >> >> >> >> >> >><victor.hogemann%40gmail.com>>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> wrote:
                                    >>> >> >> >> >> >> >> >> > Anderson,
                                    >>> >> >> >> >> >> >> >> > A forma mais fácil de fazer isso é criar uma
                                    >>> >> >> >>associação
                                    >>> >> >> >> >> >> >> >> >bi-direcional entre
                                    >>> >> >> >> >> >> >> >> > Assinante e Video, assim você pode a partir
                                    >>>do
                                    >>> >> >>Video
                                    >>> >> >> >> >>filtrar
                                    >>> >> >> >> >> >> >>pelo
                                    >>> >> >> >> >> >> >> >> >nome do
                                    >>> >> >> >> >> >> >> >> > assinante usando somente uma query Lucene...
                                    >>>Por
                                    >>> >> >> >>exemplo:
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > TermQuery query = new TermQuery(new
                                    >>> >> >> >> >> >> >>Term("Video.assinante.nome",
                                    >>> >> >> >> >> >> >> >> >"Fulano"));
                                    >>> >> >> >> >> >> >> >> >FullTextQuery fullTextQuery =
                                    >>> >> >> >> >> >> >> >> > fullTextSession.createFullTextQuery(query,
                                    >>> >> >> >>Video.class);
                                    >>> >> >> >> >> >> >> >> > return fullTextQuery.list();
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > Pelo que você escreveu a associação entre
                                    >>> >>Assinante
                                    >>> >> >>e
                                    >>> >> >> >> >>Vídeo
                                    >>> >> >> >> >> >>é
                                    >>> >> >> >> >> >> >> >> >one-to-many,
                                    >>> >> >> >> >> >> >> >> > então não vai ser uma mudança tão traumática
                                    >>> >>assim
                                    >>> >> >>no
                                    >>> >> >> >> >> >>código. O
                                    >>> >> >> >> >> >> >> >> >pulo-do-gato
                                    >>> >> >> >> >> >> >> >> > é que você vai ter que repetir os dados de
                                    >>> >> >>Assinante
                                    >>> >> >> >>no
                                    >>> >> >> >> >> >>indice
                                    >>> >> >> >> >> >> >>de
                                    >>> >> >> >> >> >> >> >> >Vídeo,
                                    >>> >> >> >> >> >> >> >> > utilizando as annotations @IndexedEmbended e
                                    >>> >> >> >> >>@ContainedIn.
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > Em Vídeo você vai ter:
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > @IndexedEmbeded
                                    >>> >> >> >> >> >> >> >> > @OneToOne
                                    >>> >> >> >> >> >> >> >> > Assinante assinante;
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > E em Assinante vai ficar:
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > @ContainedIn
                                    >>> >> >> >> >> >> >> >> > @OneToMany
                                    >>> >> >> >> >> >> >> >> > List<Video> videos;
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > Eu escrevi um pequeno tutorial de
                                    >>> >>hibernate-search,
                                    >>> >> >> >>que
                                    >>> >> >> >> >> >> >> >>basicamente
                                    >>> >> >> >> >> >> >> >> >é um
                                    >>> >> >> >> >> >> >> >> > resumo traduzido da referência em inglês do
                                    >>> >> >>hibernate
                                    >>> >> >> >> >> >>search.
                                    >>> >> >> >> >> >> >>No
                                    >>> >> >> >> >> >> >> >> >exemplo que
                                    >>> >> >> >> >> >> >> >> > está lá tem um exemplo de como fazer busca em
                                    >>> >> >> >>entidades
                                    >>> >> >> >> >> >> >> >>associadas:
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >>
                                    >>>>>http://victor.hogemann.eti.br/2009/06/hibernate-search.html
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > Espero ter ajudado, boa sorte!
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> > 2009/10/2 Anderson Moraes
                                    >>> >> >> >> >> >> >> >><amoraes@...
                                    >>><amoraes%40tecmetal.com.br>
                                    >>> >><amoraes%40tecmetal.com.br>
                                    >>> >> >><amoraes%40tecmetal.com.br><amoraes%
                                    >>> >> >> 40tecmetal.com.br>
                                    >>> >> >> >><amoraes%
                                    >>> >> >> >> 40tecmetal.com.br>
                                    >>> >> >> >> >><amoraes%
                                    >>> >> >> >> >> 40tecmetal.com.br> <amoraes%
                                    >>> >> >> >> >> >> 40tecmetal.com.br><amoraes%
                                    >>> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> 40tecmetal.com.br>
                                    >>> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> Pessoal, bom dia.
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> Vou explicar o que estou fazendo por parte,
                                    >>> >> >>primeiro
                                    >>> >> >> >>vou
                                    >>> >> >> >> >> >> >> >>descrever
                                    >>> >> >> >> >> >> >> >> >>os
                                    >>> >> >> >> >> >> >> >> >> atributos da minha bean:
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> BEAN Assinante:
                                    >>> >> >> >> >> >> >> >> >> id
                                    >>> >> >> >> >> >> >> >> >> nome
                                    >>> >> >> >> >> >> >> >> >> Videos (Uma Coleção de Vídeo - private
                                    >>> >> >> >>Collection<Video>
                                    >>> >> >> >> >> >> >>Videos;)
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> BEAN Video:
                                    >>> >> >> >> >> >> >> >> >> id
                                    >>> >> >> >> >> >> >> >> >> title
                                    >>> >> >> >> >> >> >> >> >> description
                                    >>> >> >> >> >> >> >> >> >> idAssinante
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> Blz, até aí tudo bem.
                                    >>> >> >> >> >> >> >> >> >> Aí eu uso o método abaixo para realizar uma
                                    >>> >>busca
                                    >>> >> >>nas
                                    >>> >> >> >> >>duas
                                    >>> >> >> >> >> >> >> >>classes
                                    >>> >> >> >> >> >> >> >> >> (tabelas), sendo que em Assinante eu busco
                                    >>>no
                                    >>> >> >> >>atributo
                                    >>> >> >> >> >> >>"nome"
                                    >>> >> >> >> >> >> >>e
                                    >>> >> >> >> >> >> >> >>em
                                    >>> >> >> >> >> >> >> >> >> Video eu busco nos atributos "title" e
                                    >>> >> >>"description",
                                    >>> >> >> >> >>segue
                                    >>> >> >> >> >> >>o
                                    >>> >> >> >> >> >> >> >>método
                                    >>> >> >> >> >> >> >> >> >> abaixou:
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> ************** MÉTODO ********************
                                    >>> >> >> >> >> >> >> >> >> try{
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> final Session session =
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >>HibernateUtil.getSessionFactory().openSession();
                                    >>> >> >> >> >> >> >> >> >> final FullTextSession ftSession =
                                    >>> >> >> >> >> >> >> >> >> Search.getFullTextSession(session);
                                    >>> >> >> >> >> >> >> >> >> final List<Assinante> assinantes =
                                    >>> >> >> >> >> >> >> >> >>
                                    >>>session.createCriteria(Assinante.class).list();
                                    >>> >> >> >> >> >> >> >> >> final List<Video> videos =
                                    >>> >> >> >> >> >> >> >> >> session.createCriteria(Video.class).list();
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> for(Assinante a : assinantes) {
                                    >>> >> >> >> >> >> >> >> >> ftSession.index(a);
                                    >>> >> >> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> for(Video v : videos) {
                                    >>> >> >> >> >> >> >> >> >> ftSession.index(v);
                                    >>> >> >> >> >> >> >> >> >> }
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >> >> >> >> >> >> >> final String[] stopWords =
                                    >>> >> >> >> >> >> >> >> >>
                                    >>> >> >>{"de","do","da","dos","das","a","o","na","no","em"};
                                    >>> >

                                    (Message over 64 KB, truncated)
                                  Your message has been successfully submitted and would be delivered to recipients shortly.