使用条件创建别名时,列索引超出范围

时间:2013-11-26 13:10:46

标签: java hibernate jpa indexing hibernate-criteria

好的,所以我得到了这个奇怪的问题,我无法解决。 我有3个实体(我会写的东西只对imo很重要)

@Data
@Entity // all @ are in javax
@Table(name = "a", schema = "pl")
@SequenceGenerator(...)
public class A extends BaseEntity {
 @OneToMany(mappedBy = "pk.a")
    private Set<ABRel> Bs = new HashSet<ABRel>();
}

@Getter
@Setter
@Entity
@Table(name = "a_b_rel", schema = "pl")
public class ABRel implements IEntity {
    @EmbeddedId
    private OfferOrderProjectRelId pk;

    public OfferOrderProjectRel(B b, A a) {
        if (a == null || b == null) {
            throw new IllegalArgumentException("B orA equals null");
        }
        B.addA(this); // this methods just adds ABRel to sets in A and B
        A.addB(this);
        pk = new ABRelId(b, a);
    }
}

@Getter
@Setter
@Embeddable
@EqualsAndHashCode
public class OfferOrderProjectRelId implements Serializable {

    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REFRESH })
    @JoinColumn(name = "b_id")
    private B b;

    @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.REFRESH })
    @JoinColumn(name = "a_id")
    private A a;

    public ABRelId(B b, A a) {
        setB(b);
        setA(a);
    }
}

@Data
@Entity (it has javax import)
@Table(name = "b", schema = "pl")
@SequenceGenerator(...)
public class B extends BaseEntity {
 @OneToMany(mappedBy = "pk.b")
 private Set<ABRel> As = new HashSet<ABRel>();

@NotBlank
@Length(max = 10000)
@Column(name = "type", length = 10000, nullable = false)
private String type;
}

ABRel和ABRelId有私有构造函数(ABRel()ABRelId())但不确定是否重要。实体工作得很好,所以我不认为他们有些错误,但是我错了。

所以我试着通过B.type为我的过滤器添加标准。标准是“在”(不知道怎么说:) :) A.class。所以这里是我试着在我的dao中添加的标准(如果有人问的话,我可以将其添加到不分离的标准中):

DetachedCriteria idCriteria = DetachedCriteria.forClass(A.class, "a");
idCriteria.createAlias("Bs", "btype", JoinType.LEFT_OUTER_JOIN, Restrictions.eq("Bs.pk.B.type", "someType"));
Criteria criteria = getSession().createCriteria(A.class, "a");
criteria.add(Subqueries.propertyIn("id", idCriteria));

我试图实现的是获得具有某些指定B.type的所有ABRel,然后我将不得不以某种方式计算它,但这不是我的问题atm。我必须使用标准,不能使用任何HQL。我还读到,hibernate在创建别名beetwen实体及其嵌入时存在某种错误,所以我也无法做到(这可能就是为什么我不得不用它来解决它)。那么任何想法?我已经没用了选项,所以任何帮助都会很棒!

我差点忘了,我收到了这个错误

  

org.hibernate.HibernateException:未知实体:null at   org.hibernate.loader.criteria.CriteriaQueryTranslator.getPropertyMapping(CriteriaQueryTranslator.java:638)     在   org.hibernate.loader.criteria.CriteriaQueryTranslator.getType(CriteriaQueryTranslator.java:587)     在   org.hibernate.loader.criteria.CriteriaQueryTranslator.getTypeUsingProjection(CriteriaQueryTranslator.java:569)     在   org.hibernate.loader.criteria.CriteriaQueryTranslator.getTypedValue(CriteriaQueryTranslator.java:627)     在   org.hibernate.criterion.SimpleExpression.getTypedValues(SimpleExpression.java:100)     在   org.hibernate.loader.criteria.CriteriaQueryTranslator.getQueryParameters(CriteriaQueryTranslator.java:335)     在   org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:151)     在   org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:68)

更新:

我已经添加了这样的

criteria.createAlias("As", "oorel", JoinType.LEFT_OUTER_JOIN);
criteria.createAlias("oorel.pk.b", "order", JoinType.LEFT_OUTER_JOIN, Restrictions.eq("type", "order"));

现在我收到新的错误(用我的母语,所以我会尝试翻译它)的postgres和hibernate异常:

  

列索引超出范围:1,列数:0

抱歉我的英文不好,并提前感谢你。

1 个答案:

答案 0 :(得分:0)

遗憾的是,这是一个尚未修复的hibernate错误。出现此错误是因为hibernate无法通过包含组合键的实体创建别名。