English 中文(简体)
JPA2 标准
原标题:JPA2 Criteria Query JOIN
  • 时间:2011-10-10 04:21:41
  •  标签:
  • jpa-2.0

我有以下类别(实体)

@Entity
public class  Magazine {
    private int id ;
    private String magazine;

            //getters and setters
}

// tracking the magazine arrival
@Entity 
public class MagazineIn {
    private int id;
    private java.util.Date inDate;
    private java.util.Date magdate;

    @OneToOne
    private Magazine mag ; 
            //getters and setters

}

Now i want to get all arrival status of all magazine , whether magazine has in or not

使用标准

以下是法典

    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<Object[]> cq = cb.createQuery(Object[].class);

        Root<MagazineIn> magIn = cq.from(MagazineIn.class);
    Join<Magazine,MagazineIn> mag =  magIn.join("mag" , JoinType.LEFT);

        cq.multiselect(mag.get("magazine") , magIn.get("magdate") , 
            magIn.get("inDate"));
    TypedQuery<Object[]> q = em.createQuery(cq);

但是,我并没有看到所有杂志的收发日期和日期都是无效的。 RLI JOIN没有得到支持。 什么错误?

最佳回答

如果实体关系不可能发生变化,那么你可以考虑改变你对杂志的询问,并使用与磁变数挂钩的分座。

问题回答

什么错误是,你确实需要这样做的权利。 页: 1 在,以及从杂志到杂志的询问 左派加入。

我通过杂志的集刊解决了这一问题。

@OneToMany(mappedBy="mag",FETCHTYPE.LAZY)
List<MagazineIn> arrivals




相关问题
JPA 2.0 EclipseLink Check for unique

I have a collumn as unique=true.. in Exam class.... I found that because transactions are commited automaticaly so to force the commit i use em.commit() However i would like to know how to check if ...

Creating queries using Criteria API (JPA 2.0)

I m trying to create a query with the Criteria API from JPA 2.0, but I can t make it work. The problem is with the "between" conditional method. I read some documentation to know how I have to do it, ...

Hibernate 3.5-Final in JBoss 5.1.0.GA

Hibernate 3.5-Final is finally here and it offers the much anticipated JPA2 support, amongst other features. I am working on a project(EJB3 based) using JBoss 5.1.0.GA and Hibernate 3.3, but I wanted ...

Does Hibernate 3.5.0-CR-2 release support JPA2.0

I see that Hibernate home page has a symbol informing that it implements JSR 317, but I couldn t find if it implements the full spec. Does anybody knows if Hibernate 3.5.0-CR-2 fully implements the ...

A concise, clear list of what is new in JPA2?

Does anybody know of a good list of what is new in JPA 2? Not what is new with Hibernate/TopLink in the version that supports JPA 2 but what is new in the actual spec.

热门标签