• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

problem with one-to-one mapping

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am getting problem with one-to-one mapping. i have mapped it as birectional, the child table is sharing PK of parent as PK.

I am using using hiber nate annotations 3.3 and spring 2.0


here is the mapping:
1.
@Entity
@Table(name = "USER")
@Proxy(lazy = true)
public class User implements Serializable
{
@Id
@Column(name = "USER_ID", nullable = false, length = 50)
@GeneratedValue(generator = "uuid.hex")
@GenericGenerator(name = "uuid.hex", strategy = "uuid.hex")
private String userId;
...
@OneToOne(fetch = FetchType.LAZY)
@Cascade({CascadeType.ALL})
@PrimaryKeyJoinColumn
private UserProfile userProfile;
}

2.

@Entity
@Table(name = "USER_PROFILE")
@org.hibernate.annotations.GenericGenerator(name = "UserProfile", strategy = "foreign", parameters = {@org.hibernate.annotations.Parameter(name = "property", value = "userProfile")})
public class UserProfile implements Serializable
{
@Id
@Column(name = "USERID")
@GeneratedValue(generator = "UserProfile")
private String userProfileId;

@OneToOne(mappedBy = "userProfile")
@SuppressWarnings("all")
private User user;
}

this is the mapping, it is hvaing normal setter/getter methods.

my problem is::

when i am adding user profile through user it is getting added:

User user=new USer();
...
UserProfile uf=new UserProfile();
uf.serUser(user);
user.setUserProfile(uf);
...
session.save(user);

but when i am trying to delete user profile from the user then its not happening:

User user=session.findByPrimaryKey(User.class,id);
//this is user is hvaing user profile
user.setUserProfile(null);
..
session.save(user);
..

but the deletion is not happening... :-(

please help me out...what is the problem??

Thanks in advance
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please UseCodeTags.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of saving a null user profile, why not just issue a direct delete on the UserProfile?

-Cameron McKenzie
 
Lavanya Rao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, i can do like that also. but why its not wroking like this?? when i am trying to add its happening , when i am deleting the User its getting deleted. but when i am setting null objevt in side User then its not firing update query...

is any thing wrong or it wont work like that or what...

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to set the the UserProfiles User to null before saving:

 
Lavanya Rao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried as above metioned, but its not working. It's not at all firing any query

User user=session.findByPrimaryKey(User.class,id);
user.getUserProfile().setUser(null);
user.setUserProfile(null);
..

no use :-(

Is any thing wrong in the mapping??
 
Lavanya Rao
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please any body do reply to my query..

i want to implement it is in my proj....
this is the only out standing item i have....



Thanks in advance,
Lavanya
 
Are we home yet? Wait, did we forget the tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic