Page 1 of 1

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

Posted: Sat Aug 29, 2015 9:32 am
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?

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

Posted: Sat Aug 29, 2015 11:42 am
by admin
It is implied that if you use this annotation, you would be creating that column.

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

Posted: Mon May 02, 2016 3:56 am
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;
}

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

Posted: Tue May 17, 2016 10:02 pm
by admin
No, why do you think so?

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

Posted: Sun May 22, 2016 2:59 am
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;

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

Posted: Sun May 22, 2016 3:30 am
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.