简体   繁体   English

如何使用扩展对象中的字段使用左联接创建hql查询

[英]How to create hql query with left join using field from extending object

I have this class called Locatable: 我有一个叫做Locatable的类:

 @Entity
 @Table(name = "locatable")
 @PrimaryKeyJoinColumn(name = "device_id", referencedColumnName = "id")
 open class Locatable: Device() {

 @Basic
 @Column(name = NAME_COLUMN)
 var name: String? = null
    }

as you can see Locatable extended Device, Device looks like this: 如您所见,可定位扩展设备,设备如下所示:

@Entity
@Table(name = "device")
@Inheritance(strategy = InheritanceType.JOINED)
abstract class Device {

 @Id
 @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGen")
@SequenceGenerator(name = "sequenceGen", sequenceName = "devices_id_seq", allocationSize = 1)
@Column(name = ID_COLUMN)
open var id: Long = 0

@Basic
@Column(name = GROUP_COLUMN)
open var groupId: Long = 0
}

Now, Im trying to make a repo using hql like this: 现在,我正在尝试使用hql进行这样的回购:

interface LocatableRepo : JpaRepository<Locatable, Long> {

  @Query("SELECT l FROM Locatable l LEFT JOIN FETCH l.Device WHERE l.groupId IN ?1")
fun getByGroupIdIn(ids: List<Long>): List<Locatable>
}

but from some reason it's not working for me... probably i do it wrong, Thank you 但是由于某种原因它对我不起作用...可能我做错了,谢谢

groupdId is of entity Device so it should be groupdId属于设备实体,因此应为

LEFT JOIN FETCH l.Device d WHERE d.groupId 

you give a name to the device join and use that when referencing column belonging to device 您为设备连接命名,并在引用属于设备的列时使用该名称

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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