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:
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:
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.
> 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:
> 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:
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 : mybatis-user@googlegroups.com [mailto:mybatis-user@googlegroups.com] De la part de Guy Rouillier Envoyé : October-28-11 1:59 AM À : mybatis-user@googlegroups.com Objet : Re: Some objects with association not getting created
I tried a couple of settings in the config file to see if they would help:
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.
> 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:
> 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:
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.
On 11/5/2011 4:11 PM, Guy wrote:
> I've created an issue to track this problem. Reproducible test case > is attached to the issue:
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.
> 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; > }
> 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.
> On 11/5/2011 4:11 PM, Guy wrote: >> I've created an issue to track this problem. Reproducible test case >> is attached to the issue:
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
> > 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;
> > }
> > 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.
> > On 11/5/2011 4:11 PM, Guy wrote:
> >> I've created an issue to track this problem. Reproducible test case
> >> is attached to the issue: