-->
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.  [ 3 posts ] 
Author Message
 Post subject: OneToOne where row may not exist
PostPosted: Thu Jun 28, 2007 5:23 pm 
Newbie

Joined: Wed Apr 27, 2005 7:40 pm
Posts: 4
Using Hibernate with annotations version: 3.2.1

I have a Customer object which has an association to an AccountManager object. Problem is that the value in the join column in Customer may not exist in the AccountManager table (no the value isn't null unfortunately). My question is how can I tell hibernate to select the Customer even if the AccountManager doesn't exist? Here is more info:

@Entity
@Table(name="customers")
public class Customer {

private AccountManager acctMgr;

@OneToOne
@JoinColumn(name="acct_mgr_id", referencedColumnName="user_id")
public AccountManager getAcctMgr() { ... }
public void setAcctMgr() { ... }

...
}
--
@Entity
@Table(name="users")
public class AccountManager {
private long userId;

@Column(name="user_id")
public long getUserId() { ... }
...
}

For example, if the acct_mgr_id is 0 (no acct mgr yet) I get the following error:
"No row with the given identifier exists"

I realize this isn't optimal db design at work here (I know how to get it to work with nulls), but I have to work with a legacy system. Is there any way to do what I want? Maybe specify some hql that says if acct_mgr_id is 0 then return null for this association?

Thanks in advance :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 11:17 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
try @NotFound(IGNORE)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 2:35 pm 
Newbie

Joined: Wed Apr 27, 2005 7:40 pm
Posts: 4
emmanuel wrote:
try @NotFound(IGNORE)


Thanks! This worked.

@NotFound(action=NotFoundAction.IGNORE)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.