I have entity User which contains field with entity Actor which contains field with entity Product. Now I want User in database to have information about product id that's being stored in Actor using @JoinColum on Product. For better clarification, some code:
@Entity
public class User {
@ManyToOne
@JoinColumns(value = {@JoinColumn(name = "actor_id", referencedColumnName = "id"),
@JoinColumn(name = "product_id", referencedColumnName = "product_id")})
private Actor actor;
public Actor getActor() {
return actor;
}
public void setActor(Actor actor) {
this.actor = actor;
}
}
@Entity
public class Actor {
@ManyToOne
@JoinColumn(name = "product_id")
private Product product;
}
In database it creates table "users" with "actor_id" and "product_id" and table "actors" with column "product_id".
Using Spring Data Repository's userRepository.findAll() method I end up with ClassCastException and the following message:
Actor_$$_jvst485_0 cannot be cast to java.io.Serializable
Any ideas how to fix it?