Questions tagged [joincolumn]

82 questions
9
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
  • 172
  • 1
  • 5
  • 10
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,478
  • 4
  • 18
  • 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
  • 193
  • 1
  • 3
  • 16
6
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,938
  • 7
  • 37
  • 57
5
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
  • 63
  • 1
  • 6
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,873
  • 14
  • 49
  • 72
4
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 =…
Limpep
  • 499
  • 3
  • 11
  • 22
4
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,731
  • 11
  • 47
  • 73
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…
Andrea Alciato
  • 199
  • 1
  • 11
2
votes
1 answer

Hibernate: ManyToOne / multiple join columns with one column nullable=true

I hope you can help me on that. Table A has a multi-column join to Table B where one of the JoinColumns can be nullable... @Entity @Table(name = "TABLE_A") public class TableA { @ManyToOne(fetch = FetchType.EAGER, optional = false) @JoinColumns({ …
NeoP5
  • 611
  • 7
  • 19
2
votes
0 answers

Best practice for using @Column and @JoinColumn for same field

I've got two different scenarios where I have to retrieve data from one or two entities that have a relation between them. @Entity @Table public class Level2 { @Id @Column(name = "id_level_2") private Integer idLevel2; @Column(name…
Rachel
  • 65
  • 11
2
votes
0 answers

Hibernate SQL @JoinColumn generates null

I am using @JoinColumn Annotation in order to join two tables, but the linking results in a null value. What am I doing wrong? Is there any way to debug the linking process? Maybe it has something to do with sql database, I mean that no linking can…
2
votes
1 answer

Hibernate (Spring JPA): @ManyToOne JoinColumns (which are an EmbeddedId) are null

I didn't see my error and after a research on stackoverflow and Google I think the code should be correct. But Hibernate (spring-boot-starter-data-jpa 2.2.4) still fill the JoinColumns with null. Here is my OneToMany class: @Entity @Table(name =…
INJG
  • 71
  • 7
2
votes
1 answer

How to create and link a child entity in an unidirectional relationship by a non-nullable join column using Spring-Data-Rest

I can't figure out how to add a child entity (lets say a comment entity to a parent post entity) using Spring-Data-Rest when the relationship between them is one-to-many + unidirectional (specifically from the parent to the child) and when the…
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
  • 2
1
2 3 4 5 6