I am doing some tests with hibernate but the rollback seems to not be working with the Mysql database MyISAM.
I have an Entity called “Person”, that have a property poiting to same class (Person)
like this:
@Entity
public class Person {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "pessoa_id")
private Person conjuge;
@Column(unique = true)
private String document;
}
Then I have a generic DAO:
public void save( T entity ){
try {
getCurrentSession().beginTransaction();
getCurrentSession().saveOrUpdate( entity );
getCurrentSession().getTransaction().commit();
} catch (Exception e) {
getCurrentSession().getTransaction().rollback();
System.out.print(e.getMessage());
System.out.print("error............");
}
}
When I set the Person.conjuge property to another Person and call this save method, and if I set the main person with the same document property it will throw an excpetion, because the field “document” is unique, and it is ok.
But that rollback is not working and the conjuge Person continues being inserted into the table,
What am I missing here?