Page 1 of 1

About Question enthuware.oce-jpad.v6.2.414 :

Posted: Sun Mar 19, 2017 5:51 am
by unvector
Hello,

I think the explanation for the third option: "the value of joinColumns must be @JoinColumns or @JoinColumn" is invalid, because joinColumns is defines as JoinColumn[].

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Sun Mar 19, 2017 11:45 am
by admin
You can use @JoinColumn also if there is only one.

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Tue Mar 21, 2017 9:29 am
by unvector
You're right, but what I meant is the "JoinColumns" annotation - the grouping annotation which can consist of several @JoinColumn definitions.

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Tue Mar 21, 2017 11:11 pm
by admin
You can annotate like this:
joinColumns=@JoinColumn(name="EV_2")
or
joinColumns=@JoinColumns({
@JoinColumn(name="DEPT_NAME", referencedColumnName="Name"),
@JoinColumn(name="DEPT_ID", referencedColumnName="ID")
})

Both are valid. That is why the explanation says that the value of joinColumns can be @JoinColumn or JoinColumns

HTH,
Paul.

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Wed Mar 22, 2017 2:26 am
by unvector
The first case works perfectly, but the second does not compile:

"Error:(45, 28) java: incompatible types: javax.persistence.JoinColumns cannot be converted to javax.persistence.JoinColumn"

Examples:

Code: Select all


@Entity
@DiscriminatorValue("QP")
@AssociationOverride(
        name = "employees", joinColumns = @JoinColumns({
                 @JoinColumn(name = "FK_EMP")
        })
)
public class QualityProject extends Project {
       ...
}

Code: Select all

    @ElementCollection(targetClass = VacationEntry.class)
    @CollectionTable(name = "VACATIONS",
            joinColumns = @JoinColumns({@JoinColumn(name = "EMP_ID")}))
    @AttributeOverride(name = "daysTaken",
            column = @Column(name = "DAYS_ABS"))
    private Collection vacationBookings;

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Wed Mar 22, 2017 2:39 am
by admin
Not sure why it is not working, but you can see the example of @JoinColumns at
http://docs.oracle.com/javaee/7/api/jav ... lumns.html

Code: Select all

@JoinColumns({
        @JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
        @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
    })

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Wed Mar 22, 2017 10:10 am
by unvector
This example is for using @JoinColumns alone, not as a value of "joinColumns" property of @AssociationOverride.

Code for full example:

Code: Select all

    @ManyToOne
    @JoinColumns({
        @JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
        @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
    })
    public Address getAddress() { return address; }

Re: About Question enthuware.oce-jpad.v6.2.414 :

Posted: Wed Mar 22, 2017 12:05 pm
by admin
I tried looking for an example of joinColumns property but couldn't find any. But I think you are right. I have updated the explanation.

thank you for your feedback!
Paul.