Let me see if I got this. In your example of flights and reservations using
both constraints and IBATSI, you are talking about using one or the other,
correct?

And if you are using caches, you should flush the statements referring to
the reservations when the flight is deleted?

Also, Is there a way to delete the flight and reservations via the same type
of mechanism used to select a flight and its reservations? Could you replace
the SELECT with DELETE?

   <resultMap id="flightWithReservatonsResult" class="flight">
    <result property="pKey" column="flt_pk" javaType="int"
jdbcType="INTEGER"/>
    ...
    <result property="reservationsList" column="flt_pk"
select="getReservations"/>
   </resultMap>

  <resultMap id="reservationsResult" class="reservation">
    <result property="pKey" column="rsv_pk" javaType="int"
jdbcType="INTEGER"/>
    <result property="flightFKey" column="rsv_flt_fk" javaType="int"
jdbcType="INTEGER"/>
    ...
  </resultMap>

  <select id="getFlightWithReservatons" parameterClass="flight"
resultMap="flightWithReservatonsResult">
        SELECT * FROM flights WHERE flt_pk = #pKey#
  </select>

  <select id="getReservations" parameterClass="java.lang.Integer"
resultMap="reservationsResult">
        SELECT * FROM reservations WHERE rsv_flt_fk = #value#
  </select>


> Like most answers this really depends on a lot of different factors.
>
> For data integrity I prefer to use a database constraint.
>
> Where is gets a little complicated is if you are using caching inside
> of ibatis.
>
> A simple example might be a airline flight with many reservations.
>
> If you have different caches for both the flights table and the
> reservations table you could run into problems with relying on the DB
> constraint.  If you only told the flights cache to clear then you
> would have bad data in your reservations cache.  iBatis does allow
> for you to have the reservations cache to clear when a change is made
> to the flights cache.  I guess I defeated my own argument :)
>
> I guess I don't really see a problem with using both.  You never know
> when you will create a second or third client to connect to the same
> DB so the constraint should be use.  But to keep the application and
> the DB loosely coupled I would also code this into the service layer
> of my app.
>
> Hope this helps,
> Nathan
>
> On Dec 21, 2005, at 2:45 PM, Warren Bell wrote:
>
> > I have an object with a list. I want to delete the items in the
> > list and the
> > object too. Is it better to let a foreign key do this in the
> > database or
> > have IBATIS do it? If IBATIS, should I run two deletes for the
> > object and
> > items, or does Ibatis have a better way?
> >
> > Thanks,
> >
> > Warren Bell
> > Systems Administrator
> > Clark's Nutritional Centers
> > 4225 Market St.
> > Riverside, CA 92501
> > 951-321-1960 ext. 142
> > 909-645-8864 mobile
> >
>
> __________ NOD32 1.1332 (20051221) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>

Reply via email to