Marcin Petrów
Marcin Petrów

Reputation: 1497

JPA: single database field, multiple times in different fomr on that same Entity

Like in a topic... How can I get that same field from database in one single entity but in two different types....

i.e.

@Entity
@Table(name = "ROOMS")
public class Rooms implements Serializable {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_ROOM")

private int idRoom;

@ManyToOne
@JoinColumn(name = "ID_HOTEL")
private Hotel hotel;
//and right here I need a something like

@JoinColumn(name = "ID_HOTEL")
private int hotelId;

but.... I need it only for doing some searches using EL... I dont need it for inserting or updateing....

Upvotes: 2

Views: 2263

Answers (1)

James
James

Reputation: 18379

Your hotelId is a @Basic, so you must use @Column not @JoinColumn. You should also set one of the columns as insertable/updateable=false, as you are mapping it twice.

Upvotes: 4

Related Questions