Hello,
Here is some minor enhancements I would like to acheive considering SQL queries generated by Hibernate.
I use
Hibernate 3.1, Hibernate Annotation 3.1 beta 7, Hibernate entity manager 3.1 beta 5.
The example : an employee (class Employee) has an address (class Address) and many qualifications (class Qualification).
The mapping (in the Employee class) :
Code:
@OneToOne(targetEntity = Address.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "ID_ADDRESS")
public IAddress getAddress()
{
return address;
}
@OneToMany(targetEntity = Qualification.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "ID_EMPLOYEE", nullable = false)
public Collection<IQualification> getQualifications()
{
return qualifications;
}
When I delete an employee (using 'remove' method defined in javax.persistence.EntityManager) :
DEBUG | org.hibernate.SQL | 346 | delete from T_QUALIFICATION where ID_QUALIFICATION=?
DEBUG | org.hibernate.SQL | 346 | delete from T_QUALIFICATION where ID_QUALIFICATION=?
DEBUG | org.hibernate.SQL | 346 | delete from T_EMPLOYEE where ID_EMPLOYEE=?
DEBUG | org.hibernate.SQL | 346 | delete from T_ADDRESS where ID_ADDRESS=?
Idealy there would only be 1 query to delete qualifications (delete from T_QUALIFICATION where ID_EMPLOYEE=?)
Is there a way to optimize the mapping ?
More over, whatever the value of the updatable property (see annotation on getQualifications() ), I cannot clear the collection by updating the employee (employee.getQualifications().clear() before persist(employee) has no effect).
Any idea ? Of course I can work outside the employee object graph and delete qualifications in a new dedicated transaction.
Anyway congratulation for the framework.
Gengis