Home  >  Q&A  >  body text

java - How to query through external key in spring?

Entity relationship: A teacher has multiple students

@Entity
public Teacher class{
    @Id
    private Long id;
}
@Entity
public Student class{
    @Id
    Long id;
    @ManyToOne
    private Teacher teacher;
}

At this time, the database will automatically generate the foreign key of teacher_id in the student table, but if I know the teacherId, how can I query all the students of this teacher? By external teacher_id

为情所困为情所困2713 days ago598

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-05-17 10:00:13

    1. This problem has nothing to do with spring

    2. This problem has nothing to do with JPA or Hibernate

    3. This problem is related to the database you are using. Different databases have different methods. I only know how to do it in Oracle, see here

    reply
    0
  • 大家讲道理

    大家讲道理2017-05-17 10:00:13

    http://docs.spring.io/spring-...
    Method in official documentation

    reply
    0
  • Cancelreply