Conceptual Question regarding Associations and Fast Insert ..

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

Conceptual Question regarding Associations and Fast Insert ..

Daniel Stieger
Hi,

i m looking for a hint regarding a conceptual decision in a mybatis
application. Basically i have an entity Car and an entity Radio. Both
have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
will Map Car and Radio in mybatis and use an <association ....
select="radioSelect"> in the Car result map. This will load the Radio
object lazy if it is accessed with myCar.getRadio().


But another usecase is that i have a Car object myCar where the Radio
entity is not loaded. I simply want to make a copy of that car with an
insert statement, but i do not want to load the Radio object due to
performance issues. The radio id should be already available in
myCar.... but how can i access that id without touching
myCar.getRadio() .. which will load the whole Radio Object ...

Any hint appreciated,
Daniel
Reply | Threaded
Open this post in threaded view
|

Re: Conceptual Question regarding Associations and Fast Insert ..

Clinton Begin
Administrator
There's no way of stopping that... touch the getter, the object will load.  

One approach would be to keep another field for just the ID, and map it a second time.  But that's not pretty if this is a common case.

Clinton

On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger <[hidden email]> wrote:
Hi,

i m looking for a hint regarding a conceptual decision in a mybatis
application. Basically i have an entity Car and an entity Radio. Both
have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
will Map Car and Radio in mybatis and use an <association ....
select="radioSelect"> in the Car result map. This will load the Radio
object lazy if it is accessed with myCar.getRadio().


But another usecase is that i have a Car object myCar where the Radio
entity is not loaded. I simply want to make a copy of that car with an
insert statement, but i do not want to load the Radio object due to
performance issues. The radio id should be already available in
myCar.... but how can i access that id without touching
myCar.getRadio() .. which will load the whole Radio Object ...

Any hint appreciated,
Daniel

Reply | Threaded
Open this post in threaded view
|

Re: Conceptual Question regarding Associations and Fast Insert ..

Shanhong Cheng
is there a way to access a method of a parameter object in xml file? 
like this: 
#{parameterObject.methodName()}

On Wed, Jun 29, 2011 at 3:50 PM, Clinton Begin <[hidden email]> wrote:
There's no way of stopping that... touch the getter, the object will load.  

One approach would be to keep another field for just the ID, and map it a second time.  But that's not pretty if this is a common case.

Clinton

On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger <[hidden email]> wrote:
Hi,

i m looking for a hint regarding a conceptual decision in a mybatis
application. Basically i have an entity Car and an entity Radio. Both
have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
will Map Car and Radio in mybatis and use an <association ....
select="radioSelect"> in the Car result map. This will load the Radio
object lazy if it is accessed with myCar.getRadio().


But another usecase is that i have a Car object myCar where the Radio
entity is not loaded. I simply want to make a copy of that car with an
insert statement, but i do not want to load the Radio object due to
performance issues. The radio id should be already available in
myCar.... but how can i access that id without touching
myCar.getRadio() .. which will load the whole Radio Object ...

Any hint appreciated,
Daniel




--
Shanhong Cheng
Reply | Threaded
Open this post in threaded view
|

RE: Conceptual Question regarding Associations and Fast Insert ..

Poitras Christian

If you can have 2 selects, one for the common case and one for the car copy, you can use a second resultMap defined like this:

 

<resultMap id=”some_id” type=”car”>

  <!—all things for car -->

  <result property=“radio.id” column=”radio_id”/>

</resultMap>

 

Or

 

<resultMap id=”some_id” type=”car”>

  <!—all things for car -->

  <associtation type=”radio”>

    <id property=“ id” column=”radio_id”/>

  </ associtation>

</resultMap>

 

That will prevent any lazy load since the radio object is preloaded (although only 1 property is correct).

 

Christian

 

De : [hidden email] [mailto:[hidden email]] De la part de Shanhong Cheng
Envoyé : June-29-11 5:52 PM
À : [hidden email]
Objet : Re: Conceptual Question regarding Associations and Fast Insert ..

 

is there a way to access a method of a parameter object in xml file? 

like this: 

#{parameterObject.methodName()}

On Wed, Jun 29, 2011 at 3:50 PM, Clinton Begin <[hidden email]> wrote:

There's no way of stopping that... touch the getter, the object will load.  

 

One approach would be to keep another field for just the ID, and map it a second time.  But that's not pretty if this is a common case.

 

Clinton

On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger <[hidden email]> wrote:

Hi,

