-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: child collections manipulation
PostPosted: Wed Jan 11, 2006 10:56 am 
Newbie

Joined: Wed Jun 15, 2005 9:18 am
Posts: 11
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.