title: Hibernate: illegally attempted to associate a proxy with two open Sessions
body: <p>I have 2 methods:</p>
  
  <pre><code>public static Ticket issueTicket(User user,Service service,String[] seats) {
      Session ticSess= DB.factory.openSession();
      ticSess.beginTransaction();
      Date d= new Date();
      Ticket ticket=new Ticket(d, service, user);
  
      ticSess.save(ticket);
      ticSess.getTransaction().commit();
      int seatCount=seats.length;
      for (int i=0;i&lt;seatCount;i++){
          int seatID=Integer.parseInt(seats[i]);
          Seat seat=getSeatByID(seatID);
          seat.setTicket(ticket);
          ticSess.update(seat);
      }
      return ticket;
  
  
  }
  </code></pre>
  
  <p>and,</p>
  
  <pre><code>public static Seat getSeatByID(int seatID) {
      Session proSess = DB.factory.openSession();
      proSess.beginTransaction();
      Seat c = (Seat) (proSess.load(Seat.class, seatID));
      proSess.getTransaction().commit();
  
      return c;
  }
  </code></pre>
  
  <p>when I call issueTicket method I get:</p>
  
  <pre><code>illegally attempted to associate a proxy with two open Sessions
  </code></pre>
  
  <p>and If I close the session in getSeatByID method there will be another error telling that the session is closed. Here is the Stack Trace:</p>
  
  <pre><code>at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:164)
  at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:285)
  at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
  at ir.ac.shirazu.cse.Terminal.Seat_$$_javassist_9.setTicket(Seat_$$_javassist_9.java)
  at ir.ac.shirazu.cse.Database.DB.issueTicket(DB.java:231)
  </code></pre>