From c987deb619fccc9521b44d51ab2ce2388d9f0208 Mon Sep 17 00:00:00 2001 From: Adam Warski Date: Wed, 30 Sep 2009 17:11:04 +0000 Subject: [PATCH] HHH-4447: - applying patches git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@17586 1b8cb986-b30d-0410-93ca-fae66ebed9b2 --- .../mapper/relation/ToOneIdMapper.java | 2 +- .../integration/proxy/ProxyIdentifier.java | 90 +++++++++++++++++++ envers/src/test/resources/testng.xml | 1 + 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java diff --git a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java index 953cab2c66..cf3dd65ec3 100644 --- a/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java +++ b/envers/src/main/java/org/hibernate/envers/entities/mapper/relation/ToOneIdMapper.java @@ -82,7 +82,7 @@ public class ToOneIdMapper implements PropertyMapper { Class entityClass = ReflectionTools.loadClass(referencedEntityName); value = versionsReader.getSessionImplementor().getFactory().getEntityPersister(referencedEntityName). - createProxy(null, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg)); + createProxy((Serializable)entityId, new ToOneDelegateSessionImplementor(versionsReader, entityClass, entityId, revision, verCfg)); } } diff --git a/envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java b/envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java new file mode 100644 index 0000000000..e495283c58 --- /dev/null +++ b/envers/src/test/java/org/hibernate/envers/test/integration/proxy/ProxyIdentifier.java @@ -0,0 +1,90 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as + * indicated by the @author tags or express copyright attribution + * statements applied by the authors. All third-party contributions are + * distributed under license by Red Hat Middleware LLC. + * + * This copyrighted material is made available to anyone wishing to use, modify, + * copy, or redistribute it subject to the terms and conditions of the GNU + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ +package org.hibernate.envers.test.integration.proxy; + +import org.hibernate.ejb.Ejb3Configuration; + +import org.hibernate.envers.test.AbstractEntityTest; +import org.hibernate.envers.test.entities.UnversionedStrTestEntity; +import org.hibernate.envers.test.entities.manytoone.unidirectional.TargetNotAuditedEntity; + +import org.hibernate.proxy.HibernateProxy; +import org.hibernate.proxy.LazyInitializer; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import javax.persistence.EntityManager; + + +/** + * @author Eugene Goroschenya + */ +public class ProxyIdentifier extends AbstractEntityTest { + private TargetNotAuditedEntity tnae1; + private UnversionedStrTestEntity uste1; + + public void configure(Ejb3Configuration cfg) { + cfg.addAnnotatedClass(TargetNotAuditedEntity.class); + cfg.addAnnotatedClass(UnversionedStrTestEntity.class); + } + + @BeforeClass(dependsOnMethods = "init") + public void initData() { + EntityManager em = getEntityManager(); + + uste1 = new UnversionedStrTestEntity("str1"); + + // No revision + em.getTransaction().begin(); + em.persist(uste1); + em.getTransaction().commit(); + + // Revision 1 + em.getTransaction().begin(); + uste1 = em.find(UnversionedStrTestEntity.class, uste1.getId()); + tnae1 = new TargetNotAuditedEntity(1, "tnae1", uste1); + em.persist(tnae1); + em.getTransaction().commit(); + } + + @Test + public void testProxyIdentifier() { + TargetNotAuditedEntity rev1 = getAuditReader().find(TargetNotAuditedEntity.class, tnae1.getId(), 1); + + assert rev1.getReference() instanceof HibernateProxy; + + HibernateProxy proxyCreateByEnvers = (HibernateProxy) rev1.getReference(); + LazyInitializer lazyInitializer = proxyCreateByEnvers.getHibernateLazyInitializer(); + + assert lazyInitializer.isUninitialized(); + assert lazyInitializer.getIdentifier() != null; + assert lazyInitializer.getIdentifier().equals(tnae1.getId()); + assert lazyInitializer.isUninitialized(); + + assert rev1.getReference().getId().equals(uste1.getId()); + assert rev1.getReference().getStr().equals(uste1.getStr()); + assert !lazyInitializer.isUninitialized(); + } +} diff --git a/envers/src/test/resources/testng.xml b/envers/src/test/resources/testng.xml index 995c13faaf..447ddb5667 100644 --- a/envers/src/test/resources/testng.xml +++ b/envers/src/test/resources/testng.xml @@ -45,6 +45,7 @@ +