Package com.force.sdk.jpa.entities

Examples of com.force.sdk.jpa.entities.SerializableEntity


    @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.");
View Full Code Here


    public void testMergeDeserializedEntityForPersistedSerializedEntityInSingleTransaction() throws Exception {
        try {
            EntityTransaction transaction = em.getTransaction();
            transaction.begin();

            SerializableEntity serializableEntity = new SerializableEntity();
            serializableEntity.setName("Test" + String.valueOf(new Random().nextInt(10000)));

            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();

            em.merge(deserializedSerializableEntity);

            Assert.fail("A deserialized entity cannot be merged for a managed entity with the same identity.");
        } catch (PersistenceException pe) {
View Full Code Here

    @Test
    public void testMergeDeserializedEntityForPersistedSerializedEntityInTwoTransactions() throws Exception {
        EntityTransaction transaction = em.getTransaction();
        transaction.begin();

        SerializableEntity serializableEntity = new SerializableEntity();
        serializableEntity.setName("Test" + String.valueOf(new Random().nextInt(10000)));

        em.persist(serializableEntity);
        Assert.assertTrue(em.contains(serializableEntity),
                "serializableEntity was just persisted by the EntityManager, but it is not managed.");

        transaction.commit();

        Assert.assertFalse(em.contains(serializableEntity), "serializableEntity was committed, but is still managed.");

        transaction = em.getTransaction();
        transaction.begin();

        out.writeObject(serializableEntity);

        byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        in = new ObjectInputStream(byteArrayInputStream);
        SerializableEntity deserializedSerializableEntity = (SerializableEntity) in.readObject();

        em.merge(deserializedSerializableEntity);

        transaction.commit();
    }
View Full Code Here

TOP

Related Classes of com.force.sdk.jpa.entities.SerializableEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.