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

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
crolip
Posts: 6
Joined: Mon Jun 16, 2014 9:47 am
Contact:

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

Post by crolip »

Hi!

How could I know that there is a CINFO_ID column at Address to use @JoinColumn(name="CINFO_ID") at ContactInfo.addresses?

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

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

Post by admin »

It is implied that if you use this annotation, you would be creating that column.
If you like our products and services, please help us by posting your review here.

shubeer
Posts: 2
Joined: Mon May 02, 2016 3:45 am
Contact:

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

Post by shubeer »

In the explanation of the correct answer, should this not read:
public class ContactInfo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
// Notice that this is a unidirectional one to many, so a join table
// will be created by default. The JoinColumn forces the use of
// foreign key column in Address table instead of creating a join table.
@OneToMany(cascade = {
CascadeType.ALL
})
// CINFO_ID column will be created in Address table.
// if name is not specified, the column will be named ADDRESSES_ID
@JoinColumn(name = "CINFO_ID")
private List<Address> addresses;
private String emailid;
}

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

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

Post by admin »

No, why do you think so?
If you like our products and services, please help us by posting your review here.

shubeer
Posts: 2
Joined: Mon May 02, 2016 3:45 am
Contact:

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

Post by shubeer »

I removed the name attribute from the @JoinColumn annotation on the addresses attribute to verify the default that will be applied, and the table created was:

Code: Select all

CREATE TABLE ADDRESS (ID BIGINT NOT NULL, LINE1 VARCHAR(255), ADDRESSES_ID INTEGER, PRIMARY KEY (ID))
and there's no CONTACTINFO_ID column as the correct answer suggests:

Code: Select all

// CINFO_ID column will be created in Address table.
//if name is not specified, the column will be named CONTACTINFO_ID
@JoinColumn(name="CINFO_ID")
private List<Address> addresses;

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

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

Post by admin »

You are right. The JavaDoc for the name attribute of JoinColumn annotation clearly says:
The concatenation of the following: the name of the referencing relationship property or field of the referencing entity or embeddable class; "_"; the name of the referenced primary key column. If there is no such referencing relationship property or field in the entity, or if the join is for an element collection, the join column name is formed as the concatenation of the following: the name of the entity; "_"; the name of the referenced primary key column.
Fixed.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests