cat.setAge( 3 );
cat.setDateOfBirth( new Date() );
cat.setLength( 22 );
cat.setName( "Kitty" );
em.persist( cat );
Item item = new Item();
item.setName( "Train Ticket" );
item.setDescr( "Paris-London" );
em.persist( item );
//em.getTransaction().commit();
//em.getTransaction().begin();
item.setDescr( "Paris-Bruxelles" );
//em.getTransaction().commit();
//fake the in container work
( (HibernateEntityManager) em ).getSession().disconnect();
stream = new ByteArrayOutputStream();
out = new ObjectOutputStream( stream );
out.writeObject( em );
out.close();
serialized = stream.toByteArray();
stream.close();
byteIn = new ByteArrayInputStream( serialized );
in = new ObjectInputStream( byteIn );
em = (EntityManager) in.readObject();
in.close();
byteIn.close();
//fake the in container work
em.getTransaction().begin();
item = em.find( Item.class, item.getName() );
item.setDescr( item.getDescr() + "-Amsterdam" );
cat = (Cat) em.createQuery( "select c from " + Cat.class.getName() + " c" ).getSingleResult();
cat.setLength( 34 );
em.flush();
em.remove( item );
em.remove( cat );