【问题标题】:Joda time interval can not be indexed through HibernateJoda时间间隔不能通过Hibernate索引
【发布时间】:2011-03-01 03:59:26
【问题描述】:

我有一个数据库表,它有两个列一起指定事件的开始时间和结束时间。

我正在使用 Hibernate 访问数据库并检索和存储数据。

我的这个表的休眠模型类看起来像这样。

public class EstateViewing implements Comparable<EstateViewing> {
    private Long id;
    private Estate estate;
    private Interval timeInterval;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "estate_viewing_generator")
    @SequenceGenerator(sequenceName = "estate_viewing_sequence", name = "estate_viewing_generator")
    public Long getId() {
        return id;
    }

    protected void setId(Long id) {
        this.id = id;
    }

    @ManyToOne
    public Estate getEstate() {
        return estate;
    }

    public void setEstate(Estate estate) {
        this.estate = estate;
    }

    @Columns(columns = { @Column(name = "timeIntervalStart"), @Column(name = "timeIntervalEnd") })
    @Type(type = "org.joda.time.contrib.hibernate.PersistentInterval")
    public Interval getTimeInterval() {
        return timeInterval;
    }

    public void setTimeInterval(Interval timeInterval) {
        this.timeInterval = timeInterval;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    @Override
    /*
     * Time not defined is conceptually thought of as an unlimited high value
     * -1 Time is earlier than other (lower value) 
     *  0 Time is equal 
     *  1 Time is later than other (higher value)
     */
    public int compareTo(EstateViewing otherViewing) {

        if (this.getTimeInterval() == null && otherViewing == null)
            return 1;

        // Not defined, so in the future at some point
        if (this.getTimeInterval() == null && (otherViewing != null && otherViewing.getTimeInterval() != null))
            return 1;

        if (this.getTimeInterval() != null && (otherViewing == null || otherViewing.getTimeInterval() == null))
            return -1;

        if (this.getTimeInterval() != null) {

            // Before
            if (this.getTimeInterval().getEnd().isBefore(otherViewing.getTimeInterval().getEnd())) {
                return -1;
            }

            if (this.getTimeInterval().getEnd().isAfter(otherViewing.getTimeInterval().getEnd())) {
                return 1;
            }
        }
        return 0;
    }

但是当我给太阳能索引这个类时,它不会索引 Joda 时间间隔。

我要求 solr 索引这个类的方式是

solrServer.addBean(estate);

这个房地产对象包含我上面提到的 EstateViewings 对象的列表。

Solr 索引存储在 Estate 对象中的其他数据,除了 EstateViewings 列表。

我想知道这是否是因为我使用的 Joda 时间间隔。

任何人都可以帮助我找到解决这个问题的方法。提前感谢任何帮助

【问题讨论】:

    标签: hibernate indexing jodatime solr


    【解决方案1】:

    我不明白为什么 Solr 必须了解 Jodatime 类型。我认为在将其提供给 Solr 之前,您必须将其映射到标准类型(例如,long 的刻度)。

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 1970-01-01
      • 2015-10-17
      • 1970-01-01
      • 2018-03-13
      相关资源
      最近更新 更多