I have 2 tables , user and user_profile with OneToOne Relationship,
user table has got id,user_name,first_name,last_name with ID has primary key,
user profile table has id,name,user_id with ID has primary key and user_id has foreign key with user tablefollowing are two JPA Entity objects
Code:
@Entity @Table(name = "user") public class User{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "user_name",unique=true,nullable=false)
private String name;
@Column(name = "first_name")
private String firstName;
@Column(name = "last_name")
private String lastName;
[b] @OneToOne(cascade = {CascadeType.ALL})
@JoinColumn(name="user_id")
public UserProfile userProfile;[/b]
//with set/get methods
}
Code:
@Entity @Table(name = "user_profile") public class UserProfile {
@Id
@Column(name = "id")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;
@Column(name = "name")
private String name;
@Column(name = "user_id")
private Long userId;
[b]@OneToOne(mappedBy="userProfile")
private User user;[/b]
//with set/get methods }
when i am trying to insert into both the tables i see user_id column getting added into USER table with value and i don't see any value in the user_id column of USER_PROFILE table, I am new to this MySQL could some one shed light how to fix this,