Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在自定义查询中加载@ElementCollection?_Java_Sql_Spring_Hibernate_Jpa - Fatal编程技术网

Java 如何在自定义查询中加载@ElementCollection?

Java 如何在自定义查询中加载@ElementCollection?,java,sql,spring,hibernate,jpa,Java,Sql,Spring,Hibernate,Jpa,我想减少spring运行的查询量。通过SQL获取带有@ElementCollection的对象时,我希望通过quers中的联接直接获取ElementCollections的数据 包含ElementCollection的属性 @ElementCollection(fetch=FetchType.EAGER) @JoinTable(name=“歌曲类型列表”) @org.hibernate.annotations.Cache(用法=cacheconcurrentystrategy.READ\u WR

我想减少spring运行的查询量。通过SQL获取带有@ElementCollection的对象时,我希望通过quers中的联接直接获取ElementCollections的数据

包含ElementCollection的属性

@ElementCollection(fetch=FetchType.EAGER)
@JoinTable(name=“歌曲类型列表”)
@org.hibernate.annotations.Cache(用法=cacheconcurrentystrategy.READ\u WRITE)
私人列表体裁;
使用自定义字符串的方法:

@Query(
value=“从musicdb.songs中选择不同的s.*,g.*左加入musicdb.song\u流派\u列表g on s.id=g.song\u id,其中s.name像?1或s.artist像?1”,
nativeQuery=true)
列表搜索歌曲(字符串标题);
我将如何想象定义一个同时加载此元素集合的查询:

s.id=g.song\u id,其中s.name LIKE?1或s.artist LIKE?1
Spring目前正在做什么(加载3首带有更多查询的歌曲的类型):

Hibernate:从musicdb.songs中选择不同的s.*,g.*左键加入musicdb.song\u流派\u列表g on s.id=g.song\u id,其中s.name像?1或s.artist像?1
休眠:从musicdb.song_流派列表中选择genre0。song_id为song_id 1_4_0,genre0。流派为genre2_4_0?
休眠:从musicdb.song_流派列表中选择genre0。song_id为song_id 1_4_0,genre0。流派为genre2_4_0?
休眠:从musicdb.song_流派列表中选择genre0。song_id为song_id 1_4_0,genre0。流派为genre2_4_0?
我希望Spring做的是:

Hibernate:从musicdb.songs中选择不同的s.*,g.*左键加入musicdb.song\u流派\u列表g on s.id=g.song\u id,其中s.name像?1或s.artist像?1

ElementCollection所需的数据已包含在联接中。如何让spring导入该数据?

FetchType.EAGER将已经为您加载了流派,因此您不需要在原始查询中编写联接。但是对于这种情况,hibernate默认使用单独的查询。若要更改此设置,请在流派字段中添加注释“@Fetch(FetchMode.JOIN)”

FetchType.EAGER将已经为您加载流派,因此您不需要在原始查询中写入联接。但是对于这种情况,hibernate默认使用单独的查询。要更改此设置,请在类型字段中添加注释“@Fetch(FetchMode.JOIN)”