Some objects with association not getting created

35 views
Skip to first unread message

Guy Rouillier

unread,
Oct 27, 2011, 3:12:54 AM10/27/11
to mybati...@googlegroups.com
I'm facing a really bizarre problem with a result set containing
associations. When I turn on log4j debugging, I can see all my data
rows being returned. But if I look at the log of objects created, one
or two of them are not being created. And the ones missing are not
always the same.

Here is my result map. I tried several variations, one using a
constructor within the association, and this one. Both of them
encounter the same problem:

<resultMap id="hubStatsMap"
type="com.masergy.lsp.db.bean.HubPairValue">
<result column="DATESTAMP" property="sampleDate" jdbcType="VARCHAR" />
<result column="COUNT" property="value" jdbcType="INTEGER" />
<association property="sourceHub" javaType="db.bean.Hub">
<result column="HUB" property="abbr" jdbcType="VARCHAR"
javaType="String"/>
<result column="HUB" property="label" jdbcType="VARCHAR"
javaType="String"/>
</association>
<association property="destinationHub" javaType="db.bean.Hub">
<result column="FAR_HUB" property="abbr" jdbcType="VARCHAR"
javaType="String"/>
<result column="FAR_HUB" property="label" jdbcType="VARCHAR"
javaType="String"/>
</association>
</resultMap>

Here is a sample of my retrieved data; no object was created for the row
SNGP, NWRK. I don't see anything unique about that data that would
cause a problem:

Row: SNGP, LONI, 2011-10-27 06:25:00, 13544
Row: SNGP, MIAS, 2011-10-27 06:25:00, 13095
Row: SNGP, NWRK, 2011-10-27 06:25:00, 208 <== no object created
Row: SNGP, NYCM, 2011-10-27 06:25:00, 30355
Row: SNGP, PARC, 2011-10-27 06:25:00, 1341

If I comment out the associations, all the objects get created. Any
idea what could be causing this problem?

Thanks.

--
Guy Rouillier

Guy Rouillier

unread,
Oct 28, 2011, 1:58:59 AM10/28/11
to mybati...@googlegroups.com
I tried a couple of settings in the config file to see if they would help:

<settings>
<setting name="lazyLoadingEnabled" value="false"/>
<setting name="aggressiveLazyLoading" value="false"/>
</settings>

Unfortunately, I still have the same problem, with both or either one of
the above settings enabled. This is the first I'm aware that
associations have this problem. We use them widely; hopefully they are
not causing hidden problems elsewhere.

Appreciate any ideas on getting this to work. Thanks.

Poitras Christian

unread,
Oct 28, 2011, 8:23:40 AM10/28/11
to mybati...@googlegroups.com
That a very good question.

Maybe the problem is linked to issue 417.
Another possibility is that the Executor's connection is closed and the Executor is unable to get a new connection and fails silently.

But I think these cases would throw an exception instead of failing silently.

Christian

-----Message d'origine-----
De : mybati...@googlegroups.com [mailto:mybati...@googlegroups.com] De la part de Guy Rouillier
Envoyé : October-28-11 1:59 AM
À : mybati...@googlegroups.com
Objet : Re: Some objects with association not getting created

Guy

unread,
Nov 5, 2011, 4:11:40 PM11/5/11
to mybatis-user
I've created an issue to track this problem. Reproducible test case
is attached to the issue:

http://code.google.com/p/mybatis/issues/detail?id=433

Guy Rouillier

unread,
Nov 6, 2011, 1:09:50 AM11/6/11
to mybati...@googlegroups.com
I've made some progress in isolating this problem. I think it may be
related to http://code.google.com/p/mybatis/issues/detail?id=263. The
sample I attached to the issue is a command-line program, though the
real app is a web app.

I don't want to get into the extreme details present in the sample
attached to the issue I opened, but the object type I'm trying to
instantiate looks like this:

public class PairValue {
private Date sampleDate = null;
private double value = 0;
}

public class HubPairValue extends PairValue {
private Hub sourceHub = null;
private Hub destinationHub = null;
}

What is happening is that when the association creates a HubPairValue
using a constructor, that in turn creates a PairValue. For the objects
that are not created, the sampleDate and value fields contain the same
values as a previous row, *even though* that row is for a different
combination of sourceHub and destinationHub. That is causing the
PairValue object to not be created; and since the PairValue object is
not created, neither is HubPairValue.

I notice that (some of the) Hub objects that have been previously
created are also not created the next time the same hub appears in a
different row. So apparently MyBatis is doing some kind of optimization
and not creating objects that it thinks already exist. I tried turning
off the global cache, and also on the select statement specifying
useCache="false", but the outcome did not change.

This is a pretty basic problem; I'm surprised it hasn't surfaced already.


--
Guy Rouillier

Guy Rouillier

unread,
Nov 6, 2011, 1:15:45 AM11/6/11
to mybati...@googlegroups.com
Sorry, I'm tired, the first paragraph after the code snippet should read:

What is happening is that when the ResultMap creates a HubPairValue,

that in turn creates a PairValue. For the objects that are not created,
the sampleDate and value fields contain the same values as a previous
row, *even though* that row is for a different combination of sourceHub
and destinationHub. That is causing the PairValue object to not be
created; and since the PairValue object is not created, neither is
HubPairValue.

I don't know why commenting out the associations (which use constructors
to create sourceHub and destinationHub) results in all objects being
created.

Guy

unread,
Nov 6, 2011, 2:14:26 AM11/6/11
to mybatis-user
I've found a workaround. I got rid of the associations completely,
and added a TypeHandler for constructing the Hub object. That allowed
me to change the resultMap for hubStatsMap to a simple set of four
column mappings, each of which is an "id" type. Since all 4 are ids,
MyBatis requires each instance to be unique and is now no longer
discarding objects.

I would like to understand why this couldn't be done with
associations. I guess that would require identifying the association
as being an "id" type, which isn't possible.

On Nov 6, 12:15 am, Guy Rouillier <g...@burntmail.com> wrote:
> Sorry, I'm tired, the first paragraph after the code snippet should read:
>
> What is happening is that when the ResultMap creates a HubPairValue,
> that in turn creates a PairValue.  For the objects that are not created,
> the sampleDate and value fields contain the same values as a previous
> row, *even though* that row is for a different combination of sourceHub
> and destinationHub.  That is causing the PairValue object to not be
> created; and since the PairValue object is not created, neither is
> HubPairValue.
>
> I don't know why commenting out the associations (which use constructors
> to create sourceHub and destinationHub) results in all objects being
> created.
>
> On 11/6/2011 1:09 AM, Guy Rouillier wrote:
>
>
>
>
>
>
>
>
>
> > I've made some progress in isolating this problem. I think it may be
> > related tohttp://code.google.com/p/mybatis/issues/detail?id=263. The
Reply all
Reply to author
Forward
0 new messages