Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@OneToMany doesn't select join column because of missing join statement #84

Closed
kopax opened this issue Jan 16, 2017 · 4 comments
Closed
Assignees
Labels
Milestone

Comments

@kopax
Copy link

kopax commented Jan 16, 2017

annotation @OneToMany doesn't join column

It appear the @OneToMany association doesn't work as expected.

version

I am using commit.

This is how I did the join table mapping, in SiteService.java :

@JdbcType(BIGINT)
@OneToMany
@JoinTable(name = "SITE_FUNCTION")
@JoinColumn(name = "SITE_SERVICE_ID")
@NotNull
private List<SiteFunction> siteFunctionList;

Result

Produce an empty array for siteFunctionList

Expected result

Produce an array using database data for siteFunctionList

The select method appear to not add any jointure for this table.

(but @manytoone association seems to work fine so far.)
The xml generated render an empty <sql id="SELECT_CONDITION_INNER"></sql>

What is it use for ?

There is this generated for the mapping by the annotations:

        <collection property="siteFunctionList" ofType="com.domain.security.SiteFunction">
            <id property="id" column="siteFunctionList.id" javaType="java.lang.Long" jdbcType="BIGINT"/>
            <result property="messageId" column="siteFunctionList.messageId" javaType="java.lang.String"
                    jdbcType="VARCHAR"/>
            <result property="name" column="siteFunctionList.name" javaType="java.lang.String" jdbcType="VARCHAR"/>
        </collection>

But nothing for selecting the field.

@kopax kopax changed the title Problem with @OneToMany and @ManyToOne Problem with @OneToMany Jan 16, 2017
@kopax kopax changed the title Problem with @OneToMany @OneToMany doesn't select join column because of missing join statement Jan 16, 2017
@kopax
Copy link
Author

kopax commented Jan 16, 2017

I also wonder, in this scenario, is there any way for me to just rewrite or add some extra xml in my mappers folder in order to complete/repair the mapping ?

That would be a good information to know.

@kopax
Copy link
Author

kopax commented Jan 31, 2017

Hi @hatunet any update on this ?

@easybest easybest self-assigned this Feb 1, 2017
@easybest easybest added the bug label Feb 1, 2017
@easybest easybest added this to the 1.0.8 milestone Feb 1, 2017
@kopax
Copy link
Author

kopax commented Feb 2, 2017

I have upgraded to spring-boot 1.5.1.RELEASE and now how spring-data-commons 1.13.RELEASE according to #98

I was able to start without my error but it seems the one to many have some "case" and mapping issues.

@OneToMany

spring-data-mybatis commit version : 3b6fba0

Test repository available here

git clone git@github.com:kopax/spring-data-mybatis-testing.git
git checkout onetomany
./gradlew build --info && java -jar build/libs/spring-data-mybatis-testing-0.1.0.war

Test

curl http://localhost:8080/siteServices

Expected

HTTP 200

Result

Thu Feb 02 19:14:48 ICT 2017
There was an unexpected error (type=Internal Server Error, status=500).
### Error querying database. Cause: org.h2.jdbc.JdbcSQLException: Column "SITE_FUNCTION.SITE_FUNCTION_ID" not found; SQL statement: select "siteService".id as "id","siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id","siteService.siteFunctionList".NAME as "siteFunctionList.name","siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" from SITE_SERVICE "siteService" left outer join SITE_FUNCTION on SITE_FUNCTION.SITE_SERVICE_id="siteService".id left outer join SITE_FUNCTION "siteService.siteFunctionList" on SITE_FUNCTION.SITE_FUNCTION_id="siteService.siteFunctionList".id [42122-193] ### The error may exist in org.springframework.data.mybatis.samples.security.SiteService_auto_generate.xml ### The error may involve org.springframework.data.mybatis.samples.security.SiteService._findAll ### The error occurred while executing a query ### SQL: select "siteService".id as "id","siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id","siteService.siteFunctionList".NAME as "siteFunctionList.name","siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" from SITE_SERVICE "siteService" left outer join SITE_FUNCTION on SITE_FUNCTION.SITE_SERVICE_id="siteService".id left outer join SITE_FUNCTION "siteService.siteFunctionList" on SITE_FUNCTION.SITE_FUNCTION_id="siteService.siteFunctionList".id ### Cause: org.h2.jdbc.JdbcSQLException: Column "SITE_FUNCTION.SITE_FUNCTION_ID" not found; SQL statement: select "siteService".id as "id","siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id","siteService.siteFunctionList".NAME as "siteFunctionList.name","siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" from SITE_SERVICE "siteService" left outer join SITE_FUNCTION on SITE_FUNCTION.SITE_SERVICE_id="siteService".id left outer join SITE_FUNCTION "siteService.siteFunctionList" on SITE_FUNCTION.SITE_FUNCTION_id="siteService.siteFunctionList".id [42122-193] ; bad SQL grammar []; nested exception is org.h2.jdbc.JdbcSQLException: Column "SITE_FUNCTION.SITE_FUNCTION_ID" not found; SQL statement: select "siteService".id as "id","siteService".NAME as "name","siteService.siteFunctionList".id as "siteFunctionList.id","siteService.siteFunctionList".NAME as "siteFunctionList.name","siteService.siteFunctionList".SITE_SERVICE_ID as "siteFunctionList.siteService.id" from SITE_SERVICE "siteService" left outer join SITE_FUNCTION on SITE_FUNCTION.SITE_SERVICE_id="siteService".id left outer join SITE_FUNCTION "siteService.siteFunctionList" on SITE_FUNCTION.SITE_FUNCTION_id="siteService.siteFunctionList".id [42122-193]

@easybest
Copy link
Owner

easybest commented Feb 2, 2017

You have a problem with the usage, and you can see this pr: kopax/spring-data-mybatis-testing#2

this pr include @OneToMany , rest projection and extend-xml issues.

@easybest easybest closed this as completed Feb 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants