-->
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.  [ 9 posts ] 
Author Message
 Post subject: Index of child subclasses missing subclass fields
PostPosted: Tue Jun 10, 2008 4:50 am 
Newbie

Joined: Tue Apr 29, 2008 6:31 am
Posts: 7
Hi, I have the following problem: I have a form object with a map of child field objects. The Map is of types <String, Field> where field is an abstract class and particular types of field subclass is and implement getValue(). The problem I have is that i need to be able to access the field values from the form index. The field name is stored in the index (fields.name) but not the values.

I would appreciate someone looking over these mappings.

Code:

@Entity
@Table(name="form")
@Indexed
public class Form implements Serializable, Cloneable , IFormsDataObject
{
            ......

       private Map<String, Field> fields;

   @OneToMany(fetch = FetchType.EAGER, mappedBy = "form")
   @MapKey(name = "name")
   @Cascade({org.hibernate.annotations.CascadeType.ALL, org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
   @IndexedEmbedded
   public Map<String, Field> getFields() {
      if(fields == null) fields = new HashMap<String, Field>();
      return fields;
   }

}

@Entity
@Table(name="field")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public abstract class Field implements Serializable, Cloneable {

   private int id;
   private String name;
   //private String label;
   private Form form;

   @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
   @ContainedIn
   public Form getForm() {
      return form;
   }

   public void setForm(Form form) {
      this.form = form;
   }

   @Id
   @DocumentId
   @GeneratedValue(strategy = GenerationType.AUTO)
   public int getId() {
      return id;
   }

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

   @org.hibernate.search.annotations.Field(index= Index.TOKENIZED, store= Store.NO)
   public String getName() {
      return name;
   }

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

   @Transient
   public abstract Class getValueClass();
   public abstract void setValue(Object obj);

   @Transient
   public abstract Object getValue();

   public Field clone() throws CloneNotSupportedException {
      try {
         Field f = this.getClass().newInstance();
         f.setName(name);
         f.setValue(this.getValue());
         return f;
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }
}

@Entity
@Table(name="stringfield")
@Indexed
public class StringField extends Field implements Serializable {

   private String value;

   @org.hibernate.search.annotations.Field(index=Index.TOKENIZED, store= Store.NO)
   public String getValue() {

      return value;
   }

   @Transient
   public Class getValueClass() {
      return String.class;
   }

   public void setValue(Object obj) {
      value = ((String) obj).trim();
   }

   public void setValue(String obj)
   {
      value = obj;
   }
}



Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

Have you tried removing the @Transient from getValue(). I am not sure if this important or not, it is just a guess. If it does not help there might be another problem, but either way you could implement a custom field or class bridge (http://www.hibernate.org/hib_docs/search/reference/en/html_single/#d0e1617).

--Hardy


Top
 Profile  
 
 Post subject: Seeing similar problem
PostPosted: Tue Jan 27, 2009 1:58 am 
Newbie

Joined: Tue Jan 27, 2009 1:03 am
Posts: 4
Save for a few differences, I'm seeing the same problem, where the fields of the several subclasses of the property marked with @IndexedEmbedded are not getting indexed, but the fields of the base class are. Below is an adjusted mapping from that of the previous post that illustrates my conditions a bit better:

Code:
@Entity
@Table(name="form")
@Indexed
public class Form implements Serializable, Cloneable , IFormsDataObject
{
            ......

       private Field field;

   @ManyToOne(fetch = FetchType.LAZY)
   @IndexedEmbedded
   public Field getField() {
      return field;
   }

}

@Entity
@Table(name="field")
@Inheritance(strategy = InheritanceType.JOINED)
@Indexed
public abstract class Field implements Serializable {

   private int id;
   private String name;
   private Collection<Form> forms;

   @OneToMany(mappedBy="field")
   @ContainedIn
   public Collection<Form> getForms() {
      return forms;
   }

   public void setForm(Collection<Form> forms) {
      this.forms = forms;
   }

   @Id
   @DocumentId
   @GeneratedValue(strategy = GenerationType.AUTO)
   public int getId() {
      return id;
   }

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

   @org.hibernate.search.annotations.Field(index= Index.TOKENIZED, store= Store.NO)
   public String getName() {
      return name;
   }

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

@Entity
@Table(name="stringfield")
@Indexed
public class StringField extends Field implements Serializable {

   private String value;

   @org.hibernate.search.annotations.Field(index=Index.TOKENIZED, store= Store.NO)
   public String getValue() {

      return value;
   }

   public void setValue(String obj)
   {
      value = obj;
   }
}


Again, with this mapping, form.field.name gets indexed while form.field.value does not. Is there something I'm missing here?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2009 11:11 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Have you tried without transient?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 23, 2009 3:19 pm 
Newbie

Joined: Tue Jan 27, 2009 1:03 am
Posts: 4
The @Transient annotation is irrelevant in the example I posted. But yes, in the code I'm using here, there are no indexed fields that are marked with @Transient. The behavior is the same. The fields of the base class are indexed, but the fields of the subclasses are not.

Sorry for the delayed response.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 2:50 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Which version of Hibernate Search are you using? The latest 3.1.0 GA?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 24, 2009 12:52 pm 
Newbie

Joined: Tue Jan 27, 2009 1:03 am
Posts: 4
Yes. 3.1.0.GA


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2009 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hi,

actually looking at the code, we are not supporting this type of functionality at the moment. So you guys right, the above usecase won't work.

To make this work we would have to change the way meta data is handled. Maybe that could be a feature for Hibernate Search 4. If you want you can create a Jira issue for it.

--Hardy


Top
 Profile  
 
 Post subject: JIRA issue filed
PostPosted: Fri Mar 20, 2009 5:15 pm 
Newbie

Joined: Tue Jan 27, 2009 1:03 am
Posts: 4
Thanks for the help and sorry again for the long reply. I have filed a JIRA issue, which can be found here:

http://opensource.atlassian.com/project ... SEARCH-351


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