You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Dan Bradley <de...@gmail.com> on 2005/09/19 21:15:30 UTC

Mapping Composition (aka composite property, aka value objects)

I have one entity, a Product, which holds a Price as a composed (not
related) entity. A Price is a numeric value and a currency code as a
String. Prices don't have a distinct identity in the database - they
are value objects, so this is not the more usual persistent entity to
persistent entity relationship mapping.

How would you map this using iBATIS? I've tried a variety of things
without success and can't yet find any documentation that covers this
situation. Thanks.

Re: Mapping Composition (aka composite property, aka value objects)

Posted by Dan Bradley <de...@gmail.com>.
I have the same question myself, but haven't yet figured out how to
handle that situation.

Anyone else know?

On 9/20/05, Volker_Reichel@t-online.de <vo...@t-online.de> wrote:
> If iBATIS is doing these steps
> 
>         Product product = new Product();
>         product.getPrice().setAmount(amount);
> 
> the Product constructor has to create a Price instance as side-effect.
> My question is: What do you do in case the Product does not need to have a
> related Price instance for each Product?
> 
> 
> Volker
> 
> -----Ursprüngliche Nachricht-----
> Von: Dan Bradley [mailto:debradley@gmail.com]
> Gesendet: Montag, 19. September 2005 22:11
> An: lmeadors@apache.org
> Cc: user-java@ibatis.apache.org
> Betreff: Re: Mapping Composition (aka composite property, aka value
> objects)
> 
> 
> Of course, after being stuck on it for a while, I figured it out right
> after I posted the question:
> 
> <typeAlias alias="product" type="com.foo.Product" />
> <resultMap id="result" class="product">
>                 <result property="name" column="name" />
>                 <result property="description" column="description" />
>                 <result property="price.amount" column="amount" />
>                 <result property="price.currency" column="currency_code" />
>         </resultMap>
> 
> It appears that the Product class must have a Price instance that is
> initialized, not null. In other words it looks like iBATIS doesn't do:
> 
> Price price = new Price();
> price.setAmount(amount);
> Product product = new Product();
> product.setPrice(price);
> 
> But instead does:
> 
> Product product = new Product();
> product.getPrice().setAmount(amount);
> 
> Take this all with a grain of salt - I'm new to iBATIS!
> 
> On 9/19/05, Larry Meadors <la...@gmail.com> wrote:
> > Can you explain more how the model is in Java, and in the database?
> >
> > Larry
> >
> >
> > On 9/19/05, Dan Bradley <de...@gmail.com> wrote:
> > > I have one entity, a Product, which holds a Price as a composed (not
> > > related) entity. A Price is a numeric value and a currency code as a
> > > String. Prices don't have a distinct identity in the database - they
> > > are value objects, so this is not the more usual persistent entity to
> > > persistent entity relationship mapping.
> > >
> > > How would you map this using iBATIS? I've tried a variety of things
> > > without success and can't yet find any documentation that covers this
> > > situation. Thanks.
> >
> 
>

AW: Mapping Composition (aka composite property, aka value objects)

Posted by "Volker_Reichel@t-online.de" <vo...@t-online.de>.
If iBATIS is doing these steps

	Product product = new Product();
	product.getPrice().setAmount(amount);

the Product constructor has to create a Price instance as side-effect.
My question is: What do you do in case the Product does not need to have a
related Price instance for each Product?


Volker

-----Ursprüngliche Nachricht-----
Von: Dan Bradley [mailto:debradley@gmail.com]
Gesendet: Montag, 19. September 2005 22:11
An: lmeadors@apache.org
Cc: user-java@ibatis.apache.org
Betreff: Re: Mapping Composition (aka composite property, aka value
objects)


Of course, after being stuck on it for a while, I figured it out right
after I posted the question:

<typeAlias alias="product" type="com.foo.Product" />
<resultMap id="result" class="product">
		<result property="name" column="name" />
		<result property="description" column="description" />
		<result property="price.amount" column="amount" />
		<result property="price.currency" column="currency_code" />
	</resultMap>

It appears that the Product class must have a Price instance that is
initialized, not null. In other words it looks like iBATIS doesn't do:

Price price = new Price();
price.setAmount(amount);
Product product = new Product();
product.setPrice(price);

But instead does:

Product product = new Product();
product.getPrice().setAmount(amount);

Take this all with a grain of salt - I'm new to iBATIS!

On 9/19/05, Larry Meadors <la...@gmail.com> wrote:
> Can you explain more how the model is in Java, and in the database?
>
> Larry
>
>
> On 9/19/05, Dan Bradley <de...@gmail.com> wrote:
> > I have one entity, a Product, which holds a Price as a composed (not
> > related) entity. A Price is a numeric value and a currency code as a
> > String. Prices don't have a distinct identity in the database - they
> > are value objects, so this is not the more usual persistent entity to
> > persistent entity relationship mapping.
> >
> > How would you map this using iBATIS? I've tried a variety of things
> > without success and can't yet find any documentation that covers this
> > situation. Thanks.
>


Re: Mapping Composition (aka composite property, aka value objects)

Posted by Dan Bradley <de...@gmail.com>.
Of course, after being stuck on it for a while, I figured it out right
after I posted the question:

<typeAlias alias="product" type="com.foo.Product" />
<resultMap id="result" class="product">
		<result property="name" column="name" />
		<result property="description" column="description" />
		<result property="price.amount" column="amount" />
		<result property="price.currency" column="currency_code" />
	</resultMap>

It appears that the Product class must have a Price instance that is
initialized, not null. In other words it looks like iBATIS doesn't do:

Price price = new Price();
price.setAmount(amount);
Product product = new Product();
product.setPrice(price);

But instead does:

Product product = new Product();
product.getPrice().setAmount(amount);

Take this all with a grain of salt - I'm new to iBATIS!

On 9/19/05, Larry Meadors <la...@gmail.com> wrote:
> Can you explain more how the model is in Java, and in the database?
> 
> Larry
> 
> 
> On 9/19/05, Dan Bradley <de...@gmail.com> wrote:
> > I have one entity, a Product, which holds a Price as a composed (not
> > related) entity. A Price is a numeric value and a currency code as a
> > String. Prices don't have a distinct identity in the database - they
> > are value objects, so this is not the more usual persistent entity to
> > persistent entity relationship mapping.
> >
> > How would you map this using iBATIS? I've tried a variety of things
> > without success and can't yet find any documentation that covers this
> > situation. Thanks.
>

Re: Mapping Composition (aka composite property, aka value objects)

Posted by Larry Meadors <la...@gmail.com>.
Can you explain more how the model is in Java, and in the database?

Larry


On 9/19/05, Dan Bradley <de...@gmail.com> wrote:
> I have one entity, a Product, which holds a Price as a composed (not
> related) entity. A Price is a numeric value and a currency code as a
> String. Prices don't have a distinct identity in the database - they
> are value objects, so this is not the more usual persistent entity to
> persistent entity relationship mapping.
> 
> How would you map this using iBATIS? I've tried a variety of things
> without success and can't yet find any documentation that covers this
> situation. Thanks.