|
Hibernate example source code file (QueryingWithProxyObjectTest.java)
The Hibernate QueryingWithProxyObjectTest.java source codepackage org.hibernate.envers.test.integration.proxy; import org.hibernate.MappingException; import org.hibernate.envers.test.AbstractSessionTest; import org.hibernate.envers.test.Priority; import org.hibernate.envers.test.entities.StrTestEntity; import org.hibernate.testing.TestForIssue; import org.junit.Assert; import org.junit.Test; import java.net.URISyntaxException; import java.util.Arrays; import java.util.List; /** * @author Lukasz Antoniak (lukasz dot antoniak at gmail dot com) */ public class QueryingWithProxyObjectTest extends AbstractSessionTest { private Integer id = null; @Override protected void initMappings() throws MappingException, URISyntaxException { config.addAnnotatedClass(StrTestEntity.class); } @Test @Priority(10) public void initData() { // Revision 1 getSession().getTransaction().begin(); StrTestEntity ste = new StrTestEntity("data"); getSession().persist(ste); getSession().getTransaction().commit(); id = ste.getId(); } @Test @TestForIssue(jiraKey="HHH-4760") @SuppressWarnings("unchecked") public void testQueryingWithProxyObject() { StrTestEntity originalSte = new StrTestEntity("data", id); // Load the proxy instance StrTestEntity proxySte = (StrTestEntity) getSession().load(StrTestEntity.class, id); Assert.assertTrue(getAuditReader().isEntityClassAudited(proxySte.getClass())); StrTestEntity ste = getAuditReader().find(proxySte.getClass(), proxySte.getId(), 1); Assert.assertEquals(originalSte, ste); List<Number> revisions = getAuditReader().getRevisions(proxySte.getClass(), proxySte.getId()); Assert.assertEquals(Arrays.asList(1), revisions); List<StrTestEntity> entities = getAuditReader().createQuery().forEntitiesAtRevision(proxySte.getClass(), 1).getResultList(); Assert.assertEquals(Arrays.asList(originalSte), entities); ste = (StrTestEntity) getAuditReader().createQuery().forRevisionsOfEntity(proxySte.getClass(), true, false).getSingleResult(); Assert.assertEquals(originalSte, ste); ste = (StrTestEntity) getAuditReader().createQuery().forEntitiesModifiedAtRevision(proxySte.getClass(), 1).getSingleResult(); Assert.assertEquals(originalSte, ste); } } Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate QueryingWithProxyObjectTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.