Hi!
How could I know that there is a CINFO_ID column at Address to use @JoinColumn(name="CINFO_ID") at ContactInfo.addresses?
About Question enthuware.oce-jpad.v6.2.429 :
Moderators: Site Manager, fjwalraven
-
- Posts: 6
- Joined: Mon Jun 16, 2014 9:47 am
- Contact:
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.429 :
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.
-
- Posts: 2
- Joined: Mon May 02, 2016 3:45 am
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.429 :
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;
}
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.429 :
No, why do you think so?
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Mon May 02, 2016 3:45 am
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.429 :
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:
and there's no CONTACTINFO_ID column as the correct answer suggests:
Code: Select all
CREATE TABLE ADDRESS (ID BIGINT NOT NULL, LINE1 VARCHAR(255), ADDRESSES_ID INTEGER, PRIMARY KEY (ID))
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;
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.oce-jpad.v6.2.429 :
You are right. The JavaDoc for the name attribute of JoinColumn annotation clearly says:
thank you for your feedback!
Paul.
Fixed.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.
thank you for your feedback!
Paul.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 28 guests