1 Reply Latest reply on Mar 24, 2014 1:42 PM by Sanne Grinovero

    Field Joda Time in index

    Serge Moers Newbie

      Hi all,

       

      In my project, I use the package "Joda Time" to manipulate the dates.

      I have problems to insert this object type in the index key.

      If I not use a specific annotation, I receive this error : "Exception in thread "main" org.hibernate.search.SearchException: HSEARCH000135: Unable to guess FieldBridge for borndate in org.joda.time.DateTime"

      I have try to use the annotation "@DateBridge(resolution=Resolution.DAY)", but I receive an error at the execution "Caused by: java.lang.ClassCastException: org.joda.time.DateTime cannot be cast to java.util.Date"

       

      Can you help me ?

       

      import java.io.Serializable;
      import java.util.Hashtable;
      import java.util.UUID;
      
      import javax.persistence.Entity;
      import javax.persistence.Id;
      import javax.persistence.OneToMany;
      
      import org.hibernate.search.annotations.DateBridge;
      import org.hibernate.search.annotations.Field;
      import org.hibernate.search.annotations.Indexed;
      import org.hibernate.search.annotations.IndexedEmbedded;
      import org.hibernate.search.annotations.Resolution;
      import org.joda.time.DateTime;
      
      @Entity
      @Indexed
      public class AuthorInfinispan implements IAuthor,Serializable {
          
          @Id
          private UUID id;
          @Field
          private String lastname;
          @Field
          private String firstname;
          @Field
          private String authoralias;
          private IPhotoOrCover photo;
          @Field
          private String website;
          @Field
          private String biography;
          @Field
          private String comment;
          @Field
          @DateBridge(resolution=Resolution.DAY)
          private DateTime borndate;
          @Field
          @DateBridge(resolution=Resolution.DAY)
          private DateTime creationdate;
          @OneToMany(mappedBy="author")
          @IndexedEmbedded
          private Hashtable<UUID, ICycle> listcycle;    
          
      
          public AuthorInfinispan(){
              this.id = UUID.randomUUID();
              this.creationdate = DateTime.now();
              this.listcycle = new Hashtable<UUID, ICycle>();
          }
          
          @Override
          public UUID getID() {
              return this.id;
          }
      
          @Override
          public void setLastName(String lastname) {
              this.lastname = lastname;
          }
      
          @Override
          public String getLastName() {
              return this.lastname;
          }
      
          @Override
          public void setFirstName(String firstname) {
              this.firstname = firstname;
          }
      
          @Override
          public String getFirstName() {
              return this.firstname;
          }
      
          @Override
          public void setAuthorAlias(String authoralias) {
              this.authoralias = authoralias;
          }
      
          @Override
          public String getAuthorAlias() {
              return this.authoralias;
          }
      
          @Override
          public void setPhoto(IPhotoOrCover photo) {
              this.photo = photo;
          }
      
          @Override
          public IPhotoOrCover getPhoto() {
              return this.photo;
          }
      
          @Override
          public void setWebSite(String website) {
              this.website = website;
          }
      
          @Override
          public String getWebSite() {
              return this.website;
          }
      
          @Override
          public void setBiography(String biography) {
              this.biography = biography;
          }
      
          @Override
          public String getBiography() {
              return this.biography;
          }
      
          @Override
          public void setComment(String comment) {
              this.comment = comment;
          }
      
          @Override
          public String getComment() {
              return this.comment;
          }
      
          @Override
          public void setBornDate(DateTime borndate) {
              this.borndate = borndate;
          }
      
          @Override
          public DateTime getBornDate() {
              return this.borndate;
          }
      
          @Override
          public void setCreationDate(DateTime creationdate) {
              this.creationdate = creationdate;
          }
      
          @Override
          public DateTime getCreationDate() {
              return this.creationdate;
          }
      
          @Override
          public void setListCycle(Hashtable listcycle) {
              this.listcycle = listcycle; 
          }
      
          @Override
          public Hashtable<UUID, ICycle> getListCycle() {
              return this.listcycle;
          }
      
      }
      

       

      Many thanks,

      Serge

        • 1. Re: Field Joda Time in index
          Sanne Grinovero Master

          Hi Serge,

          the transformation into indexable objects is handled by Hibernate Search, so this is the relevant documentation to index custom types: Hibernate Search custom bridges.

           

          Essentially the framework automatically recognizes the standard types, but you can add support for any other type you might need. In particular Joda Time is widely requested, so we might add out-of-the-box support for it in a future release, but at the moment you'll need to declare a custom FieldBridge.