Faulty data output - rows disappearing others are "just" the same

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Faulty data output - rows disappearing others are "just" the same

Nicolai Willems
Hey there.

On two occasions I have seen some unwanted behavior from MyBatis.

As seen below I have a bunch of code(don't know if its a complex
setup).
In my mapper I have two ID's and the association, when two rows has
the
same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
the association - they
somehow magically get to bee the same object, I should mention that
the ID's are completely different.
This causes some problems, because I have one more cycle of select-
>ResultHandling.

So to describe the scenario:
1. Select from DB
2. The map gets populated as results roll in
2.1. The map now contains many Queues with each of their own
statistics, except for the two
          rows where the statistics object contain exact the same
column values.
3. Select next set of statistics
4. Put the newly acquired data into the map

Then things go wrong -> in step 1.-2., Queue1 has data for the date A
matching Queue2's data for date B,
where B is later than A. This means that Queue1 and Queue2 now has the
same object assigned.
Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
for date B, where the two pieces of
data is different. The order returned from the DB is chronological and
therefore Queue1 at date A gets written first,
then Queue2's data for date B is reached and written, and the value
selected for date A on Queue1 is overwritten- yaicks.

I have done extensive debugging into the framework to see where things
go wrong, but must admit that the complexity of
MyBatis in general, statements, their handlers, executors and all
other sorts of stuff is overwhelming.

Please help me on this one, nothing makes sense anymore.

I will follow this post up with information on the other case.

Thanks in advance
Nicolai

======================================
=                                  CODE                             =
======================================

I have this mapper:
    <resultMap id="QueueFailureStatisticsMap"
type="IntermediateQueueStatistic">
        <id column="RefuseTime" property="time" javaType="Date" />
        <id column="QueueName" property="queueName" javaType="String" /
>
        <association property="qs" javaType="QueueStatistic" >
            <result column="Total" property="FailureTotal" />
            <result column="TotalBackup"
property="FailureTotalBackup" />
            <result column="TotalTerminate"
property="FailureTotalTerminate" />
            <result column="FullBackup" property="FailureFullBackup" /
>
            <result column="FullTerminate"
property="FailureFullTerminate" />
            <result column="UnmonitoredBackup"
property="FailureUnmonitoredBackup" />
            <result column="UnmonitoredTerminate"
property="FailureUnmonitoredTerminate" />
            <result column="ClosedBackup"
property="FailureClosedBackup" />
            <result column="ClosedTerminate"
property="FailureClosedTerminate" />
            <result column="ClientBackup"
property="FailureClientBackup" />
            <result column="ClientTerminate"
property="FailureClientTerminate" />
        </association>
    </resultMap>

Where IntermediateQueueStatistic is:

public interface QueueMapper {
    public class IntermediateQueueStatistics{
        public String queueName;
        public Date time;
        public QueueStatistic qs;
    }
... methods
}

When trying to get my data out of there I have the following
resulthandler:
    public void handleResult(ResultContext context) {
            QueueMapper.IntermediateQueueStatistics res =
 
(QueueMapper.IntermediateQueueStatistics)context.getResultObject();

            //Strip the date
            Date strippedDate =
Granularity.stripDateToGranularity(res.time, this.gran);
            Queue queue = this.queues.get(res.queueName);

            // Handling if the queue hasn't been added yet
            if(queue == null){
                queue = new Queue(res.queueName);
                this.queues.put(res.queueName, queue);
            }

            //Add the freshly fetched statistics
            queue.addSuccessStatistics(strippedDate, res.qs);
        }
Reply | Threaded
Open this post in threaded view
|

Re: Faulty data output - rows disappearing others are "just" the same

Nicolai Willems
I know this seems a lot of stuff to read - but essentially my problem
is that some rows accidentally when mapped get to be the same object.
I hope that I somehow can change this behavior, I just don't know how,
currently waiting for some MyBatis guru to come tell me.

I know I promised to follow up on the second case - but that as
lengthy as this one, and I remembered that I posted it before hand.
In essence - I have a resultset with Queue names and number of people
assigned to these queues - and somehow when ID'ing on the Queue name
the queues that have same number of people are removed so only the
first queue present in the resultset is presented.

Please help me out on this one - this seems so illogical.

On May 18, 9:48 am, Nicolai Willems <[hidden email]> wrote:

