将数据添加到多对多JPA关系中

时间:2016-04-16 21:08:42

标签: mysql jsf jpa jsf-2 many-to-many

我与额外的桌子(REFEREEFOUL)创造了多对多的关系,桌子上有两个主要的犯规和裁判。我可以向两个表添加数据,但额外的表没有值。我怎么能说在罚单表中的记录与另一张桌子上的裁判有关?

裁判级别的关系:

@ManyToMany(mappedBy = "refereeList", fetch = FetchType.EAGER)
private List<Foul> foulList;

犯规级别的关系:

@JoinTable(name = "REFEREEFOUL", joinColumns = {
        @JoinColumn(name = "FOULID", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "REFEREEID", referencedColumnName = "ID")})
    @ManyToMany(fetch = FetchType.EAGER)
    private List<Referee> refereeList;

关系是正确的,我使用PersistAction.Create来创造新的犯规和裁判。但问题是我无法将它们联系起来

  <h:panelGroup id="display">
                    <p:panelGrid columns="2" rendered="#{refereeController.selected != null}">
                        <p:outputLabel value="id" for="id" />
                        <p:inputText id="id" value="#{refereeController.selected.id}"  />
                        <p:outputLabel refereename" for="refereename" />
                        <p:inputText id="refereename" value="#{refereeController.selected.refereename}" title="#{bundle.CreateRefereeTitle_refereename}" />
                        <p:outputLabel value="refereeposition" for="refereeposition" />
                        <p:inputText id="refereeposition" value="#{refereeController.selected.refereeposition}"  />
                        <p:outputLabel value="gameid" for="gameid" />
                        <p:selectOneMenu id="gameid" value="#{refereeController.selected.gameid}" >
                            <f:selectItems value="#{gameController.itemsAvailableSelectOne}"
                                           var="gameidItem"
                                           itemValue="#{gameidItem}"/>
                        </p:selectOneMenu>
                    </p:panelGrid>
                    <p:commandButton actionListener="#{refereeController.create}" value="#{bundle.Save}" update="display,:RefereeListForm:datalist,:growl" oncomplete="handleSubmit(args,'RefereeCreateDialog');"/>

                </h:panelGroup>

1 个答案:

答案 0 :(得分:0)

如果它有所不同但是不能在第二步检查,但是尝试将cascade = CascadeType.PERSIST(或CascadeType.ALL)添加到连接中。