you shouldn't persist any object from hibernate

       @ApplicationState
       private Customer _customer;

same object will be referenced in you second request,
and the second request will have different session,

tapestry-hibernate integration is still basic,
and for now you should just change the above
code to persist Cutomer.id and fetch the customer
using the session in each request...

Davor Hrg

On 10/3/07, T. Papke <[EMAIL PROTECTED]> wrote:
>
> 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
>

Reply via email to