I want to link two entities with a many-to-one link, but so that the class of the many entity does not store a reference to an object of the class one.
In general, I want something like this:
@Entity(name = "A") @Table(name = "As") public class A implements Serializable { @Id @Column(name = "A_id") @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; } @Entity(name = "B") @Table(name = "Bs") public class B implements Serializable { @Id @Column(name = "B_id") @GeneratedValue(strategy = GenerationType.IDENTITY) private long id; @ManyToOne(targetEntity = A.class) @JoinColumn(name = "A_id", referencedColumnName = "A_id") private long owner; } Here, instead of object A the value of its id is stored in the field owner .
However, when I try to use such code ( session.save(objectB); ), I get exceptions from the Error accessing field series.
All setters are setters.
So the question is: How can we connect two classes of only one field so that there are no such problems?
PS I need exactly
private long owner; but not
private A owner;