-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: MySQL + JPA + Hibernate
PostPosted: Sat Jun 22, 2013 7:28 pm 
Newbie

Joined: Thu Nov 12, 2009 4:32 pm
Posts: 16
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 table


following 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,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.