I have a Spring Boot app using Spring JPA, hibernate, Derby database, having the following entities and relationships;
@Entity
@Table(name = "users")
public class User implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Long id;
@Column(name = "email", nullable = false, unique = true)
private String email;
//bi-directional one-to-one association to Profile
@OneToOne(cascade={CascadeType.ALL}, orphanRemoval=true)
@JoinColumn(name="profile_id")
private Profile profile;
// ... other fields + getters & setters
}
And then I have a related Entity shown below;
@Entity
@Table(name = "profiles")
public class Profile implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Long id;
//bi-directional one-to-one association to User
@OneToOne(mappedBy="profile")
private User user;
@Column(name = "first_name", nullable = false)
private String firstname;
@Column(name = "last_name", nullable = false)
private String lastname;
// ... other fields + getters & setters
}
Strangely, I noticed that when I run the application and the Database tables get created from the Entities, an email Column also gets created in the profiles Table, even though the Entity has no email field declared.
1. Can someone please first of all explain why this is happening?
2. How do I ensure that the profiles Table does not have an email Column?