> Hey there.
>
> On two occasions I have seen some unwanted behavior from MyBatis.
>
> As seen below I have a bunch of code(don't know if its a complex
> setup).
> In my mapper I have two ID's and the association, when two rows has
> the
> same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
> the association - they
> somehow magically get to bee the same object, I should mention that
> the ID's are completely different.
> This causes some problems, because I have one more cycle of select-
>
> >ResultHandling.
>
> So to describe the scenario:
> 1. Select from DB
> 2. The map gets populated as results roll in
> 2.1. The map now contains many Queues with each of their own
> statistics, except for the two
>           rows where the statistics object contain exact the same
> column values.
> 3. Select next set of statistics
> 4. Put the newly acquired data into the map
>
> Then things go wrong -> in step 1.-2., Queue1 has data for the date A
> matching Queue2's data for date B,
> where B is later than A. This means that Queue1 and Queue2 now has the
> same object assigned.
> Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
> for date B, where the two pieces of
> data is different. The order returned from the DB is chronological and
> therefore Queue1 at date A gets written first,
> then Queue2's data for date B is reached and written, and the value
> selected for date A on Queue1 is overwritten- yaicks.
>
> I have done extensive debugging into the framework to see where things
> go wrong, but must admit that the complexity of
> MyBatis in general, statements, their handlers, executors and all
> other sorts of stuff is overwhelming.
>
> Please help me on this one, nothing makes sense anymore.
>
> I will follow this post up with information on the other case.
>
> Thanks in advance
> Nicolai
>
> ======================================
> =                                  CODE                             =
> ======================================
>
> I have this mapper:
>     <resultMap id="QueueFailureStatisticsMap"
> type="IntermediateQueueStatistic">
>         <id column="RefuseTime" property="time" javaType="Date" />
>         <id column="QueueName" property="queueName" javaType="String" /
>
>         <association property="qs" javaType="QueueStatistic" >
>             <result column="Total" property="FailureTotal" />
>             <result column="TotalBackup"
> property="FailureTotalBackup" />
>             <result column="TotalTerminate"
> property="FailureTotalTerminate" />
>             <result column="FullBackup" property="FailureFullBackup" /
>
>             <result column="FullTerminate"
> property="FailureFullTerminate" />
>             <result column="UnmonitoredBackup"
> property="FailureUnmonitoredBackup" />
>             <result column="UnmonitoredTerminate"
> property="FailureUnmonitoredTerminate" />
>             <result column="ClosedBackup"
> property="FailureClosedBackup" />
>             <result column="ClosedTerminate"
> property="FailureClosedTerminate" />
>             <result column="ClientBackup"
> property="FailureClientBackup" />
>             <result column="ClientTerminate"
> property="FailureClientTerminate" />
>         </association>
>     </resultMap>
>
> Where IntermediateQueueStatistic is:
>
> public interface QueueMapper {
>     public class IntermediateQueueStatistics{
>         public String queueName;
>         public Date time;
>         public QueueStatistic qs;
>     }
> ... methods
>
> }
>
> When trying to get my data out of there I have the following
> resulthandler:
>     public void handleResult(ResultContext context) {
>             QueueMapper.IntermediateQueueStatistics res =
>
> (QueueMapper.IntermediateQueueStatistics)context.getResultObject();
>
>             //Strip the date
>             Date strippedDate =
> Granularity.stripDateToGranularity(res.time, this.gran);
>             Queue queue = this.queues.get(res.queueName);
>
>             // Handling if the queue hasn't been added yet
>             if(queue == null){
>                 queue = new Queue(res.queueName);
>                 this.queues.put(res.queueName, queue);
>             }
>
>             //Add the freshly fetched statistics
>             queue.addSuccessStatistics(strippedDate, res.qs);
>         }
Reply | Threaded
Open this post in threaded view
|

Re: Faulty data output - rows disappearing others are "just" the same

Larry Meadors
You're using a row handler and associations? That seems like a pretty
complex case to me. What's your SQL look like?

Can you provide a simple test case the reproduce the behavior?

Larry


On Wed, May 18, 2011 at 2:01 PM, Nicolai Willems <[hidden email]> wrote:

