Joda时间间隔无法通过Hibernate建立索引

发布于 2024-10-19 13:26:08 字数 2628 浏览 6 评论 0原文

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

我正在使用 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;
    }

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

我要求 solr 索引此类的方式是

solrServer.addBean(estate);

该 Estate 对象包含我上面提到的 EstateViewings 对象的列表。

Solr 索引除 EstateViewings 列表之外的 Estate 对象中存储的其他数据。

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

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

I have a database table which has two colums together specifying start time and end time of an event.

I am using Hibernate to access database and retrieve and store data.

My hibernate Model class for this table looks like this.

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;
    }

But when i give solar to index this class, it does not index Joda time interval.

The way i am asking solr to index this class is

solrServer.addBean(estate);

This estate object contains List of EstateViewings objects that i have mentioned above.

Solr index other data stored in Estate object except List of EstateViewings.

i was wondering whether this is because of the Joda time interval i am using.

Could anyone help me in finding solutions for this problem.Thanx in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花间憩 2024-10-26 13:26:08

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

I don't see why Solr would have to understand Jodatime types. I think you'll have to map it to a standard type (e.g. a long of ticks) before feeding it to Solr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文