-1

I created a many to many relationship with an extra table(REFEREEFOUL) having the two primary keys of table foul and referee. I can add data to both tables but the extra table gets no values. how can I say that a record in foul table is related to a referee in the other table?

Relationship in Referee class:

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

Relationship in Foul class:

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

the relationships are correct, I use PersistAction.Create for creating new fouls and referees. but the problem is that I cant link them

  <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>
Cœur
  • 37,241
  • 25
  • 195
  • 267
Onix
  • 2,129
  • 2
  • 17
  • 26
  • http://stackoverflow.com/a/19465760/2459449 – Omar Apr 16 '16 at 22:16
  • so you don't post HOW you are adding data to each side, and where the persist is ? Huh. And what some JSF has to do with JPA entities i've no idea. The ENTITY objects are the only thing JPA cares about – Neil Stockton Apr 17 '16 at 06:07
  • Your question is genuinely confusing. JSF is a HTML form based MVC framework which is capable of consuming HTTP requests and producing HTML output. JSF has completely nothing to do with JPA. Basically all what JSF can do for you is setting submitted HTML form input values as bean properties. That's really all. Whatever you do with those model values is beyond the responsibility of JSF. You're not terribly clear on where exactly your problem is. Please inspect the model values after JSF has set them and before you persist with JPA. If they are all fine, then please remove JSF from question. – BalusC Apr 17 '16 at 08:39

1 Answers1

0

Can't check right this second if it makes a difference but off the top of my head try adding cascade = CascadeType.PERSIST (or CascadeType.ALL) to the join.

Nath Papadacis
  • 155
  • 2
  • 9