Steve Mayr
Steve Mayr

Reputation: 1

How can I acces another column in entity list?

I write my backend in JavaEE with the usage of JPA. I have a entity with a list in it.

public class Lesson {

    @Id
    private String id;
    private List<Time> times;

Time Entity:

@Entity
public class Time {

    @Id
    @GeneratedValue
    private int id;
    private String assigned_room;

I want to get a List of Lessons which have a specific assigned_room.

For example:

Lesson: id=1, times{id:1, assigned_room:room123 -- id:2 assigned_room_:room321 -- id:3 assigned_room:room123}

Then I want when I want all lessons in room123 with times ... I tried:


@NamedQuery(name = "Lesson.getWithRoomId", query = "select l from Lesson l where :id member of l.times")

But following error occured:

Parameter value [room123] did not match expected type [... .entities.Time (n/a)]

Has anyone an idea how to fix the error or a solution for the problem? Thank you!!

Upvotes: 0

Views: 38

Answers (1)

Michael Altenburger
Michael Altenburger

Reputation: 1336

The problem is in your member of clause as your supplying the id of the room but l.times is a collection of type Time. You could for example use the following query:

SELECT l FROM Lesson l JOIN l.times t WHERE t.assigned_room = :id

Upvotes: 2

Related Questions