Search in sources :

Example 1 with EmbeddableTestEntityId

use of com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId in project blaze-persistence by Blazebit.

the class UpdateEmbeddableComplexTest method testUpdateWithReturningExplicitId.

@Test
// TODO: report that datanucleus doesn't support element collection in an embeddable
@Category({ NoH2.class, NoOracle.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testUpdateWithReturningExplicitId() {
    final String intIdEntity1Key = "1";
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable2Id = new EmbeddableTestEntityId("1", "2");
            EmbeddableTestEntity embeddable2 = new EmbeddableTestEntity();
            embeddable2.setId(embeddable2Id);
            em.persist(embeddable2);
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", intIdEntity1Key);
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            EmbeddableTestEntityEmbeddable embeddable1Embeddable = new EmbeddableTestEntityEmbeddable();
            embeddable1Embeddable.setManyToOne(embeddable2);
            embeddable1.setEmbeddable(embeddable1Embeddable);
            em.persist(embeddable1);
            em.flush();
            EmbeddableTestEntityId manyToOneId = cbf.update(em, EmbeddableTestEntity.class, "e").set("id.key", "newKey").where("e.id.key").eq(intIdEntity1Key).executeWithReturning("embeddable.manyToOne.id", EmbeddableTestEntityId.class).getLastResult();
            assertEquals(embeddable2Id, manyToOneId);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityEmbeddable(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityEmbeddable) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with EmbeddableTestEntityId

use of com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId in project blaze-persistence by Blazebit.

the class UpdateEmbeddableComplexTest method testUpdateWithReturningEmbeddable.

@Test
// TODO: report that datanucleus doesn't support element collection in an embeddable
@Category({ NoH2.class, NoOracle.class, NoSQLite.class, NoFirebird.class, NoMySQL.class, NoDatanucleus.class, NoEclipselink.class, NoOpenJPA.class })
public void testUpdateWithReturningEmbeddable() {
    final String newEmbeddableTestEntityIdKey = "newKey";
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", "oldKey");
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            em.persist(embeddable1);
            em.flush();
            String key = cbf.update(em, EmbeddableTestEntity.class, "e").set("id.key", newEmbeddableTestEntityIdKey).executeWithReturning("id.key", String.class).getLastResult();
            assertEquals(newEmbeddableTestEntityIdKey, key);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 3 with EmbeddableTestEntityId

use of com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId in project blaze-persistence by Blazebit.

the class EmbeddedCorrelationTest method setUpOnce.

@Override
protected void setUpOnce() {
    cleanDatabase();
    transactional(new TxVoidWork() {

        @Override
        public void work(EntityManager em) {
            EmbeddableTestEntityId embeddable1Id = new EmbeddableTestEntityId("1", "oldKey");
            EmbeddableTestEntity embeddable1 = new EmbeddableTestEntity();
            embeddable1.setId(embeddable1Id);
            em.persist(embeddable1);
        }
    });
}
Also used : EmbeddableTestEntity(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity) EntityManager(javax.persistence.EntityManager) TxVoidWork(com.blazebit.persistence.testsuite.tx.TxVoidWork) EmbeddableTestEntityId(com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId)

Aggregations

EmbeddableTestEntity (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntity)3 EmbeddableTestEntityId (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityId)3 TxVoidWork (com.blazebit.persistence.testsuite.tx.TxVoidWork)3 EntityManager (javax.persistence.EntityManager)3 Test (org.junit.Test)2 Category (org.junit.experimental.categories.Category)2 EmbeddableTestEntityEmbeddable (com.blazebit.persistence.testsuite.entity.EmbeddableTestEntityEmbeddable)1