-->
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.  [ 7 posts ] 
Author Message
 Post subject: Please help to work around using embedded object in JSF
PostPosted: Thu Jan 22, 2009 1:24 pm 
java code:

Although it seems that the problem is represented in UI it is actually caused by the ad-hoc null semantic of Hibernate components.

Code:
@Entity
public class Person {
   private Address name = new Address();
   ...
   @Embedded Address getAddress() {}
}

@Embeddable
public class Address {
   public String getCity() {}
   public String getStreet() {}
}


xhtml:

<h:inputText value="#{person.address.city}" />

This code produces NPE constantly when editing a person which address properties hasn't been filled in yet.

If I set address instance before person is accessed when rendering it will force dirty checking and even I hasn't changed any property the person instance itself will be updated and its version incremented.
Moreover it would cause pre-update events. Whether events are invoked would depends on data. It is unacceptable.

If I add a fake primitive propery to every Embeddable object it would cause Exception (writing null to not-null property) when loading the Object. Although some forums suggest it as workaround it does not work for me.

So I'm asking experienced Hibernate users to suggest me an advice what to do with that?


Top
  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 12:21 pm 
Anyone?

I tried to annotate entity with @Tuplizer but without success. I'll investigate why.

At least just answer is @Tuplizer is the right way to go?

Or just tell me how you map your entities with components to web page.


Top
  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 12:57 pm 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Quote:
If I add a fake primitive propery to every Embeddable object it would cause Exception (writing null to not-null property) when loading the Object. Although some forums suggest it as workaround it does not work for me.


Because you added this fake column to your object, hibernate creates another column in your database (unless you do not use automatic schema creation). This column is added to existing tupels, but with a null value. So to avoid this exception, you have to update your database manually (via some db-frontend) and set all the values of the fake column to a not-null-value ("0").

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 1:41 pm 
Indeed!
mmerder, hanks for pointing this out.

But this approach is just a workaround. I investigate mixin-like approach in db design and JPA. Everything went well untill I came across this very problem. There is no simple solution for Web UI. I'm wondering why it is implemented in such an inconsistent manner. The only answer I have found in the internet is the attitute to the contrary - one fills inconfortable when component has all properties of null and the component itselt is not null. Hmm ... is it a strong reason to add several dozens of lines (and errors) to the Hibernate source code and lose performance?

I would like to be able to switch off this "optimization" for the entity and its descendents. May I fill in the Jira issue?


Top
  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 2:27 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
I think the ability to specify the state of all-null components is a good feature. Feel free to file a JIRA. Today the assumption is that an all-null property becomes itself null during hydration. Any implementation would default to current behavior but I think it's a nice addition to Hibernate for use cases just such as this.

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 2:38 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Did you file a JIRA? If yes, what is it's url?

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 27, 2009 8:24 am 
Yes, I have just filed it

http://opensource.atlassian.com/project ... e/HHH-3733


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