I have the same issue, i reduce the problem to this simple case reproducing the exception :
Mapping :
(standard mapping, found in https://docs.jboss.org/hibernate/orm/3.3/reference/fr-FR/html/associations.html)Code:
<class name="Person" table="tperson">
<id name="id" column="personpk">
<generator class="native"/>
</id>
<set name="addresses"
table="personaddress">
<key column="personid"/>
<many-to-many column="addressid"
unique="true"
class="Address"/>
</set>
</class>
<class name="Address" table="taddress">
<id name="id" column="addresspk">
<generator class="native"/>
</id>
<join table="personaddress"
inverse="true"
optional="true">
<key column="addressid"/>
<many-to-one name="person"
column="personid"
not-null="true"/>
</join>
</class>
Classes :
Code:
public class Address {
private Long id;
private Person person;
public Address() {}
public Address(Long id) {
this.id = id;
}
public void setPerson(Person person) {
this.person = person;
}
}
public class Person {
private Long id;
private Collection<Address> addresses;
public Person() {}
public Person(Long id) {
this.id = id;
}
public void addAddress(Address address) {
if (addresses == null) {
addresses = new HashSet<Address>();
}
addresses.add(address);
}
}
Test :
Code:
//create conditions
Transaction transaction = session.session.beginTransaction();
Person person = new Person(idPers);
Address address = new Address(idAddr);
address.setPerson(person);
person.addAddress(address);
session.save(person);
session.save(address);
transaction.commit();
session.clear();
//Now, reproduction of problem
session.beginTransaction();
//this call is necessary for reproduction of problem
session.get(Address.class, idAddr);
Person reloadedPerson = (Person) session.get(Person.class, idPers);
session.delete(reloadPerson);
//Here the exception
Person expectedNullPerson= (Person) session.get(Person.class, idPers);
Calling session.get(Address.class, idAddr); make reloadedPerson a javassit, when it is not called, "expectedNullPerson" is null like expected.
[Edit] We use hibernate 4.1.11 but i also reproduce it with hibernate 4.2.0