I am using java hibernate to store my data entities. I want to know the sql command to select the data in a @ManyToMany column using postgresql-psql command.
for normal columns, I can just run:
SELECT id FROM university;
But now I have the following university entity:
@Entity
@Table(name = "university")
public class University {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
private Long id;
@ManyToMany(fetch=FetchType.EAGER)
@JoinColumn(name="students" /* referencedColumnName="id" */)
private List<Student> students;
}
@Entity
@Table(name = "student", uniqueConstraints = { @UniqueConstraint(columnNames={"name"})})
public class Student
{
@Id
private Long id;
@NotBlank
@NotNull
private String name;
}
The problem is, I don't know what the student list is called in psql.
When I run:
SELECT students FROM university;
I get:
ERROR: column "students" does not exist
When I type:
\d university
I get (not actual data: data anonymized to student/university example):
Column | Type | Collation | Nullable | Default
------------------+-----------------------------+-----------+----------+---------
id | bigint | | not null |
Indexes:
"university_pkey" PRIMARY KEY, btree (id)
"uk_rwpd2frv6wtkgqtxn3envk3i8" UNIQUE CONSTRAINT, btree (name)
Referenced by:
TABLE "university_students" CONSTRAINT "fkdkjk4jgutu64g937gkknybax2" FOREIGN KEY (university) REFERENCES university(id)