Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.3.1
Mapping documents:
Annotations
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
ERROR AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: compta.entities.Poste
...
Name and version of the database you are using:
Mysql 5.5
The generated SQL (show_sql=true):
Hibernate: update lignecompta set accountid=?, dtpay=?, libelle=?, pointed=?, posteid=?, valeur=? where id=?
I want to update an Object called lignecompta.
This object contains another object called Poste, link with posteid.
This object is directly got from the DB and put in the lignecompta object.
An when I want to update the "lignecompta" object, I got the error.
The reason is really because I set the Poste object from a previously loaded object. I can "evict" it from the session, but it's not clean.
--------- Annotations for ligne compta ------------
@Entity
@Table (name="lignecompta")
public class LigneCompta implements Serializable{
...
@ManyToOne(optional=true)
@JoinColumn(name="posteid", nullable=true)
public Poste getPoste() {
return poste;
}
}
-------- Thes Poste object is got using: ---------
public List<Poste> getPostes(User u) {
Session session = this.getSession();
//session.beginTransaction();
Criteria crit = session.createCriteria(Poste.class);
crit.add(Restrictions.eq("ownerid", u.getId()));
List<Poste> postes= crit.list();
return postes;
}
-------- Ths lignecompta object is saved using -------
@Transactional // spring transactionnal
public void updateLigne(LigneCompta lc) {
Session session = this.getSession();
session.update(lc); // error is raised here
}
Hope I will get help because I don't see the pb.
Regards
Francillo