Java 如何跳出HQL特别栏目“;索引“;在HQL中
我有这样的实体:Java 如何跳出HQL特别栏目“;索引“;在HQL中,java,hibernate,Java,Hibernate,我有这样的实体: class Index{ } class Foo { @OneToMany @JoinColumns{....} private Set<Bar> bars; } class Bar{ @ManyToOne @JoinColumn(name="index_id") private Index index; } Hibernate假设“index”是bar的集合索引,就像在foo.bar中一样,这导致了如下异常 o
class Index{
}
class Foo {
@OneToMany
@JoinColumns{....}
private Set<Bar> bars;
}
class Bar{
@ManyToOne
@JoinColumn(name="index_id")
private Index index;
}
Hibernate假设“index”是bar
的集合索引,就像在foo.bar
中一样,这导致了如下异常
org.springframework.orm.hibernate3.HibernateSystemException: Property index does not exist in collection foo.Foo.bars;
nested exception is org.hibernate.MappingException: Property index does not exist in collection foo.Foo.bars
我是否可以告诉Hibernate,我不是在寻找那个“特殊”属性,而是在寻找我映射的普通字段
(我已经阅读了前面的几个问题,这些问题涉及使用反勾号或方括号转义关键字。但是它们只适用于作为关键字的映射列。在我的情况下,它不起作用)我只需为类和属性选择另一个名称。索引也是一个SQL关键字,使用这个名称是自找麻烦。例如,为什么不使用位置?@JBNizet原因是这里没有更好的词选择:这里的P Index不是作为位置的索引。这是这里描述的索引:当然,重命名东西是一种可能的解决方法(我已经采取了另一种解决方法),但我更希望知道是否有适当的方法来处理这种情况。
org.springframework.orm.hibernate3.HibernateSystemException: Property index does not exist in collection foo.Foo.bars;
nested exception is org.hibernate.MappingException: Property index does not exist in collection foo.Foo.bars