Comments (10)
@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.
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.
from spring-data-mybatis.
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.
siteFunctionRepository.findBySiteServiceId(1L)
what's the SQL generate in console ?
from spring-data-mybatis.
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.
is the SQL correct?
from spring-data-mybatis.
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.
because of missing quotation marks?
from spring-data-mybatis.
yes
from spring-data-mybatis.
Related Issues (20)
- 这个项目还会支持最新版的spring boot吗 HOT 1
- complex composite id
- Related queries support sorting
- @ElementCollection support
- 后续有什么计划吗
- 请问啥时发布新版本
- @Convert 注解似乎还不支持
- 中文说明中spring-boot的mapper文件配置错误
- 是否支持批量新增、修改
- Table names support uniform prefixes
- Join table supports uniform table prefix
- The official website document is gone. 文档没了
- change mapper.xml's namespace reference Repository but not DO #feature
- base on branch 3.x, I build it successful. Can I take a pull request? HOT 1
- 3.x支持多数据源么
- Is this repo still being maintained? HOT 1
- Multi-tenant support
- can support @GeneratedValue? HOT 2
- MybatisEntityManagerAutoConfiguration not running
- Multi-tenant problems
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-data-mybatis.