简体   繁体   中英

Problem joining tables with CriteriaBuilder in Hibernate

I'm trying to join table using CriteriaBuilder, using metamodels. But it seems i'm doing something wrong.

//this is where is get and join tables
Root<Album> mainTable = criteria.from(Album.class); 
Join<Album, Track> tracksJoin = mainTable.join(Track_.album, JoinType.INNER); //type conflict

//piece of metamodel 1
@StaticMetamodel(Album.class)
public class Album_ {
public static volatile CollectionAttribute<Album, Track> tracksList;

//piece of metamodel 2
@StaticMetamodel(Track.class)
public class Track_ {
public static volatile SingularAttribute<Track, Album> album;

//piece of DAO Album

@ManyToMany
private ArrayList<Track> tracksList;

//piece of DAO Track

private Album album;

Can you please explain what am I doing wrong and how to join these tables.

尝试一下,在类似的情况下,我的代码可以解决。

Join<Album, Track> tracksJoin = mainTable.join(ALBUM_.tracksList, JoinType.INNER).join(Track_.album, JoinType.INNER);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM