无交叉联接的JPA联接

无交叉联接的JPA联接,jpa,join,Jpa,Join,我试图在以下表格之间建立一种关系 结合 @Entity @NamedQuery(name="Combine.findAll", query="SELECT c FROM Combine c") @Table(name="COMBINE") public class Combine implements Serializable { private static final long serialVersionUID = 1L; @Id private int id;

我试图在以下表格之间建立一种关系

结合

@Entity
@NamedQuery(name="Combine.findAll", query="SELECT c FROM Combine c")
@Table(name="COMBINE")
public class Combine implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    private int id;

    private int artistid;

    private int automated;

    private int eventid;

    private int locationid;

    @Column(name="main_artist")
    private int mainArtist;

    public Combine() {
    }
事件

它当前所做的是使用以下TypedQuery生成与表的交叉联接

               StringBuffer sb = new StringBuffer();
sb.append("SELECT e FROM Event e, Combine c, Location l ");
sb.append("where e.id = c.eventid and l.id = c.locationid ");
sb.append("and e.time>=NOW() and e.soldOut='0' and e.active>=1");
这就产生了

select event0_.id as id1_26_,
 event0_.active as active2_26_,
  event0_.addbyspider as addbyspi3_26_,
   event0_.automated as automate4_26_,
    event0_.description as descript5_26_,
     event0_.doorsopen as doorsope6_26_,
      event0_.endtime as endtime7_26_,
       event0_.lastfm as lastfm8_26_,
        event0_.latest_update as latest_u9_26_,
         event0_.minimumageid as minimum10_26_,
          event0_.name as name11_26_,
           event0_.nolatertime as nolater12_26_,
            event0_.podiuminfo as podiumi13_26_,
             event0_.short_description as short_d14_26_,
              event0_.sold_out as sold_ou15_26_,
               event0_.time as time16_26_,
                event0_.update_by_bot as update_17_26_
                 from
                  event event0_
                   cross join COMBINE combine1_
                    cross join location location2_
                    where event0_.id=combine1_.eventid and location2_.id=combine1_.locationid and event0_.time>=now() and event0_.sold_out='0' and event0_.active>=1 limit ?
我根本不想创建
交叉联接
,而是希望在表之间创建
内部联接
。我怎样才能做到这一点

OneToOne有点问题,因为它无法构建到服务器。有人知道为什么这样不行吗

@OneToOne
@JoinColumn(name="eventid")
private List<Combine> combine;
@OneToOne
@JoinColumn(name=“eventid”)
私有列表合并;

您必须对实体中的关系进行建模。请参见
@ManyToOne
@onttomy
等等。我尝试了不同的关系,但没有成功,我如何在event.id=combine.eventid和combine.locationid=location.id之间创建关系?你大约一天前发布了完全相同的内容,我当时说,你在事件中没有关系可以合并,对于多个M-N关系的联接表,您也在使用table COMBINE。在考虑查询之前,您需要修复您的建模!现在你删除帖子并再次发布。答案是一样的问题是我没有实际创建这些模型,也没有实际使用JPA,所以我不确定“修复”什么。如果你能给我一个关于我的情况的例子,让我朝着正确的方向前进,我将非常感激。正如另一篇帖子所说(在你删除它之前),你可以使用JOIN来浏览关系。“从事件e中选择e加入e.combine c…”将获得加入到合并实体。任何JPQL教程都会告诉您如何进行连接
select event0_.id as id1_26_,
 event0_.active as active2_26_,
  event0_.addbyspider as addbyspi3_26_,
   event0_.automated as automate4_26_,
    event0_.description as descript5_26_,
     event0_.doorsopen as doorsope6_26_,
      event0_.endtime as endtime7_26_,
       event0_.lastfm as lastfm8_26_,
        event0_.latest_update as latest_u9_26_,
         event0_.minimumageid as minimum10_26_,
          event0_.name as name11_26_,
           event0_.nolatertime as nolater12_26_,
            event0_.podiuminfo as podiumi13_26_,
             event0_.short_description as short_d14_26_,
              event0_.sold_out as sold_ou15_26_,
               event0_.time as time16_26_,
                event0_.update_by_bot as update_17_26_
                 from
                  event event0_
                   cross join COMBINE combine1_
                    cross join location location2_
                    where event0_.id=combine1_.eventid and location2_.id=combine1_.locationid and event0_.time>=now() and event0_.sold_out='0' and event0_.active>=1 limit ?
@OneToOne
@JoinColumn(name="eventid")
private List<Combine> combine;