@Test
public void testDeserializedEntityNotImplicitlyManaged() throws Exception {
EntityTransaction transaction = em.getTransaction();
transaction.begin();
SerializableEntity serializableEntity = new SerializableEntity();
serializableEntity.setName("NegativeDetachPersistTest.testDeserializedEntityIsDetached");
em.persist(serializableEntity);
Assert.assertTrue(em.contains(serializableEntity),
"serializableEntity was just persisted by the EntityManager, but it is not managed.");
out.writeObject(serializableEntity);
Assert.assertTrue(em.contains(serializableEntity),
"serializableEntity was persisted by the EntityManager and should still be managed.");
byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
in = new ObjectInputStream(byteArrayInputStream);
SerializableEntity deserializedSerializableEntity = (SerializableEntity) in.readObject();
Assert.assertTrue(em.contains(serializableEntity),
"serializableEntity was just persisted by the EntityManager, but it is not managed.");
Assert.assertFalse(em.contains(deserializedSerializableEntity), "deserializedSerializableEntity should not be managed.");