-->
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.  [ 4 posts ] 
Author Message
 Post subject: Send parameters through embedded bridge
PostPosted: Wed Jan 25, 2012 5:13 pm 
Newbie

Joined: Thu Dec 08, 2011 5:43 pm
Posts: 7
I have a custom dateBridge because I wanted to add a prefix to my date field name. It works exactly how I expected for MyClassA and MyClassB creating fields:

classA.date
classB.date

However, if I @IndexedEmbedded a MyClassB object with prefix "classA" I get:

classA.embeddedClassB.id //intended
classB.classA.embeddedClassB.date //unintended

My desired field is:
classA.embeddedClassB.classB.date

This is happening because of the last line:
Code:
public class MyCalendarBridge implements FieldBridge, ParameterizedBridge {

   String paramKey = "prefix";
   String prefix = ""; //default
   
   @SuppressWarnings("rawtypes")
   @Override
   public void setParameterValues(Map parameters) {
      Object prefix = parameters.get(paramKey);
      if(prefix != null) {
         this.prefix = prefix.toString() + ".";
      }
   }

   @Override
   public void set(String name, Object object, Document doc, LuceneOptions lucene) {
      name = prefix + name;
      // ...
      doc.add(new Field(name + ".date", "thedate", store, index, tv));
}}


How do I restructure things to make it work as intended?

EDIT: I ended up changing the name as follows. It's kind of a hack though, and I'd rather have my fieldBridge behave the same way an @IndexedEmbedded(prefix="whatever") works.
Code:
   public void set(String name, Object object, Document doc, LuceneOptions lucene) {
      String a, b;
      a = name.substring(0, name.lastIndexOf('.')+1);
      b = name.substring(a.length());
      name = a + prefix + b;
      // ...


Top
 Profile  
 
 Post subject: Re: Send parameters through embedded bridge
PostPosted: Thu Jan 26, 2012 12:20 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
Quote:
classA.embeddedClassB.id //intended
classB.classA.embeddedClassB.date //unintended

My desired field is:
classA.embeddedClassB.classB.date

Sorry I didn't understand this part. what are "classB", "classA", etc? we normally have no class names in the fields.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: Send parameters through embedded bridge
PostPosted: Fri Jan 27, 2012 1:56 pm 
Newbie

Joined: Thu Dec 08, 2011 5:43 pm
Posts: 7
s.grinovero wrote:
Quote:
classA.embeddedClassB.id //intended
classB.classA.embeddedClassB.date //unintended

My desired field is:
classA.embeddedClassB.classB.date

Sorry I didn't understand this part. what are "classB", "classA", etc? we normally have no class names in the fields.

Normally, yes. I'm putting class names in the fields on purpose because I happen to need them. More to the point, my client wants them. It's also the whole reason I was having an issue in the first place. To perhaps make more clear:

so in my (annoying) required use case, Seats get fields:
seat.id
seat.model


Bikes get:
bike.id
bike.name
bike.mySeat.*


but the last element was expanding in a way that surprised me, because I'm using a custom field bridge. What I thought would happen:
bike.mySeat.seat.id
bike.mySeat.seat.model


what actually happened:
seat.bike.mySeat.id
seat.bike.mySeat.model


As I mentioned in my original post edit, I did solve this. I just don't think I solved it the "right" way.


Top
 Profile  
 
 Post subject: Re: Send parameters through embedded bridge
PostPosted: Fri Jan 27, 2012 4:04 pm 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
ah, thanks now I get it!
yes that's very surprising. Could you please create an issue on JIRA? I think this should be changed to do what you where expecting.

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.