i m looking for a hint regarding a conceptual decision in a mybatis
application. Basically i have an entity Car and an entity Radio. Both
have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
will Map Car and Radio in mybatis and use an <association ....
select="radioSelect"> in the Car result map. This will load the Radio
object lazy if it is accessed with myCar.getRadio().


But another usecase is that i have a Car object myCar where the Radio
entity is not loaded. I simply want to make a copy of that car with an
insert statement, but i do not want to load the Radio object due to
performance issues. The radio id should be already available in
myCar.... but how can i access that id without touching
myCar.getRadio() .. which will load the whole Radio Object ...

Any hint appreciated,
Daniel

 




--
Shanhong Cheng

 

Reply | Threaded
Open this post in threaded view
|

Re: Conceptual Question regarding Associations and Fast Insert ..

Hugh Ross
Another option -- define a shallow copy ctor for the Car class, use
that and then set just the fkey field before inserting?


On 6/30/11, Poitras Christian <[hidden email]> wrote:

> If you can have 2 selects, one for the common case and one for the car copy,
> you can use a second resultMap defined like this:
>
> <resultMap id="some_id" type="car">
>   <!-all things for car -->
>   <result property="radio.id" column="radio_id"/>
> </resultMap>
>
> Or
>
> <resultMap id="some_id" type="car">
>   <!-all things for car -->
>   <associtation type="radio">
>     <id property=" id" column="radio_id"/>
>   </ associtation>
> </resultMap>
>
> That will prevent any lazy load since the radio object is preloaded
> (although only 1 property is correct).
>
> Christian
>
> De : [hidden email] [mailto:[hidden email]] De
> la part de Shanhong Cheng
> Envoyé : June-29-11 5:52 PM
> À : [hidden email]
> Objet : Re: Conceptual Question regarding Associations and Fast Insert ..
>
> is there a way to access a method of a parameter object in xml file?
> like this:
> #{parameterObject.methodName()}
> On Wed, Jun 29, 2011 at 3:50 PM, Clinton Begin
> <[hidden email]<mailto:[hidden email]>> wrote:
> There's no way of stopping that... touch the getter, the object will load.
>
> One approach would be to keep another field for just the ID, and map it a
> second time.  But that's not pretty if this is a common case.
>
> Clinton
> On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger
> <[hidden email]<mailto:[hidden email]>>
> wrote:
> Hi,
>
> i m looking for a hint regarding a conceptual decision in a mybatis
> application. Basically i have an entity Car and an entity Radio. Both
> have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
> will Map Car and Radio in mybatis and use an <association ....
> select="radioSelect"> in the Car result map. This will load the Radio
> object lazy if it is accessed with myCar.getRadio().
>
>
> But another usecase is that i have a Car object myCar where the Radio
> entity is not loaded. I simply want to make a copy of that car with an
> insert statement, but i do not want to load the Radio object due to
> performance issues. The radio id should be already available in
> myCar.... but how can i access that id without touching
> myCar.getRadio() .. which will load the whole Radio Object ...
>
> Any hint appreciated,
> Daniel
>
>
>
>
> --
> Shanhong Cheng
> [hidden email]<mailto:[hidden email]>
> http://www.remedymd.com/
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Conceptual Question regarding Associations and Fast Insert ..

Clinton Begin
Administrator
In reply to this post by Poitras Christian
This is what I recommend as well... fetchLite, fetchFull... or fetchSummary, fetchDetail.

On Thu, Jun 30, 2011 at 6:23 AM, Poitras Christian <[hidden email]> wrote:

If you can have 2 selects, one for the common case and one for the car copy, you can use a second resultMap defined like this:

 

<resultMap id=”some_id” type=”car”>

  <!—all things for car -->

  <result property=“radio.id” column=”radio_id”/>

</resultMap>

 

Or

 

<resultMap id=”some_id” type=”car”>

  <!—all things for car -->

  <associtation type=”radio”>

    <id property=“ id” column=”radio_id”/>

  </ associtation>

</resultMap>

 

That will prevent any lazy load since the radio object is preloaded (although only 1 property is correct).

 

Christian

 

De : [hidden email] [mailto:[hidden email]] De la part de Shanhong Cheng
Envoyé : June-29-11 5:52 PM
À : [hidden email]
Objet : Re: Conceptual Question regarding Associations and Fast Insert ..

 

is there a way to access a method of a parameter object in xml file? 

like this: 

#{parameterObject.methodName()}

