-->
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: Component inside composite-element
PostPosted: Fri Apr 30, 2010 8:49 am 
Newbie

Joined: Sun Sep 16, 2007 6:01 am
Posts: 2
Hello,

It seems that Hibernate does not allow composite-elements to contain a component. It is not allowed by the XSD schema used for mapping file.

I would like to avoid making the xyz.AssignedCustomerProject an entity if possible. The only solution I can think of is creating a composite user type for the billingRate and map it using the "property" element rather then the "component" element. I do not like this solution though.

Thank you in advance for any hints.
Jan

<!-- customer projects assigned to the company user -->
<bag name="assignedCustomerProjects"
table="rel_company_user_customer_project"
cascade="save-update, delete">

<key column="company_user_id"/>

<composite-element class="xyz.AssignedCustomerProject">
<many-to-one name="customerProject"
class="xyz.CustomerProject"
cascade="none">

<column name="customer_project_id"
not-null="true"/>
</many-to-one>

<!-- PROBLEM HERE - component not allowed here -->
<component name="billingRate"
class="xyz.Rate">

<property name="value"
column="bill_rate_value"
type="double"
not-null="true"/>

<property name="currency"
column="bill_rate_currency_id"
type="integer"
not-null="true"/>
</component>
</composite-element>
</bag>


Top
 Profile  
 
 Post subject: Re: Component inside composite-element
PostPosted: Fri Apr 30, 2010 4:17 pm 
Newbie

Joined: Fri Apr 30, 2010 4:00 pm
Posts: 1
I actually just ran into this exact same issue today and stumbled upon your post while trying to find a solution.

I think you should be able use a nested-composite-element in place of the component. There is some information in the Hibernate documentation at http://docs.jboss.org/hibernate/core/3.3/reference/en/html/components.html#components-dependentobjects.
Quote:
Composite elements can contain components but not collections. If your composite element contains components, use the <nested-composite-element> tag. This case is a collection of components which themselves have components. You may want to consider if a one-to-many association is more appropriate. Remodel the composite element as an entity, but be aware that even though the Java model is the same, the relational model and persistence semantics are still slightly different.


Try changing your
Code:
<!-- PROBLEM HERE - component not allowed here -->
<component name="billingRate" class="xyz.Rate">
...

to
Code:
<nested-composite-element name="billingRate" class="xyz.Rate">
  <property name="value" column="bill_rate_value" type="double" not-null="true"/>
  <property name="currency" column="bill_rate_currency_id" type="integer" not-null="true"/>
</nested-composite-element>


Hopefully that works!


Top
 Profile  
 
 Post subject: Re: Component inside composite-element
PostPosted: Fri Apr 30, 2010 6:09 pm 
Newbie

Joined: Sun Sep 16, 2007 6:01 am
Posts: 2
Thanks for your reply. I eventually solved the problem by creating a composite user type to map xyz.Rate instances. These instances are used at multiple places so I can justify to myself the effort to create and use the user type. So now I have something like this:

<composite-element class="xyz.AssignedCustomerProject">
<many-to-one .../>

<!-- property whose type is xyz.Rate -->
<property name="billingRate"
<!-- composite user type to map xyz.Rate instances onto the two specified table columns -->
type="SL_RATE">
<column name="bill_rate_value"/>
<column name="bill_rate_currency_id"/>
</property>

</composite-element>

Jan


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.