Hi,
I'm trying to make hibernate execute an insert with an already queried key. I have the GeneratedValue. But in this specific useCase I get the sequenceValue before the insert, then when I try to insert using this ID I got this error:
org.hibernate.PersistentObjectException: detached entity passed to persist
Is there any way to indicate to hibernate when it should execute an insert or an update?
The code is something like this:
Code:
Entity:
@Entity
public class Content implements Serializable, EntityIF {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="CONTENT_CONTENTID_GENERATOR", sequenceName="S_CONTENT_ID")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="CONTENT_CONTENTID_GENERATOR")
@Column(name="content_id")
private Long id;
}
Code:
public Business () {
public Save() {
Long id = getNewId();
//do some logic
Content content = new Content();
content.setId(id);
entityManager.getCurrentSession().persist(content);
}
}