Giter Club home page Giter Club logo

Comments (10)

easybest avatar easybest commented on July 20, 2024

@OneToMany is not supported now, it will be supported next version.
now you must add @transient to you one-to-many column, and set it by yourself.

from spring-data-mybatis.

kopax avatar kopax commented on July 20, 2024

That make sens, I am still looking for a way to set it by myself.

So far, I can't add custom xml mappers. (#88)

I can't write generated custom query. ( #87)

Do you have an alternative way ?

from spring-data-mybatis.

easybest avatar easybest commented on July 20, 2024

see https://github.com/hatunet/spring-data-mybatis-testing/blob/extendxml/src/main/java/org/springframework/data/mybatis/samples/security/SiteFunctionRepository.java#L19

from spring-data-mybatis.

kopax avatar kopax commented on July 20, 2024

I am still trying to make this work, for some reason the list is null.

I have created a test case :

$ git clone [email protected]:kopax/spring-data-mybatis-testing.git && cd spring-data-mybatis-testing
$ git checkout extendxml
$ ./gradlew build --info && java -jar build/libs/spring-data-mybatis-testing-0.1.0.war

I have created two routes in Application.java :

    @RequestMapping(method = RequestMethod.GET, value = "/test/2", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseEntity<?> findBySiteServiceIdDirect() {
        return ResponseEntity.ok(siteServiceRepository.findOne(1L));
    }

    @RequestMapping(method = RequestMethod.GET, value = "/test/3", produces = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResponseEntity<?> findBySiteServiceId() {
        return ResponseEntity.ok(siteFunctionRepository.findBySiteServiceId(1L));
    }

And the result :

$ curl http://localhost:8080/test/2
{"id":1,"name":"User service","siteFunctionList":[{"id":1,"name":"User management","siteService":null,"siteContentList":null,"new":false}],"new":false}
$ curl http://localhost:8080/test/3
[]

I have tried to write test but I wasn't able to load the repository in junit.

from spring-data-mybatis.

easybest avatar easybest commented on July 20, 2024

siteFunctionRepository.findBySiteServiceId(1L)

what's the SQL generate in console ?

from spring-data-mybatis.

kopax avatar kopax commented on July 20, 2024

siteServiceRepository.findOne(1L)

==>  Preparing: select "siteService".id as "id","siteService".I18N_ID as "messageId","siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id","siteService.siteFunctionList".I18N_ID as "siteFunctionList.messageId","siteService.siteFunctionList".NAME as "siteFunctionList.name","siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" from SITE_SERVICE "siteService" left outer join SITE_FUNCTION "siteService.siteFunctionList" on "siteService".ID="siteService.siteFunctionList".SITE_SERVICE_ID where "siteService".id=? 
==> Parameters: 1(Long)
<==      Total: 1

siteFunctionRepository.findBySiteServiceId(1L)

==>  Preparing: select "siteFunction".id as "id","siteFunction".I18N_ID as "messageId","siteFunction".NAME as "name","siteFunction.siteService".id as "siteService.id","siteFunction.siteService".I18N_ID as "siteService.messageId","siteFunction.siteService".NAME as "siteService.name","siteFunction.siteContentList".id as "siteContentList.id","siteFunction.siteContentList".I18N_ID as "siteContentList.messageId","siteFunction.siteContentList".NAME as "siteContentList.name","siteFunction.siteContentList".SITE_FUNCTION_ID as "siteContentList.siteFunction.id" from SITE_FUNCTION "siteFunction" left outer join SITE_SERVICE "siteFunction.siteService" on "siteFunction".SITE_SERVICE_ID="siteFunction.siteService".id left outer join SITE_CONTENT "siteFunction.siteContentList" on "siteFunction".ID="siteFunction.siteContentList".SITE_FUNCTION_ID where ( "siteFunction.siteService".id=? ) 
==> Parameters: null
<==      Total: 0
Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@7b207b9e

from spring-data-mybatis.

easybest avatar easybest commented on July 20, 2024

is the SQL correct?

from spring-data-mybatis.

kopax avatar kopax commented on July 20, 2024

I think so, the escaping of the tables does not.

I have run the test on my database, I use a different LongId with uppercase for table ID, while in my sample github repo I am using your LongId.

Still, it appear there are some unescaped table names in each requests.

siteServiceRepository.findOne(1L)

The query produced by spring-data-mybatis :

 select 
     "siteService".ID as "id",
     "siteService".I18N_ID as "messageId",
     "siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id",
     "siteService.siteFunctionList".I18N_ID as "siteFunctionList.messageId",
     "siteService.siteFunctionList".NAME as "siteFunctionList.name",
     "siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" 
 from 
    SITE_SERVICE "siteService" 
 left outer join 
    SITE_FUNCTION "siteService.siteFunctionList" on "siteService".ID="siteService.siteFunctionList".SITE_SERVICE_ID 
 where 
    "siteService".ID=1

It throw the following error :

relation "site_service" does not exist
name: error
length: 112
severity: ERROR
code: 42P01
position: 425
file: parse_relation.c
line: 1159
routine: parserOpenTable

It look like they are some unescaped column name.

I have corrected the query and it should look like :

 select 
     "siteService"."ID" as "id",
     "siteService"."I18N_ID" as "messageId",
     "siteService"."NAME" as "name",
     "siteService.siteFunctionList"."ID" as "siteFunctionList.id",
     "siteService.siteFunctionList"."I18N_ID" as "siteFunctionList.messageId",
     "siteService.siteFunctionList"."NAME" as "siteFunctionList.name",
     "siteService.siteFunctionList"."SITE_SERVICE_ID" as "siteFunctionList.siteService.id" 
 from 
    "SITE_SERVICE" "siteService" 
 left outer join 
    "SITE_FUNCTION" "siteService.siteFunctionList" on "siteService"."ID"="siteService.siteFunctionList"."SITE_SERVICE_ID"
 where 
    "siteService"."ID"=1

siteFunctionRepository.findBySiteServiceId(1L)

This query also has the same problem:

select 
    "siteFunction".ID as "id",
    "siteFunction".I18N_ID as "messageId",
    "siteFunction".NAME as "name",
    "siteFunction.siteService".id as "siteService.id",
    "siteFunction.siteService".I18N_ID as "siteService.messageId",
    "siteFunction.siteService".NAME as "siteService.name",
    "siteFunction.siteContentList".id as "siteContentList.id",
    "siteFunction.siteContentList".I18N_ID as "siteContentList.messageId",
    "siteFunction.siteContentList".NAME as "siteContentList.name",
    "siteFunction.siteContentList".SITE_FUNCTION_ID as "siteContentList.siteFunction.id" 
from 
    SITE_FUNCTION "siteFunction" 
left outer join 
    SITE_SERVICE "siteFunction.siteService" on "siteFunction".SITE_SERVICE_ID="siteFunction.siteService".id 
left outer join 
    SITE_CONTENT "siteFunction.siteContentList" on "siteFunction".ID="siteFunction.siteContentList".SITE_FUNCTION_ID 
where 
    ( "siteFunction.siteService".id=1 ) 

It throw the following :

relation "site_function" does not exist
name: error
length: 113
severity: ERROR
code: 42P01
position: 604
file: parse_relation.c
line: 1159
routine: parserOpenTable

Corrected query:

select 
    "siteFunction"."ID" as "id",
    "siteFunction"."I18N_ID" as "messageId",
    "siteFunction"."NAME" as "name",
    "siteFunction.siteService"."ID" as "siteService.id",
    "siteFunction.siteService"."I18N_ID" as "siteService.messageId",
    "siteFunction.siteService"."NAME" as "siteService.name",
    "siteFunction.siteContentList"."ID" as "siteContentList.id",
    "siteFunction.siteContentList"."I18N_ID" as "siteContentList.messageId",
    "siteFunction.siteContentList"."NAME" as "siteContentList.name",
    "siteFunction.siteContentList"."SITE_FUNCTION_ID" as "siteContentList.siteFunction.id" 
from 
    "SITE_FUNCTION" "siteFunction" 
left outer join 
    "SITE_SERVICE" "siteFunction.siteService" on "siteFunction"."SITE_SERVICE_ID"="siteFunction.siteService"."ID"
left outer join 
    "SITE_CONTENT" "siteFunction.siteContentList" on "siteFunction"."ID"="siteFunction.siteContentList"."SITE_FUNCTION_ID"
where 
    ( "siteFunction.siteService"."ID"=1 ) 

from spring-data-mybatis.

easybest avatar easybest commented on July 20, 2024

because of missing quotation marks?

from spring-data-mybatis.

kopax avatar kopax commented on July 20, 2024

yes

from spring-data-mybatis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.