On Wed, Jun 29, 2011 at 3:50 PM, Clinton Begin <[hidden email]> wrote:

There's no way of stopping that... touch the getter, the object will load.  

 

One approach would be to keep another field for just the ID, and map it a second time.  But that's not pretty if this is a common case.

 

Clinton

On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger <[hidden email]> wrote:

Hi,

i m looking for a hint regarding a conceptual decision in a mybatis
application. Basically i have an entity Car and an entity Radio. Both
have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
will Map Car and Radio in mybatis and use an <association ....
select="radioSelect"> in the Car result map. This will load the Radio
object lazy if it is accessed with myCar.getRadio().


But another usecase is that i have a Car object myCar where the Radio
entity is not loaded. I simply want to make a copy of that car with an
insert statement, but i do not want to load the Radio object due to
performance issues. The radio id should be already available in
myCar.... but how can i access that id without touching
myCar.getRadio() .. which will load the whole Radio Object ...

Any hint appreciated,
Daniel

 




--
Shanhong Cheng

 


Reply | Threaded
Open this post in threaded view
|

Re: Conceptual Question regarding Associations and Fast Insert ..

Daniel Stieger
Ok,

to sum things up. I can simply use two different xml mappings. A
"deep" mapping which will load associations and a "shallow" mapping
which will just map the id of the association.

Thanks very much. Incredible support for mybatis!!!

Daniel


On 30 Jun., 23:34, Clinton Begin <[hidden email]> wrote:

> This is what I recommend as well... fetchLite, fetchFull... or fetchSummary,
> fetchDetail.
>
> On Thu, Jun 30, 2011 at 6:23 AM, Poitras Christian <
>
> [hidden email]> wrote:
> > If you can have 2 selects, one for the common case and one for the car
> > copy, you can use a second resultMap defined like this:****
>
> > ** **
>
> > <resultMap id=”some_id” type=”car”>****
>
> >   <!—all things for car -->****
>
> >   <result property=“radio.id” column=”radio_id”/>****
>
> > </resultMap>****
>
> > ** **
>
> > Or ****
>
> > ** **
>
> > <resultMap id=”some_id” type=”car”>****
>
> >   <!—all things for car -->****
>
> >   <associtation type=”radio”>****
>
> >     <id property=“ id” column=”radio_id”/>****
>
> >   </ associtation>****
>
> > </resultMap>****
>
> > ** **
>
> > That will prevent any lazy load since the radio object is preloaded
> > (although only 1 property is correct).****
>
> > ** **
>
> > Christian****
>
> > ** **
>
> > *De :* [hidden email] [mailto:[hidden email]]
> > *De la part de* Shanhong Cheng
> > *Envoyé :* June-29-11 5:52 PM
> > *À :* [hidden email]
> > *Objet :* Re: Conceptual Question regarding Associations and Fast Insert
> > ..****
>
> > ** **
>
> > is there a way to access a method of a parameter object in xml file? ****
>
> > like this: ****
>
> > *#{parameterObject.methodName()}*****
>
> > On Wed, Jun 29, 2011 at 3:50 PM, Clinton Begin <[hidden email]>
> > wrote:****
>
> > There's no way of stopping that... touch the getter, the object will load.
> >  ****
>
> > ** **
>
> > One approach would be to keep another field for just the ID, and map it a
> > second time.  But that's not pretty if this is a common case.****
>
> > ** **
>
> > Clinton****
>
> > On Tue, Jun 28, 2011 at 5:52 AM, Daniel Stieger <
> > [hidden email]> wrote:****
>
> > Hi,
>
> > i m looking for a hint regarding a conceptual decision in a mybatis
> > application. Basically i have an entity Car and an entity Radio. Both
> > have Integer Id´s and Car has a Foreign Key to a Radio. Of course i
> > will Map Car and Radio in mybatis and use an <association ....
> > select="radioSelect"> in the Car result map. This will load the Radio
> > object lazy if it is accessed with myCar.getRadio().
>
> > But another usecase is that i have a Car object myCar where the Radio
> > entity is not loaded. I simply want to make a copy of that car with an
> > insert statement, but i do not want to load the Radio object due to
> > performance issues. The radio id should be already available in
> > myCar.... but how can i access that id without touching
> > myCar.getRadio() .. which will load the whole Radio Object ...
>
> > Any hint appreciated,
> > Daniel****
>
> > ** **
>
> > --
> > Shanhong Cheng****
>
> > [hidden email]****
>
> >http://www.remedymd.com/****
>
> > ** **