Quantcast

nested selects n+1 in myabtis - queries only in intrafaces

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

nested selects n+1 in myabtis - queries only in intrafaces

tom.reynick

Is it possible at this moment solve n+1 problem (nested selects) in myabtis ? I mean Java only, without xml files.
It is about simple case, relation one-to-many. I can solve it using nested selects, but I am worried about performance. My databse is sql server.
Examples are the best thing!

Thanks in advance, Regards

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nested selects n+1 in myabtis - queries only in intrafaces

Guy Rouillier-2
I'm not understanding something about your scenario.  You can replace a nested select with a join.
 
--
Guy Rouillier
 
 
 
------ Original Message ------
To: "mybatis-user" <[hidden email]>
Sent: 1/11/2017 3:28:21 PM
Subject: nested selects n+1 in myabtis - queries only in intrafaces
 

Is it possible at this moment solve n+1 problem (nested selects) in myabtis ? I mean Java only, without xml files.
It is about simple case, relation one-to-many. I can solve it using nested selects, but I am worried about performance. My databse is sql server.
Examples are the best thing!

Thanks in advance, Regards

--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nested selects n+1 in myabtis - queries only in intrafaces

tom.reynick
In reply to this post by tom.reynick
@Roullier, you get it.

It is my aim to use join in sql query. Let's me give you an example:  

The aim is map query to following POJO, avoiding n+1 select problem:  
class Person {
  String surname;
  String name;
  int id;
  LIst <Dog> dogs;
}
class Dog {
  int IdOwnder;
  int dogId,
  String name;
  int age;
}

So, you know that Person can have many  dogs.   
We have two tables: Dog and Person
Dog: idOwner, id, name, age
Person: name, surname, id

Now, lets look at query: 
select * from Person P
join Dog D on
D.idOwner = P.id
However, it returns many rows for one person (If this person has more than one dog).   
How to map it into my POJO models ? 
Keep in mind, that I am searching for solution in JAVA, no xml.   
If it is not possible to use JAVA to do it, I can also use xml file, but I prefer JAVA interafaces.    

-------------------------------------------------------------------------------------------------------------------------------------------------------
Of course tables that I did show are not in BNFC. There is should be other thirds table: IdOwner, IdDog. However, then results is the same, only query requires two joins.   

Thanks in advance!





--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nested selects n+1 in myabtis - queries only in intrafaces

Mukarram
I believe you are looking for the Mapper Annotations (http://www.mybatis.org/mybatis-3/java-api.html) property of @Result. The id on person.id and many on the dog.dogId results should convert the person object to have a collection of dogs, right?

On Thursday, 12 January 2017 04:50:47 UTC-5, [hidden email] wrote:
@Roullier, you get it.

It is my aim to use join in sql query. Let's me give you an example:  

The aim is map query to following POJO, avoiding n+1 select problem:  
class Person {
  String surname;
  String name;
  int id;
  LIst <Dog> dogs;
}
class Dog {
  int IdOwnder;
  int dogId,
  String name;
  int age;
}

So, you know that Person can have many  dogs.   
We have two tables: Dog and Person
Dog: idOwner, id, name, age
Person: name, surname, id

Now, lets look at query: 
select * from Person P
join Dog D on
D.idOwner = P.id
However, it returns many rows for one person (If this person has more than one dog).   
How to map it into my POJO models ? 
Keep in mind, that I am searching for solution in JAVA, no xml.   
If it is not possible to use JAVA to do it, I can also use xml file, but I prefer JAVA interafaces.    

-------------------------------------------------------------------------------------------------------------------------------------------------------
Of course tables that I did show are not in BNFC. There is should be other thirds table: IdOwner, IdDog. However, then results is the same, only query requires two joins.   

Thanks in advance!





--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: nested selects n+1 in myabtis - queries only in intrafaces

tom.reynick
Yeah

W dniu sobota, 14 stycznia 2017 04:17:45 UTC+1 użytkownik Mukarram napisał:
I believe you are looking for the Mapper Annotations (<a href="http://www.mybatis.org/mybatis-3/java-api.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fjava-api.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG4gemFovNletK9rJgOJ1X879qlDA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwww.mybatis.org%2Fmybatis-3%2Fjava-api.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNG4gemFovNletK9rJgOJ1X879qlDA&#39;;return true;">http://www.mybatis.org/mybatis-3/java-api.html) property of @Result. The id on <a href="http://person.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fperson.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxmxIbEG3g1Rp9ShzLcRqWqCERQg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fperson.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFxmxIbEG3g1Rp9ShzLcRqWqCERQg&#39;;return true;">person.id and many on the dog.dogId results should convert the person object to have a collection of dogs, right?

On Thursday, 12 January 2017 04:50:47 UTC-5, [hidden email] wrote:
@Roullier, you get it.

It is my aim to use join in sql query. Let's me give you an example:  

The aim is map query to following POJO, avoiding n+1 select problem:  
class Person {
  String surname;
  String name;
  int id;
  LIst <Dog> dogs;
}
class Dog {
  int IdOwnder;
  int dogId,
  String name;
  int age;
}

So, you know that Person can have many  dogs.   
We have two tables: Dog and Person
Dog: idOwner, id, name, age
Person: name, surname, id

Now, lets look at query: 
select * from Person P
join Dog D on
D.idOwner = P.id
However, it returns many rows for one person (If this person has more than one dog).   
How to map it into my POJO models ? 
Keep in mind, that I am searching for solution in JAVA, no xml.   
If it is not possible to use JAVA to do it, I can also use xml file, but I prefer JAVA interafaces.    

-------------------------------------------------------------------------------------------------------------------------------------------------------
Of course tables that I did show are not in BNFC. There is should be other thirds table: IdOwner, IdDog. However, then results is the same, only query requires two joins.   

Thanks in advance!





--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...