> I know this seems a lot of stuff to read - but essentially my problem
> is that some rows accidentally when mapped get to be the same object.
> I hope that I somehow can change this behavior, I just don't know how,
> currently waiting for some MyBatis guru to come tell me.
>
> I know I promised to follow up on the second case - but that as
> lengthy as this one, and I remembered that I posted it before hand.
> In essence - I have a resultset with Queue names and number of people
> assigned to these queues - and somehow when ID'ing on the Queue name
> the queues that have same number of people are removed so only the
> first queue present in the resultset is presented.
>
> Please help me out on this one - this seems so illogical.
>
> On May 18, 9:48 am, Nicolai Willems <[hidden email]> wrote:
>> Hey there.
>>
>> On two occasions I have seen some unwanted behavior from MyBatis.
>>
>> As seen below I have a bunch of code(don't know if its a complex
>> setup).
>> In my mapper I have two ID's and the association, when two rows has
>> the
>> same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
>> the association - they
>> somehow magically get to bee the same object, I should mention that
>> the ID's are completely different.
>> This causes some problems, because I have one more cycle of select-
>>
>> >ResultHandling.
>>
>> So to describe the scenario:
>> 1. Select from DB
>> 2. The map gets populated as results roll in
>> 2.1. The map now contains many Queues with each of their own
>> statistics, except for the two
>>           rows where the statistics object contain exact the same
>> column values.
>> 3. Select next set of statistics
>> 4. Put the newly acquired data into the map
>>
>> Then things go wrong -> in step 1.-2., Queue1 has data for the date A
>> matching Queue2's data for date B,
>> where B is later than A. This means that Queue1 and Queue2 now has the
>> same object assigned.
>> Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
>> for date B, where the two pieces of
>> data is different. The order returned from the DB is chronological and
>> therefore Queue1 at date A gets written first,
>> then Queue2's data for date B is reached and written, and the value
>> selected for date A on Queue1 is overwritten- yaicks.
>>
>> I have done extensive debugging into the framework to see where things
>> go wrong, but must admit that the complexity of
>> MyBatis in general, statements, their handlers, executors and all
>> other sorts of stuff is overwhelming.
>>
>> Please help me on this one, nothing makes sense anymore.
>>
>> I will follow this post up with information on the other case.
>>
>> Thanks in advance
>> Nicolai
>>
>> ======================================
>> =                                  CODE                             =
>> ======================================
>>
>> I have this mapper:
>>     <resultMap id="QueueFailureStatisticsMap"
>> type="IntermediateQueueStatistic">
>>         <id column="RefuseTime" property="time" javaType="Date" />
>>         <id column="QueueName" property="queueName" javaType="String" /
>>
>>         <association property="qs" javaType="QueueStatistic" >
>>             <result column="Total" property="FailureTotal" />
>>             <result column="TotalBackup"
>> property="FailureTotalBackup" />
>>             <result column="TotalTerminate"
>> property="FailureTotalTerminate" />
>>             <result column="FullBackup" property="FailureFullBackup" /
>>
>>             <result column="FullTerminate"
>> property="FailureFullTerminate" />
>>             <result column="UnmonitoredBackup"
>> property="FailureUnmonitoredBackup" />
>>             <result column="UnmonitoredTerminate"
>> property="FailureUnmonitoredTerminate" />
>>             <result column="ClosedBackup"
>> property="FailureClosedBackup" />
>>             <result column="ClosedTerminate"
>> property="FailureClosedTerminate" />
>>             <result column="ClientBackup"
>> property="FailureClientBackup" />
>>             <result column="ClientTerminate"
>> property="FailureClientTerminate" />
>>         </association>
>>     </resultMap>
>>
>> Where IntermediateQueueStatistic is:
>>
>> public interface QueueMapper {
>>     public class IntermediateQueueStatistics{
>>         public String queueName;
>>         public Date time;
>>         public QueueStatistic qs;
>>     }
>> ... methods
>>
>> }
>>
>> When trying to get my data out of there I have the following
>> resulthandler:
>>     public void handleResult(ResultContext context) {
>>             QueueMapper.IntermediateQueueStatistics res =
>>
>> (QueueMapper.IntermediateQueueStatistics)context.getResultObject();
>>
>>             //Strip the date
>>             Date strippedDate =
>> Granularity.stripDateToGranularity(res.time, this.gran);
>>             Queue queue = this.queues.get(res.queueName);
>>
>>             // Handling if the queue hasn't been added yet
>>             if(queue == null){
>>                 queue = new Queue(res.queueName);
>>                 this.queues.put(res.queueName, queue);
>>             }
>>
>>             //Add the freshly fetched statistics
>>             queue.addSuccessStatistics(strippedDate, res.qs);
>>         }
Reply | Threaded
Open this post in threaded view
|

