Consider this class:
@Entity
@Table(name = "USER_TABLE")
@Inheritance(strategy = InheritanceType.JOINED)
public class User {
@Id
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
@GeneratedValue(generator="system-uuid")
@Column(name = "id", unique = true)
@Type(type= "org.hibernate.type.PostgresUUIDType")
private UUID id;
@Column(name = "USERNAME")
private String userName;
}
and its simple child:
@Entity
@Table(name = "CUSTOMER")
public class Customer extends User{
//some extra fields
}
I have another class having relation to user:
@Entity
@Table(name = "USER_ACTIVITY")
public class UserActivity {
@ManyToOne
@JoinColumn(name = "USERID")
private User user;
//id and other fields
}
This is the tricky part. I want to fetch all objects of type UserActivity which relates to a "Customer". I tried something like this:
public interface UserActivityRepository extends PagingAndSortingRepository<UserActivity,UUID> {
@Query("select u from UserActivity u join Customer.id")
List<UserActivity> findAllByUserIsNotNullOrderByCreatedDesc(Pageable pageable);
}
But hibernate tells me that I've specified an invalid path.
Could you help me on this?