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 Collin Peters <ca...@gmail.com> on 2007/03/02 21:10:32 UTC
Syntax for getter variables in a POJO
I am trying to figure out the magical syntax for POJO's in
getter/setters. I have a database column called product_id, another
called p_sequence. What do these map to in a POJO getter/setter?
Seems the underscore causes some problems. I have had to do some
aliases to make them work (i.e. productid, psequence)
Collin
Re: Syntax for getter variables in a POJO
Posted by Clinton Begin <cl...@gmail.com>.
+1. Yep, you can either use column aliases or a result map.
On 3/2/07, Ted Schrader <te...@gmail.com> wrote:
>
> Hi Collin,
>
> So setProduct_id() and setP_sequence() wouldn't work?
>
> Regardless, if I understand the recommeneded iBATIS way of doing
> things, your situation would be an excellent case for using
> <resultMap>, perhaps something like:
>
> <resultMap id="productResult" class="mypackage.Product">
> <result column="product_id" property="id" />
> <result column="p_sequence" property="sequence" />
> </resultMap>
>
> <select id="products" resultMap="productResult" >
> SELECT product_id, p_sequence
> FROM Products
> </select>
>
> The <resultMap> expects setId() and setSequence() setters on the
> Product class. It's a great way to keep database column names from
> dictating method names on the Java side of things.
>
> Ted
>
> > -----Original Message-----
> > From: Collin Peters [mailto:cadiolis@gmail.com]
> > Sent: Friday, March 02, 2007 12:11 PM
> > To: user-java@ibatis.apache.org
> > Subject: Syntax for getter variables in a POJO
> >
> > I am trying to figure out the magical syntax for POJO's in
> > getter/setters. I have a database column called product_id, another
> > called p_sequence. What do these map to in a POJO getter/setter?
> > Seems the underscore causes some problems. I have had to do some
> > aliases to make them work (i.e. productid, psequence)
> >
> > Collin
>
Re: Syntax for getter variables in a POJO
Posted by Ted Schrader <te...@gmail.com>.
Hi Collin,
So setProduct_id() and setP_sequence() wouldn't work?
Regardless, if I understand the recommeneded iBATIS way of doing
things, your situation would be an excellent case for using
<resultMap>, perhaps something like:
<resultMap id="productResult" class="mypackage.Product">
<result column="product_id" property="id" />
<result column="p_sequence" property="sequence" />
</resultMap>
<select id="products" resultMap="productResult" >
SELECT product_id, p_sequence
FROM Products
</select>
The <resultMap> expects setId() and setSequence() setters on the
Product class. It's a great way to keep database column names from
dictating method names on the Java side of things.
Ted
> -----Original Message-----
> From: Collin Peters [mailto:cadiolis@gmail.com]
> Sent: Friday, March 02, 2007 12:11 PM
> To: user-java@ibatis.apache.org
> Subject: Syntax for getter variables in a POJO
>
> I am trying to figure out the magical syntax for POJO's in
> getter/setters. I have a database column called product_id, another
> called p_sequence. What do these map to in a POJO getter/setter?
> Seems the underscore causes some problems. I have had to do some
> aliases to make them work (i.e. productid, psequence)
>
> Collin
RE: Syntax for getter variables in a POJO
Posted by "Armeanu, Christian" <Ar...@hsd.k12.or.us>.
These should map respectively to pSequence and productId.
Chris
-----Original Message-----
From: Collin Peters [mailto:cadiolis@gmail.com]
Sent: Friday, March 02, 2007 12:11 PM
To: user-java@ibatis.apache.org
Subject: Syntax for getter variables in a POJO
I am trying to figure out the magical syntax for POJO's in
getter/setters. I have a database column called product_id, another
called p_sequence. What do these map to in a POJO getter/setter?
Seems the underscore causes some problems. I have had to do some
aliases to make them work (i.e. productid, psequence)
Collin