Re: Faulty data output - rows disappearing others are "just" the same

Nicolai Willems
Sorry the answer is coming so late.

In the first case a dataset looking like the following(Sorry for the
bad ASCII art)
I let TT be TotalTerminate
------------------------------------------------------------------------
| QueueName | Time                             | Total | ... | TT
| ... |
------------------------------------------------------------------------
....
------------------------------------------------------------------------
| queueA         | 2011-03-29 09:00:00 | 6        | 0  | 6    | 0 |
------------------------------------------------------------------------
....
------------------------------------------------------------------------
| queueB         | 2011-03-31 11:00:00 | 6        | 0  | 6    | 0 |
------------------------------------------------------------------------
....
------------------------------------------------------------------------

This renders two different IntermediateQueueStatistics-objects with
the same(Object.equals() = true) QueueStatistic object.

In the second case - the DB returns something similar to

-------------------------------
| QueueName | People |
-------------------------------
| QueueA        | 1           |
-------------------------------
| QueueB        | 2           |
-------------------------------
| QueueC        | 1           |
-------------------------------
| QueueD        | 2           |
-------------------------------
| QueueE        | 3           |
-------------------------------

My resulting list would contain 3 entries, one for QueueA, QueueB and
QueueE.
I provided some mappings in the post "To ID or not to ID", the
behavior seems to change dependent on whether I ID on QueueName or
not.

I hope this clears up some things, and why I'm confused. I really
appreciate the help on this one.

Regards
Nicolai

PS: To me it looks like MyBatis is using the object-pool design
pattern - I just don't know what to do about it.

On May 18, 10:51 pm, Larry Meadors <[hidden email]> wrote:

> You're using a row handler and associations? That seems like a pretty
> complex case to me. What's your SQL look like?
>
> Can you provide a simple test case the reproduce the behavior?
>
> Larry
>
>
>
> On Wed, May 18, 2011 at 2:01 PM, Nicolai Willems <[hidden email]> wrote:
> > I know this seems a lot of stuff to read - but essentially my problem
> > is that some rows accidentally when mapped get to be the same object.
> > I hope that I somehow can change this behavior, I just don't know how,
> > currently waiting for some MyBatis guru to come tell me.
>
> > I know I promised to follow up on the second case - but that as
> > lengthy as this one, and I remembered that I posted it before hand.
> > In essence - I have a resultset with Queue names and number of people
> > assigned to these queues - and somehow when ID'ing on the Queue name
> > the queues that have same number of people are removed so only the
> > first queue present in the resultset is presented.
>
> > Please help me out on this one - this seems so illogical.
>
> > On May 18, 9:48 am, Nicolai Willems <[hidden email]> wrote:
> >> Hey there.
>
> >> On two occasions I have seen some unwanted behavior from MyBatis.
>
> >> As seen below I have a bunch of code(don't know if its a complex
> >> setup).
> >> In my mapper I have two ID's and the association, when two rows has
> >> the
> >> same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
> >> the association - they
> >> somehow magically get to bee the same object, I should mention that
> >> the ID's are completely different.
> >> This causes some problems, because I have one more cycle of select-
>
> >> >ResultHandling.
>
> >> So to describe the scenario:
> >> 1. Select from DB
> >> 2. The map gets populated as results roll in
> >> 2.1. The map now contains many Queues with each of their own
> >> statistics, except for the two
> >>           rows where the statistics object contain exact the same
> >> column values.
> >> 3. Select next set of statistics
> >> 4. Put the newly acquired data into the map
>
> >> Then things go wrong -> in step 1.-2., Queue1 has data for the date A
> >> matching Queue2's data for date B,
> >> where B is later than A. This means that Queue1 and Queue2 now has the
> >> same object assigned.
> >> Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
> >> for date B, where the two pieces of
> >> data is different. The order returned from the DB is chronological and
> >> therefore Queue1 at date A gets written first,
> >> then Queue2's data for date B is reached and written, and the value
> >> selected for date A on Queue1 is overwritten- yaicks.
>
> >> I have done extensive debugging into the framework to see where things
> >> go wrong, but must admit that the complexity of
> >> MyBatis in general, statements, their handlers, executors and all
> >> other sorts of stuff is overwhelming.
>
> >> Please help me on this one, nothing makes sense anymore.
>
> >> I will follow this post up with information on the other case.
>
> >> Thanks in advance
> >> Nicolai
>
> >> ======================================
> >> =                                  CODE                             =
> >> ======================================
>
> >> I have this mapper:
> >>     <resultMap id="QueueFailureStatisticsMap"
> >> type="IntermediateQueueStatistic">
> >>         <id column="RefuseTime" property="time" javaType="Date" />
> >>         <id column="QueueName" property="queueName" javaType="String" /
>
> >>         <association property="qs" javaType="QueueStatistic" >
> >>             <result column="Total" property="FailureTotal" />
> >>             <result column="TotalBackup"
> >> property="FailureTotalBackup" />
> >>             <result column="TotalTerminate"
> >> property="FailureTotalTerminate" />
> >>             <result column="FullBackup" property="FailureFullBackup" /
>
> >>             <result column="FullTerminate"
> >> property="FailureFullTerminate" />
> >>             <result column="UnmonitoredBackup"
> >> property="FailureUnmonitoredBackup" />
> >>             <result column="UnmonitoredTerminate"
> >> property="FailureUnmonitoredTerminate" />
> >>             <result column="ClosedBackup"
> >> property="FailureClosedBackup" />
> >>             <result column="ClosedTerminate"
> >> property="FailureClosedTerminate" />
> >>             <result column="ClientBackup"
> >> property="FailureClientBackup" />
> >>             <result column="ClientTerminate"
> >> property="FailureClientTerminate" />
> >>         </association>
> >>     </resultMap>
>
> >> Where IntermediateQueueStatistic is:
>
> >> public interface QueueMapper {
> >>     public class IntermediateQueueStatistics{
> >>         public String queueName;
> >>         public Date time;
> >>         public QueueStatistic qs;
> >>     }
> >> ... methods
>
> >> }
>
> >> When trying to get my data out of there I have the following
> >> resulthandler:
> >>     public void handleResult(ResultContext context) {
> >>             QueueMapper.IntermediateQueueStatistics res =
>
> >> (QueueMapper.IntermediateQueueStatistics)context.getResultObject();
>
> >>             //Strip the date
> >>             Date strippedDate =
> >> Granularity.stripDateToGranularity(res.time, this.gran);
> >>             Queue queue = this.queues.get(res.queueName);
>
> >>             // Handling if the queue hasn't been added yet
> >>             if(queue == null){
> >>                 queue = new Queue(res.queueName);
> >>                 this.queues.put(res.queueName, queue);
> >>             }
>
> >>             //Add the freshly fetched statistics
> >>             queue.addSuccessStatistics(strippedDate, res.qs);
> >>         }
Reply | Threaded
Open this post in threaded view
|

