Search in sources :

Example 1 with BookISBNReferenceEntity

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

the class NonPrimaryKeyJoinColumnTest method testNonPrimaryKeySingleValuedAssociationIdInUpdate.

// NOTE: No JPA provider supports the optimized natural id access and only EclipseLink and Hibernate seem to support natural ids
@Test
@Category({ NoHibernate42.class, NoHibernate43.class, NoHibernate50.class, NoHibernate51.class, NoHibernate52.class, NoHibernate53.class, NoEclipselink.class, NoDatanucleus.class, NoOpenJPA.class })
public void testNonPrimaryKeySingleValuedAssociationIdInUpdate() {
    Person owner = new Person("p1");
    BookEntity bookEntity = new BookEntity();
    bookEntity.setOwner(owner);
    bookEntity.setIsbn("123");
    em.persist(owner);
    em.persist(bookEntity);
    UpdateCriteriaBuilder<BookISBNReferenceEntity> cb1 = cbf.update(em, BookISBNReferenceEntity.class, "r").setExpression("version", "r.version + 1").where("r.book.isbn").eq(bookEntity.getIsbn());
    UpdateCriteriaBuilder<BookISBNReferenceEntity> cb2 = cbf.update(em, BookISBNReferenceEntity.class, "r").setExpression("version", "r.version + 1").where("r.book").eq(bookEntity);
    assumeTrue(jpaProvider.supportsSingleValuedAssociationIdExpressions());
    assumeTrue(jpaProvider.supportsSingleValuedAssociationNaturalIdExpressions());
    assertEquals("UPDATE BookISBNReferenceEntity r SET r.version = r.version + 1 WHERE r.book.isbn = :param_0", cb1.getQueryString());
    assertEquals("UPDATE BookISBNReferenceEntity r SET r.version = r.version + 1 WHERE r.book = :param_0", cb2.getQueryString());
    cb1.executeUpdate();
    cb2.executeUpdate();
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookISBNReferenceEntity(com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity) Person(com.blazebit.persistence.testsuite.entity.Person) Category(org.junit.experimental.categories.Category) Test(org.junit.Test)

Example 2 with BookISBNReferenceEntity

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

the class AbstractBookEntityViewTest method prepareData.

@Override
protected void prepareData(EntityManager em) {
    Person p1 = new Person("pers1");
    BookEntity b1 = new BookEntity();
    b1.setOwner(p1);
    b1.setIsbn("123");
    BookEntity b2 = new BookEntity();
    b2.setOwner(p1);
    b2.setIsbn("456");
    BookEntity b3 = new BookEntity();
    b3.setOwner(p1);
    b3.setIsbn("789");
    e1 = new NaturalIdJoinTableEntity();
    e1.setVersion(1L);
    e1.setOwner(p1);
    e1.setIsbn("123");
    e1.getManyToManyBook().put("b1", b1);
    e1.getManyToManyBook().put("b2", b2);
    e1.getOneToManyBook().add(b1);
    e1.getOneToManyBook().add(b2);
    e2 = new BookISBNReferenceEntity();
    e2.setVersion(1L);
    e2.setBook(b1);
    e2.setBookNormal(b2);
    em.persist(p1);
    em.persist(b1);
    em.persist(b2);
    em.persist(b3);
    em.persist(e1);
    em.persist(e2);
}
Also used : BookEntity(com.blazebit.persistence.testsuite.entity.BookEntity) BookISBNReferenceEntity(com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity) Person(com.blazebit.persistence.testsuite.entity.Person) NaturalIdJoinTableEntity(com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)

Aggregations

BookEntity (com.blazebit.persistence.testsuite.entity.BookEntity)2 BookISBNReferenceEntity (com.blazebit.persistence.testsuite.entity.BookISBNReferenceEntity)2 Person (com.blazebit.persistence.testsuite.entity.Person)2 NaturalIdJoinTableEntity (com.blazebit.persistence.testsuite.entity.NaturalIdJoinTableEntity)1 Test (org.junit.Test)1 Category (org.junit.experimental.categories.Category)1