Questions tagged [joincolumn]

71 questions
8
votes
1 answer

Hibernate @ManyToMany joinTable - OrderBy using join table's field

There are 3 tables: TABLE_A ID_A field1 fieldN TABLE_B ID_B field1 fieldN TABLE_A_B ID_A ID_B orderField public class A(){ @ManyToMany @JoinTable(name="TABLE_A_B", joinColumns={@JoinColumn(name="ID_A")},…
Daniel Santana
  • 142
  • 1
  • 2
  • 9
7
votes
2 answers

Annotation to join columns with OR condition instead of AND condition

I have 2 java classes, Relation and Person, which both are present in my database. Person: @Entity @Table(name = "persons") public class Person { @Id @Column private int id; @Column private String name; @OneToMany(fetch =…
STheFox
  • 1,458
  • 3
  • 16
  • 24
7
votes
2 answers

OneToOne relationship for a non primary key column

I'm having a problem when I query an entity who has a OneToOne relationship with another one. This is the scenario: Database tables: create table people ( id decimal(10,0) NOT NULL, email varchar(512) NOT NULL ); create table users ( …
RDV
  • 145
  • 1
  • 3
  • 9
5
votes
2 answers

EntityManager query by joinColumn

I have a Login entity and a Customer entity. Login.username is a foreign key in the customer table. Hence the following line in the Java Customer POJO @OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "username", nullable = false) private Login…
kasavbere
  • 5,583
  • 9
  • 46
  • 71
3
votes
1 answer

How to join a table with forgein key in nested object in hibernate

i have this case: @Table(name = "metadata") @Entity @Data @Builder @NoArgsConstructor @AllArgsConstructor public class Metadata{ @Column(name = "id", updatable = false, nullable = false) @Type(type = "uuid-char") private UUID id; …
Alex Alex
  • 49
  • 5
3
votes
2 answers

Joincolumn returns null value

I am trying to join a column using the @JoinColumn annotation but my column is always returning a null and I am not sure why. @Entity public class Blender implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name =…
Ergun Polat
  • 466
  • 1
  • 10
  • 22
3
votes
2 answers

Is @JoinColumn annotation mandatory in Hibernate?

In Hibernate, to specify a column for joining association, @JoinColumn annotation in used, for example like this: @ManyToOne @JoinColumn(name="address_id") public Address getAddress() { return address; } In most cases, name of the column is…
Mikhail Batcer
  • 1,536
  • 2
  • 28
  • 49
3
votes
1 answer

Join by a single column instead of a composite primary key

I have single JPA entity and I would to add self join on this table. Table looks like e.g. @Entity @Table(name = "TABLE_A") @IdClass(TableAPk.class) public class TableA implements Serializable { private static final long serialVersionUID =…
user613114
  • 2,459
  • 10
  • 40
  • 68
3
votes
3 answers

Conditional/composite JoinColumn In JPA/Hibernate

In one of my classes, say Location, I have something like this: private List magicians; ... @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name="location_id") public List getMagicians() { return…
2
votes
2 answers

Hibernate join using non-primary key column

I have two tables: users: user_id (primary) ip (unique) etc .. services_to_ip id (primary) service_id ip etc .. In class User: @OneToMany() @JoinColumn(name = "ip", insertable = false, nullable = false, updatable = false) public…
FakiR
  • 33
  • 1
  • 5
2
votes
2 answers

EntityManager query cannot resolve property

I am using JPA to query an OracleSQL database. However, I am getting the error: Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: CLIENT_ID of:…
asd
  • 29
  • 1
2
votes
0 answers

@JoinColumns with composite primary key on both tables

I have to map a legacy db with a couple of tables like these --------- - GROUP - --------- +idcust - +key - +idgroup- -domain - --------- pk(idcust,key,idgroup) ------------------ - GROUP_LABEL - ------------------ +idcust - +key …
2
votes
1 answer

Creation of entity in JPA which has a joinColumn

I am trying to create a entity B which has a Join column with another entity A with the other entity's primary key. When I create an entity B with a value that is not in entity A, I am not seeing an exception. Should this not be automatically taken…
Arti P
  • 21
  • 2
2
votes
1 answer

JPA - List of Foreign Keys instead of Entities in ManyToMany relationship

I want to import data from an existing database which contains a table of appointments and a join table for appointments and rooms. TABLE Appointment { id ... } TABLE Appointment_Room { appointment_id, room_id } I do not have…
juffel
  • 685
  • 9
  • 19
2
votes
0 answers

JPA issue 2 attributes mapped to same column InvalidStateException: Attempt to set column to two different values

I have the following problem, I have the folowing classes: class C(){ ... @ManyToOne @JoinColumns({ @JoinColumn(name = "B_FK", referencedColumnName = "B_ID"), @JoinColumn(name = "A_FK", referencedColumnName = "A_ID")}) …
Olli Paq
  • 31
  • 4
1
2 3 4 5