-->
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: need help with component object
PostPosted: Tue Jun 14, 2005 6:47 pm 
Beginner
Beginner

Joined: Sat Jan 29, 2005 8:49 pm
Posts: 20
Hibernate version:
3.0.5

Mapping documents:
Code:
<component name="webAddress" class="WebAddress">
<property name="url" column="WEB" insert="true" access="property" type="string"/>
</component>


I use a component for the web address so I can use a validate method on the url. Though when the database field WEB is null the containing object webAddress is not created but set to null.

The same effect happens when I use the not-null attribute.
Code:
<component name="webAddress" class="WebAddress">
<property name="url" column="WEB" insert="true" access="property" type="string" not-null="true"/>
</component>


The only workaround I have found is to use a second dummy property that uses a formula.

Code:
<component name="webAddress" class="WebAddress">
<property name="url" column="WEB" insert="true" access="property" type="string"/>
<property name="dummy" formula="''"/>
</component>


What else can I do?[/code]


Top
 Profile  
 
 Post subject: quote from the manual
PostPosted: Tue Jun 14, 2005 6:57 pm 
Beginner
Beginner

Joined: Sat Jan 29, 2005 8:49 pm
Posts: 20
I just found a paragraph in the manual about that

http://www.hibernate.org/hib_docs/reference/en/html/components.html

Quote:
Like all value types, components do not support shared references. The null value semantics of a component are ad hoc. When reloading the containing object, Hibernate will assume that if all component columns are null, then the entire component is null. This should be okay for most purposes.


For now I have manipulated the setter function to something like ...

Code:
public void setWebAddress(WebAddress webAddress) {
  this.webAddress = (webAddress == null) ? new WebAddress() : webAddress;
}


... but I hope there is something more simple (like a not-null of the component)

Code:
<component name="webAddress" class="WebAddress" not-null="true">
  <property name="url" column="WEB" insert="true" access="property" type="string"/>
</component>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 6:18 am 
Regular
Regular

Joined: Thu Oct 13, 2005 4:19 am
Posts: 98
I 'll also use your hack as it isn't okay in my situation to leave it null :(

_________________
http://www.ohloh.net/accounts/ge0ffrey


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.