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

All the posts and topics that contain only an error report will be moved here after the error is corrected. This is to ensure that when users view a question in ETS Viewer, the "Discuss" button will not indicate the presence of a discussion that adds no value to the question.

Moderators: Site Manager, fjwalraven

Post Reply
unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

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

Post 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[].

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post by admin »

You can use @JoinColumn also if there is only one.

unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

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

Post by unvector »

You're right, but what I meant is the "JoinColumns" annotation - the grouping annotation which can consist of several @JoinColumn definitions.

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

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

Post 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;

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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")
    })

unvector
Posts: 18
Joined: Sun Jun 21, 2015 2:56 am
Contact:

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

Post 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; }

admin
Site Admin
Posts: 10386
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

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

Post 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.

Post Reply

Who is online

Users browsing this forum: No registered users and 10 guests