@OrderColumn,@OneToMany&用于收集的空索引列 [英] @OrderColumn, @OneToMany & null index column for collection

查看:100
本文介绍了@OrderColumn,@OneToMany&用于收集的空索引列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建保存顺序的父子表。 Hibernate文档中的例子7.8展示了如何做到这一点:

  @Entity 
public class Customer {
@Id @GeneratedValue public Integer getId(){return id; }
public void setId(Integer id){this.id = id; }
私人整数ID;

@OneToMany(mappedBy =customer)
@OrderColumn(name =orders_index)
public List< Order> getOrders(){返回订单; }
public void setOrders(List< Order> orders){this.orders = orders; }
私人列表<订单>命令;
}

@Entity
public class Order {
@Id @GeneratedValue public Integer getId(){return id; }
public void setId(Integer id){this.id = id; }
私人整数ID;

public String getNumber(){return number; }
public void setNumber(String number){this.number = number; }
私人字符串编号;

@ManyToOne
public Customer getCustomer(){return customer; }
public void setCustomer(Customer customer){this.customer = customer; }
私人客户号码;
}

来自 http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html #collection-indexed



当我尝试这样做时,我收到一个错误:
null收藏集的索引列



有一个Hibernate问题描述了这个问题并给出了一个无效的例子,但它明确地说我从文档中给出的例子是有效的。

  @Entity 
public class Parent {
@OneToMany(mappedBy =parent)
@OrderColumn(name =order)
私人列表< Child>儿童;
}

@实体
公共类子元素{
@ManyToOne
私有父母;
}

from:https://hibernate.onjira.com/browse/HHH-5390



也许我很密集,但我没有看到这两个例子之间的区别。一种是:

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ @

另一种是:

  @OneToMany(mappedBy =parent)
@OrderColumn(name =order)

当然,我还没有弄清楚如何让OrderColumn工作。有没有人有任何洞见,为什么这些例子之一是有效的,而另一个不是?

解决方案

该错误是指Hibernate 3.5 .3虽然文档引用了Hibernate 3.6。从我的理解中可以看出, HHH-5390 问题已得到解决。你使用哪个版本的Hibernate?
请注意,您必须在 @OrderCoulumn 中具有精确指定名称的列。



另请参阅讨论关于同一问题和解决方法




更新



显然它不受支持,如 HHH-5732 所述,存在文档错误。我从HHH-5390想到,被分配的人(同样拥有HHH-5390的人)已同意解决这个问题。但目前还不清楚是否会发生。何时发生。


I am trying to create parent child tables where the order is preserved. The example 7.8 from Hibernate documentation shows how to do this:

@Entity
public class Customer {
   @Id @GeneratedValue public Integer getId() { return id; }
   public void setId(Integer id) { this.id = id; }
   private Integer id;

   @OneToMany(mappedBy="customer")
   @OrderColumn(name="orders_index")
   public List<Order> getOrders() { return orders; }
   public void setOrders(List<Order> orders) { this.orders = orders; }
   private List<Order> orders;
}

@Entity
public class Order {
   @Id @GeneratedValue public Integer getId() { return id; }
   public void setId(Integer id) { this.id = id; }
   private Integer id;

   public String getNumber() { return number; }
   public void setNumber(String number) { this.number = number; }
   private String number;

   @ManyToOne
   public Customer getCustomer() { return customer; }
   public void setCustomer(Customer customer) { this.customer = customer; }
   private Customer number;
}

from http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html/collections.html#collections-indexed

When I try this I get an error: null index column for collections

There is Hibernate issue that describes the problem and gives an invalid example, but it specifically says that the example I gave above from the docs IS valid.

@Entity
public class Parent {
    @OneToMany(mappedBy="parent")
    @OrderColumn(name="order")
    private List<Child> children;
}

@Entity
public class Child {
    @ManyToOne
    private Parent parent;
}

from: https://hibernate.onjira.com/browse/HHH-5390

Maybe I'm being dense, but I don't see the difference between these two examples. One is:

@OneToMany(mappedBy="customer")
@OrderColumn(name="orders_index")

The other is:

@OneToMany(mappedBy="parent")
@OrderColumn(name="order")

And of course, I haven't figured out how to the get OrderColumn to work. Does anyone have any insight into why one of these examples is valid and the other is not?

解决方案

The bug refers to Hibernate 3.5.3 while documentation refers to Hibernate 3.6. It is my understanding from comments that the issue HHH-5390 has been resolved. Which version of Hibernate do you use? Note that you must have a column with exact specified name in @OrderCoulumn.

Also see this discussion about that same issue and a workaround in case of 3.5.


Update

Apparently it remains unsupported and there is a documentation bug as described by HHH-5732. I thought from HHH-5390 that the person who it was assigned (same who owns HHH-5390) has agreed to fix it. But it's not clear whether and when it is going to happen.

这篇关于@OrderColumn,@OneToMany&amp;用于收集的空索引列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