JPA と Hibernate を使用して、Java Spring プロジェクトに取り組んでいます。「トピック」と「チューター」の 2 つのエンティティがあります。クラス「Topic」には、次のスニペットでわかるように、「Tutor」への参照として ManyToMany List があります。
public class Topic implements Serializable {
...
@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
@JoinColumn(name = "pretutor_id")
@IndexColumn(name = "id")
private List<Tutor> preferedTutors = new ArrayList<Tutor>();
....
「チューター」エンティティには、「トピック」への後方参照はありません。
私が達成したいのは、preferedTutors List 属性に特定の Tutor オブジェクトを含むすべてのトピックを含むトピックのリストを取得することです。そうするために、私はそれを試しました
"SELECT t FROM Topic t WHERE :tutor MEMBER OF t.preferedTutors"
パラメータ ":tutor" は "Tutor" オブジェクトです。コードは正しくコンパイルされていますが、テストで実行すると、残念ながら次のエラーが発生します。
Caused by: java.sql.SQLException: Unexpected token: . in statement [select topic0_.id as id4_0_, diplomate2_.id as id1_1_, tutor4_.id as id1_2_, topicdescr5_.id as id6_3_, topic0_.descriptionfile_id as descript3_4_0_, topic0_.procedure_id as procedure4_4_0_, topic0_.diplomate_id as diplomate5_4_0_, topic0_.title as title4_0_, topic0_.tutor_id as tutor6_4_0_, diplomate2_.accountName as accountN2_1_1_, diplomate2_.description as descript3_1_1_, diplomate2_.procedure_id as procedure8_1_1_, diplomate2_.email as email1_1_, diplomate2_.firstname as firstname1_1_, diplomate2_.lastname as lastname1_1_, diplomate2_.title as title1_1_, prospectiv1_.Topic_id as Topic1_4_0__, prospectiv1_.prospectiveDiplomates_id as prospect2_0__, prospectiv1_.id as id0__, tutor4_.accountName as accountN2_1_2_, tutor4_.description as descript3_1_2_, tutor4_.procedure_id as procedure8_1_2_, tutor4_.email as email1_2_, tutor4_.firstname as firstname1_2_, tutor4_.lastname as lastname1_2_, tutor4_.title as title1_2_, tutor4_.contingent as contingent5_2_, tutor4_.createdAt as createdAt5_2_, tutor4_.isAdmin as isAdmin5_2_, preferedtu3_.Topic_id as Topic1_4_1__, preferedtu3_.preferedTutors_id as prefered2_1__, preferedtu3_.id as id1__, topicdescr5_.file as file6_3_, topicdescr5_.fileName as fileName6_3_, topicdescr5_.fileType as fileType6_3_, topicdescr5_.uploadDate as uploadDate6_3_ from Topic topic0_ left outer join Topic_Diplomate prospectiv1_ on topic0_.id=prospectiv1_.Topic_id left outer join Diplomate diplomate2_ on prospectiv1_.prospectiveDiplomates_id=diplomate2_.id left outer join Topic_Tutor preferedtu3_ on topic0_.id=preferedtu3_.Topic_id left outer join Tutor tutor4_ on preferedtu3_.preferedTutors_id=tutor4_.id left outer join TopicDescription topicdescr5_ on topic0_.descriptionfile_id=topicdescr5_.id cross join Topic_Tutor preferedtu6_, Tutor tutor7_ where topic0_.id=preferedtu6_.Topic_id and preferedtu6_.preferedTutors_id=tutor7_.id and (topic0_.diplomate_id is not null) and (. is not null)]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1616)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
... 58 more
明らかに「。」生成されたステートメントの末尾にある式「(. is not null)」では処理できません。これは既知のバグですか、それとも JPA クエリを変更する必要がありますか?
ありがとう、マックス