-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate oneToOne points to same class
PostPosted: Sat Oct 20, 2007 8:33 am 
Beginner
Beginner

Joined: Sat Oct 20, 2007 8:28 am
Posts: 28
Hi i have :
Code:
public class User implements Serializable{
...
private User referer;
...
@Id
@NotNull
@Column(name="username")
public String getUserName() {return userName;}
public void setUserName(String userName) {this.userName = userName;}
...
@NotNull
@OneToOne
@PrimaryKeyJoinColumn
public User getReferer() {return referer;}
public void setReferer(User referer) {this.referer = referer;}
....
}

}

i can't get it to work , i've tried mappedby and join column allso when i use it like above it says that referer can't be null but it's not null it holds a valid user (i inserted one into db manualy) .
and when try to use other ways it says unknow on userName on refererr_username ... what am i doing wrong ?
allso tried @onetoone with nothing else still no luck ...
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 21, 2007 6:47 am 
Newbie

Joined: Sun May 06, 2007 9:42 am
Posts: 7
Hi Amnon,

What are you trying to achieve.

Please describe you DB table with the data you have and what you want to get back when u perform your query


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 21, 2007 2:06 pm 
Beginner
Beginner

Joined: Sat Oct 20, 2007 8:28 am
Posts: 28
i have a table called user which has a PK on column usernmae (varchar) and a colum referer (varchar) that is a FK pointing to username (same table)
i want to add a new user entity (DB row) and make sure the referer is not null and pointing to an existing user PK (username)
Code:

   @Id
   @OneToOne
   @NotNull
   @Column(name="username")
   public String getUserName() {return userName;}
   public void setUserName(String userName) {this.userName = userName;}

@OneToOne
   @JoinColumn(name="referer")
   public User getReferer() {return referer;}
   public void setReferer(User referer) {this.referer = referer;}


solved , but i have another q. can i make hibernate validate that the @Id is unique and not fail on constraint violation ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 22, 2007 5:26 pm 
Newbie

Joined: Sun May 06, 2007 9:42 am
Posts: 7
@UniqueConstraint(columnNames="col1") maybe


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 5:09 pm 
Beginner
Beginner

Joined: Sat Oct 20, 2007 8:28 am
Posts: 28
bhecht wrote:
@UniqueConstraint(columnNames="col1") maybe


thanks !


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

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.