-->
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.  [ 2 posts ] 
Author Message
 Post subject: EAGER null expectation issue
PostPosted: Tue Oct 10, 2017 5:20 am 
Newbie

Joined: Mon Oct 09, 2017 10:30 am
Posts: 1
Hello everyone,

I'm a bit new to Hibernate and I just wanted to ask a few questions about an issue I'm currently encountering.

To give a bit of a setting, I have a CUSTOMER entity that has a column called UPDATED_BY which is referenced to another table called USER.
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = COLUMN_NAME_UPDATED_BY)
@Cascade(value = CascadeType.DETACH)
protected MyUser updatedBy;



When I try to execute the EntityManager.find() to fetch a CUSTOMER, there are customers with UPDATED_BY values that are not existing in the USER table (which I expect). This would then result to a null CUSTOMER entity returned by the find() method as explained by this message

DEBUG [org.hibernate.jpa.spi.AbstractEntityManagerImpl] (default task-21) HHH015013: Returning null (as required by JPA spec) rather than throwing EntityNotFoundException, as the entity does not exist
(Note: In which I tried to execute the query made by hibernate which actually returned a result of Customer but I assume that since update_by has no value, it returned the customer as a whole to be null)

With this, I wanted to know if there is a way to handle this by giving the UPDATED_BY column a "default" value when its current value(not null) does not actually exist in the USER table. Or if there are other better way to handle it instead. Also, I wanted to ask how this behavior actually works because it seems to me that when a child of parent is null and a find() is requested, the parent as a whole will be returned null.

All help would be greatly appreciated!
Please ask me you need more information about the issue.


Top
 Profile  
 
 Post subject: Re: EAGER null expectation issue
PostPosted: Wed Oct 11, 2017 9:14 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
there are customers with UPDATED_BY values that are not existing in the USER table (which I expect)


Sounds like a bad DB design you have there.

Since you said you were new to Hibernate, I expect you read the User Guide fully, right? If you did, you might have bumped into the @NotFound annotation to help you with this task.

Anyway, if you read the docs, you'll find solutions to other issues as well.


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