Re: Faulty data output - rows disappearing others are "just" the same

Nicolai Willems
Does this make any sense? Or am I way out?

/Nicolai Willems

On May 22, 1:10 am, Nicolai Willems <[hidden email]> wrote:

> Sorry the answer is coming so late.
>
> In the first case a dataset looking like the following(Sorry for the
> bad ASCII art)
> I let TT be TotalTerminate
> ------------------------------------------------------------------------
> | QueueName | Time                             | Total | ... | TT
> | ... |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
> | queueA         | 2011-03-29 09:00:00 | 6        | 0  | 6    | 0 |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
> | queueB         | 2011-03-31 11:00:00 | 6        | 0  | 6    | 0 |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
>
> This renders two different IntermediateQueueStatistics-objects with
> the same(Object.equals() = true) QueueStatistic object.
>
> In the second case - the DB returns something similar to
>
> -------------------------------
> | QueueName | People |
> -------------------------------
> | QueueA        | 1           |
> -------------------------------
> | QueueB        | 2           |
> -------------------------------
> | QueueC        | 1           |
> -------------------------------
> | QueueD        | 2           |
> -------------------------------
> | QueueE        | 3           |
> -------------------------------
>
> My resulting list would contain 3 entries, one for QueueA, QueueB and
> QueueE.
> I provided some mappings in the post "To ID or not to ID", the
> behavior seems to change dependent on whether I ID on QueueName or
> not.
>
> I hope this clears up some things, and why I'm confused. I really
> appreciate the help on this one.
>
> Regards
> Nicolai
>
> PS: To me it looks like MyBatis is using the object-pool design
> pattern - I just don't know what to do about it.
>
> On May 18, 10:51 pm, Larry Meadors <[hidden email]> wrote:
>
>
>
>
>
>
>
> > You're using a row handler and associations? That seems like a pretty
> > complex case to me. What's your SQL look like?
>
> > Can you provide a simple test case the reproduce the behavior?
>
> > Larry
>
> > On Wed, May 18, 2011 at 2:01 PM, Nicolai Willems <[hidden email]> wrote:
> > > I know this seems a lot of stuff to read - but essentially my problem
> > > is that some rows accidentally when mapped get to be the same object.
> > > I hope that I somehow can change this behavior, I just don't know how,
> > > currently waiting for some MyBatis guru to come tell me.
>
> > > I know I promised to follow up on the second case - but that as
> > > lengthy as this one, and I remembered that I posted it before hand.
> > > In essence - I have a resultset with Queue names and number of people
> > > assigned to these queues - and somehow when ID'ing on the Queue name
> > > the queues that have same number of people are removed so only the
> > > first queue present in the resultset is presented.
>
> > > Please help me out on this one - this seems so illogical.
>
> > > On May 18, 9:48 am, Nicolai Willems <[hidden email]> wrote:
> > >> Hey there.
>
> > >> On two occasions I have seen some unwanted behavior from MyBatis.
>
> > >> As seen below I have a bunch of code(don't know if its a complex
> > >> setup).
> > >> In my mapper I have two ID's and the association, when two rows has
> > >> the
> > >> same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
> > >> the association - they
> > >> somehow magically get to bee the same object, I should mention that
> > >> the ID's are completely different.
> > >> This causes some problems, because I have one more cycle of select-
>
> > >> >ResultHandling.
>
> > >> So to describe the scenario:
> > >> 1. Select from DB
> > >> 2. The map gets populated as results roll in
> > >> 2.1. The map now contains many Queues with each of their own
> > >> statistics, except for the two
> > >>           rows where the statistics object contain exact the same
> > >> column values.
> > >> 3. Select next set of statistics
> > >> 4. Put the newly acquired data into the map
>
> > >> Then things go wrong -> in step 1.-2., Queue1 has data for the date A
> > >> matching Queue2's data for date B,
> > >> where B is later than A. This means that Queue1 and Queue2 now has the
> > >> same object assigned.
> > >> Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
> > >> for date B, where the two pieces of
> > >> data is different. The order returned from the DB is chronological and
> > >> therefore Queue1 at date A gets written first,
> > >> then Queue2's data for date B is reached and written, and the value
> > >> selected for date A on Queue1 is overwritten- yaicks.
>
> > >> I have done extensive debugging into the framework to see where things
> > >> go wrong, but must admit that the complexity of
> > >> MyBatis in general, statements, their handlers, executors and all
> > >> other sorts of stuff is overwhelming.
>
> > >> Please help me on this one, nothing makes sense anymore.
>
> > >> I will follow this post up with information on the other case.
>
> > >> Thanks in advance
> > >> Nicolai
>
> > >> ======================================
> > >> =                                  CODE                             =
> > >> ======================================
>
> > >> I have this mapper:
> > >>     <resultMap id="QueueFailureStatisticsMap"
> > >> type="IntermediateQueueStatistic">
> > >>         <id column="RefuseTime" property="time" javaType="Date" />
> > >>         <id column="QueueName" property="queueName" javaType="String" /
>
> > >>         <association property="qs" javaType="QueueStatistic" >
> > >>             <result column="Total" property="FailureTotal" />
> > >>             <result column="TotalBackup"
> > >> property="FailureTotalBackup" />
> > >>             <result column="TotalTerminate"
> > >> property="FailureTotalTerminate" />
> > >>             <result column="FullBackup" property="FailureFullBackup" /
>
> > >>             <result column="FullTerminate"
> > >> property="FailureFullTerminate" />
> > >>             <result column="UnmonitoredBackup"
> > >> property="FailureUnmonitoredBackup" />
> > >>             <result column="UnmonitoredTerminate"
> > >> property="FailureUnmonitoredTerminate" />
> > >>             <result column="ClosedBackup"
> > >> property="FailureClosedBackup" />
> > >>             <result column="ClosedTerminate"
> > >> property="FailureClosedTerminate" />
> > >>             <result column="ClientBackup"
> > >> property="FailureClientBackup" />
> > >>             <result column="ClientTerminate"
> > >> property="FailureClientTerminate" />
> > >>         </association>
> > >>     </resultMap>
>
> > >> Where IntermediateQueueStatistic is:
>
> > >> public interface QueueMapper {
> > >>     public class IntermediateQueueStatistics{
> > >>         public String queueName;
> > >>         public Date time;
> > >>         public QueueStatistic qs;
> > >>     }
> > >> ... methods
>
> > >> }
>
> > >> When trying to get my data out of there I have the following
> > >> resulthandler:
> > >>     public void handleResult(ResultContext context) {
> > >>             QueueMapper.IntermediateQueueStatistics res =
>
> > >> (QueueMapper.IntermediateQueueStatistics)context.getResultObject();
>
> > >>             //Strip the date
> > >>             Date strippedDate =
> > >> Granularity.stripDateToGranularity(res.time, this.gran);
> > >>             Queue queue = this.queues.get(res.queueName);
>
> > >>             // Handling if the queue hasn't been added yet
> > >>             if(queue == null){
> > >>                 queue = new Queue(res.queueName);
> > >>                 this.queues.put(res.queueName, queue);
> > >>             }
>
> > >>             //Add the freshly fetched statistics
> > >>             queue.addSuccessStatistics(strippedDate, res.qs);
> > >>         }
Reply | Threaded
Open this post in threaded view
|

