-->
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.  [ 5 posts ] 
Author Message
 Post subject: components and subclassing: how
PostPosted: Mon Sep 05, 2005 11:56 am 
Pro
Pro

Joined: Wed Nov 05, 2003 7:22 pm
Posts: 211
I have an address class as a component for the user class and a mobile phone class as a component for the address class. Because of locale specific validation, the mobile and address are locale specific (NLAddress, UKAddress, etc.) and instantiated through a factory.

The question is how do I make sure the classes are retrieved in their specific locale version? Because Hibernate requires you to specify the component class, I always get the generic class (AnAddress, AMobile) back when the user is instantiated and the address and mobile is retrieved from the database.

I guess my real question is: how to distinguish between subclasses within a component?


I have the following file structure:
Subscriber.java - class containing component reference to Address interface. Subclass of User.java

AddressFactory.java - factory creating addresses based on created string name, based on locale
Address.java - interface containing component reference to mobile.java
AnAddress.java - generic class, implements Address
NLAddress.java - implementation class, extends AnAddress

MobileFactory.java - factory creating mobiles based on created string name, based on locale
Mobile.java - interface
AMobile.java - generic class, implements Mobile
NLMobile.java - implementation class, extends AMobile


user.hbm.xml
<component name="address" class="nl.msw.dates4free.business.entities.address.AnAddress">
<component name="mobile" class="nl.msw.dates4free.business.entities.address.AMobile">
<property name="mobile" length="25"/>
</component>
<many-to-one column="FK_provinceID" cascade="none" name="province"/>
<property name="city" length="255"/>
<property name="street" length="255"/>
<property name="zipcode" length="255"/>
<many-to-one column="FK_countryID" cascade="none" outer-join="true" name="country"/>
</component>



Kind regards,

Marc


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 05, 2005 12:52 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 10:20 am
Posts: 77
Please post your mapping files for the Address classes.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 12:11 pm 
Newbie

Joined: Thu Sep 08, 2005 12:06 pm
Posts: 2
I think I have a similar issue: My polymorphism is defined on a
Code:
component
(value object), instead of the
Code:
class
(entity):

For example,
public class A{ // persistent
Long id;
Specification spec;
}

public abstract class Specification{
}

public class ASpecification extends Specification{
}

How do I define the mapping?

Thanks[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:31 pm 
Newbie

Joined: Wed Aug 31, 2005 9:13 am
Posts: 8
Location: Springfield, VA
I had tried several work arounds for my abstract class Activity. It has abstract method that is the only diffrence for the subclasses. The discriminator mechanism returns the correct concrete classes. I had to rework existing DB schema and load in the discriminator column.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="activityjammer.src.model.activity">

<class name="Activity"
table="production.activity"
discriminator-value="ABSTRACT">

<id name="id" column="id" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="discriminator" type="string"/>

< YOUR PROPERTIES HERE >

<many-to-one name="user"
class="userfactory.src.model.User"
column="id_user"
not-null="true" />

<many-to-one name="location"
class="activityjammer.src.model.Location"
column="id_location"
not-null="true" />

<subclass name="activityjammer.src.model.activity.CommuteActivity" discriminator-value="COMMUTE">
<join table="production.activitycommute">
<key column="id"/>

<many-to-one name="destination"
class="activityjammer.src.model.Location"
column="id_destination"
not-null="true"/>
</join>
</subclass>

<subclass name="activityjammer.src.model.activity.GeneralActivity" discriminator-value="GENERAL">
</subclass>

<subclass name="activityjammer.src.model.activity.HireTransportationActivity" discriminator-value="HIRE_TRANS">
</subclass>

<subclass name="activityjammer.src.model.activity.ReturnTransportationActivity" discriminator-value="RETURN_TRANS">
</subclass>

<subclass name="activityjammer.src.model.activity.RentableCheckOut" discriminator-value="CHECKOUT">
</subclass>

<subclass name="activityjammer.src.model.activity.RentableCheckIn" discriminator-value="CHECKIN">
</subclass>

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 1:52 pm 
Newbie

Joined: Thu Sep 08, 2005 12:06 pm
Posts: 2
zenmaster wrote:
I had tried several work arounds for my abstract class Activity. It has abstract method that is the only diffrence for the subclasses. The discriminator mechanism returns the correct concrete classes. I had to rework existing DB schema and load in the discriminator column.


The issue is different though. In your case, you have subclasses for persistent entities (Activity). However, what if you when to have subclasses for components? Something like this:

Code:
<class name="A" table="A">
[color=red] 
  <compoent name="spec" name="Specification">
     <discriminator ...>
      <subclass name="ASpecification" discriminator-value="...">
   </component>
[/color]
</class>


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