I have two entities: PlayerProfileEntity & UserInfoEntity I have a join on userInfoEntity & PlaterProfileEntity and saving my record in database like this:
Session session = sessionFactory.openSession();
Transaction tr = session.beginTransaction();
Criteria crit = session.createCriteria(PlayerProfileEntity.class);
player.setUserId(new UserInfoEntity());
player.getUserId().setAddress(user.getUserId().getAddress());
session.save(player);
tr.commit();
I used this assosiation in my PlayerProfileEntity class
@ManyToOne (fetch = FetchType.LAZY)
@Cascade({CascadeType.REFRESH})
@JoinColumn(name="userid")
I am getting this error:
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.shared.entity.UserInfoEntity
Note : If i use CascadeType.All, i get this error:
Cannot add or update a child row: a foreign key constraint fails
Any idea how can i solve this
Thanks