Hi,
i have tried the tapestry-hibernate package to handle my hibernate
sessions. I have setup the package in maven and add the hibernate
Session to all constructors of my services.
I started with my CustomerService getting and setting my customerbeans
(each of them having a Set of AddressBeans). After first time saving a
customer, everything works fine. If i do the saveOrUpdate again in a
second request (because i want to change something), i got:
/*"Illegal attempt to associate a collection with two open sessions"*/
I googled a lot, but i do not find the answer??
I thought the tapestry-hibernate module open one session per request? It
seems so that the session from the previous request is still open?
*service -->*
public class CustomerFactoryImpl implements CustomerFactory{
private Session hibernateSession = null;
public CustomerFactoryImpl(Session session){
this.hibernateSession=session;
}
public void setCustomer(Customer customer) {
hibernateSession.saveOrUpdate(customer);
}
}
*page -->*
public class CustomerData {
@Inject
private CustomerFactory customerFactory;
@ApplicationState
private Customer _customer;
public void onSuccess(){
customerFactory.setCustomer(_customer);
}
....
}
*bean --->*
@Entity
public class Customer{
@Id
@GeneratedValue
private long id;
... lots of simple attributes ....
@OneToMany
@Cascade(CascadeType.ALL)
private Set<Address> address= new HashSet<Address>();
.... access methods to addresses ...
}
It seems so simple, but i don't know whats going wrong? Anyone an idea?
Thanks a lot,
Thomas