Re: Faulty data output - rows disappearing others are "just" the same

Nicolai Willems
In reply to this post by Nicolai Willems
I think I found a solution to this issue.
When adding the object - as seen on the last line of my resulthandler
- in that method, to clone the stat object so that my queue object has
a "private" clone.
That should solve the issue on the short run - in the long run, I
would really like to know why MyBatis behaves like this.

Thanks for the attention - hope this answer can help some one out
there.

On May 22, 1:10 am, Nicolai Willems <[hidden email]> wrote:

> Sorry the answer is coming so late.
>
> In the first case a dataset looking like the following(Sorry for the
> bad ASCII art)
> I let TT be TotalTerminate
> ------------------------------------------------------------------------
> | QueueName | Time                             | Total | ... | TT
> | ... |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
> | queueA         | 2011-03-29 09:00:00 | 6        | 0  | 6    | 0 |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
> | queueB         | 2011-03-31 11:00:00 | 6        | 0  | 6    | 0 |
> ------------------------------------------------------------------------
> ....
> ------------------------------------------------------------------------
>
> This renders two different IntermediateQueueStatistics-objects with
> the same(Object.equals() = true) QueueStatistic object.
>
> In the second case - the DB returns something similar to
>
> -------------------------------
> | QueueName | People |
> -------------------------------
> | QueueA        | 1           |
> -------------------------------
> | QueueB        | 2           |
> -------------------------------
> | QueueC        | 1           |
> -------------------------------
> | QueueD        | 2           |
> -------------------------------
> | QueueE        | 3           |
> -------------------------------
>
> My resulting list would contain 3 entries, one for QueueA, QueueB and
> QueueE.
> I provided some mappings in the post "To ID or not to ID", the
> behavior seems to change dependent on whether I ID on QueueName or
> not.
>
> I hope this clears up some things, and why I'm confused. I really
> appreciate the help on this one.
>
> Regards
> Nicolai
>
> PS: To me it looks like MyBatis is using the object-pool design
> pattern - I just don't know what to do about it.
>
> On May 18, 10:51 pm, Larry Meadors <[hidden email]> wrote:
>
>
>
>
>
>
>
> > You're using a row handler and associations? That seems like a pretty
> > complex case to me. What's your SQL look like?
>
> > Can you provide a simple test case the reproduce the behavior?
>
> > Larry
>
> > On Wed, May 18, 2011 at 2:01 PM, Nicolai Willems <[hidden email]> wrote:
> > > I know this seems a lot of stuff to read - but essentially my problem
> > > is that some rows accidentally when mapped get to be the same object.
> > > I hope that I somehow can change this behavior, I just don't know how,
> > > currently waiting for some MyBatis guru to come tell me.
>
> > > I know I promised to follow up on the second case - but that as
> > > lengthy as this one, and I remembered that I posted it before hand.
> > > In essence - I have a resultset with Queue names and number of people
> > > assigned to these queues - and somehow when ID'ing on the Queue name
> > > the queues that have same number of people are removed so only the
> > > first queue present in the resultset is presented.
>
> > > Please help me out on this one - this seems so illogical.
>
> > > On May 18, 9:48 am, Nicolai Willems <[hidden email]> wrote:
> > >> Hey there.
>
> > >> On two occasions I have seen some unwanted behavior from MyBatis.
>
> > >> As seen below I have a bunch of code(don't know if its a complex
> > >> setup).
> > >> In my mapper I have two ID's and the association, when two rows has
> > >> the
> > >> same values in all fields(Total, TotalBackup, ..., ClientTerminate) in
> > >> the association - they
> > >> somehow magically get to bee the same object, I should mention that
> > >> the ID's are completely different.
> > >> This causes some problems, because I have one more cycle of select-
>
> > >> >ResultHandling.
>
> > >> So to describe the scenario:
> > >> 1. Select from DB
> > >> 2. The map gets populated as results roll in
> > >> 2.1. The map now contains many Queues with each of their own
> > >> statistics, except for the two
> > >>           rows where the statistics object contain exact the same
> > >> column values.
> > >> 3. Select next set of statistics
> > >> 4. Put the newly acquired data into the map
>
> > >> Then things go wrong -> in step 1.-2., Queue1 has data for the date A
> > >> matching Queue2's data for date B,
> > >> where B is later than A. This means that Queue1 and Queue2 now has the
> > >> same object assigned.
> > >> Then in step 3.-4., Queue1 has data for date A, and Queue2 has data
> > >> for date B, where the two pieces of
> > >> data is different. The order returned from the DB is chronological and
> > >> therefore Queue1 at date A gets written first,
> > >> then Queue2's data for date B is reached and written, and the value
> > >> selected for date A on Queue1 is overwritten- yaicks.
>
> > >> I have done extensive debugging into the framework to see where things
> > >> go wrong, but must admit that the complexity of
> > >> MyBatis in general, statements, their handlers, executors and all
> > >> other sorts of stuff is overwhelming.
>
> > >> Please help me on this one, nothing makes sense anymore.
>
> > >> I will follow this post up with information on the other case.
>
> > >> Thanks in advance
> > >> Nicolai
>
> > >> ======================================
> > >> =                                  CODE                             =
> > >> ======================================
>
> > >> I have this mapper:
> > >>     <resultMap id="QueueFailureStatisticsMap"
> > >> type="IntermediateQueueStatistic">
> > >>         <id column="RefuseTime" property="time" javaType="Date" />
> > >>         <id column="QueueName" property="queueName" javaType="String" /
>
> > >>         <association property="qs" javaType="QueueStatistic" >
> > >>             <result column="Total" property="FailureTotal" />
> > >>             <result column="TotalBackup"
> > >> property="FailureTotalBackup" />
> > >>             <result column="TotalTerminate"
> > >> property="FailureTotalTerminate" />
> > >>             <result column="FullBackup" property="FailureFullBackup" /
>
> > >>             <result column="FullTerminate"
> > >> property="FailureFullTerminate" />
> > >>             <result column="UnmonitoredBackup"
> > >> property="FailureUnmonitoredBackup" />
> > >>             <result column="UnmonitoredTerminate"
> > >> property="FailureUnmonitoredTerminate" />
> > >>             <result column="ClosedBackup"
> > >> property="FailureClosedBackup" />
> > >>             <result column="ClosedTerminate"
> > >> property="FailureClosedTerminate" />
> > >>             <result column="ClientBackup"
> > >> property="FailureClientBackup" />
> > >>             <result column="ClientTerminate"
> > >> property="FailureClientTerminate" />
> > >>         </association>
> > >>     </resultMap>
>
> > >> Where IntermediateQueueStatistic is:
>
> > >> public interface QueueMapper {
> > >>     public class IntermediateQueueStatistics{
> > >>         public String queueName;
> > >>         public Date time;
> > >>         public QueueStatistic qs;
> > >>     }
> > >> ... methods
>
> > >> }
>
> > >> When trying to get my data out of there I have the following
> > >> resulthandler:
> > >>     public void handleResult(ResultContext context) {
> > >>             QueueMapper.IntermediateQueueStatistics res =
>
> > >> (QueueMapper.IntermediateQueueStatistics)context.getResultObject();
>
> > >>             //Strip the date
> > >>             Date strippedDate =
> > >> Granularity.stripDateToGranularity(res.time, this.gran);
> > >>             Queue queue = this.queues.get(res.queueName);
>
> > >>             // Handling if the queue hasn't been added yet
> > >>             if(queue == null){
> > >>                 queue = new Queue(res.queueName);
> > >>                 this.queues.put(res.queueName, queue);
> > >>             }
>
> > >>             //Add the freshly fetched statistics
> > >>             queue.addSuccessStatistics(strippedDate, res.qs);
> > >>         }