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

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: StringBridge ClassCastException
PostPosted: Mon Sep 14, 2015 8:23 am 
Beginner
Beginner

Joined: Sat Feb 16, 2008 3:09 pm
Posts: 24
Hello
when I try to use a StringBridge in my project I see that the objectToString(Object obj) method is being called at least twice. One time with the Object which will be mapped to a String, and a second time with the resulting String, which leads to a ClassCastException.

Code:
public class SchluessellisteBridge implements StringBridge {

   @Override
   public String objectToString(Object obj) {
      if (obj == null) {
         return "";
      }
      Schluesselliste schluesselliste = (Schluesselliste) obj;
      return schluesselliste.getLangname();
   }

}


Code:
   @ManyToOne(fetch = FetchType.EAGER)
   @JoinColumn(name = "rv_entscheidungArt_id")
   @Field
   @FieldBridge(impl = SchluessellisteBridge.class)
   protected Rechtsvorgang entscheidungArt;


Even when I use the @DateBridge I get this behavior
Code:
   @Field(analyze = Analyze.NO)
   @DateBridge(resolution = Resolution.DAY)
   @Temporal(TemporalType.DATE)


Did I misunderstand the purpose of StringBridge????

I am using Hibernate Search 5.3 with Hibernate 4.3

Code:
            <property name="hibernate.search.default.directory_provider"
                value="filesystem" />
            <property name="hibernate.search.default.indexBase" value="/var/lucene/indexes" />


My entities are JPA Entities. For searching I use the Hibernate API like
Code:
List<Gesamtentscheidung> gesamtentscheidungen = null;
EntityManager em = PersistenceService.getInstance().getEntityManagerFactory().createEntityManager();
Session session = em.unwrap(Session.class);

FullTextSession fullTextSession = Search.getFullTextSession(session);


fullTextSession.beginTransaction();


QueryBuilder queryBuilder = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Gesamtentscheidung.class).get();


org.apache.lucene.search.Query luceneQuery = queryBuilder
      .keyword()
      .onFields("betreff", "tatbestaende.aktenzeichen", "entscheidungArt")
      .matching(searchString)
      .createQuery();
org.hibernate.Query hibernateQuery = fullTextSession.createFullTextQuery(luceneQuery, Gesamtentscheidung.class);


gesamtentscheidungen = hibernateQuery.list();

fullTextSession.getTransaction().commit();

em.close();
return gesamtentscheidungen;


Top
 Profile  
 
 Post subject: Re: StringBridge ClassCastException
PostPosted: Tue Sep 15, 2015 11:31 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 388
Hi,

Can you share the full stacktrace, please?

Thanks,

--Gunnar

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


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

All times are UTC - 5 hours [ DST ]


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

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