Hibernate SVN: r19751 - in core/branches/Branch_3_5/envers/src: test/java/org/hibernate/envers/test/entities/components and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-06-16 14:11:44 -0400 (Wed, 16 Jun 2010)
New Revision: 19751
Added:
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java
core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java
Modified:
core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
Log:
HHH-5288:
- applying patch by Erik-Berndt Scheper - thanks!
- Envers auditReader.find() returns wrong data for embedded components using fields with default values
Modified: core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
===================================================================
--- core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-16 18:06:57 UTC (rev 19750)
+++ core/branches/Branch_3_5/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-16 18:11:44 UTC (rev 19751)
@@ -24,19 +24,19 @@
package org.hibernate.envers.entities.mapper;
import java.io.Serializable;
+import java.lang.reflect.Field;
import java.util.List;
import java.util.Map;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.PropertyData;
-import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.envers.tools.reflection.ReflectionTools;
-
-import org.hibernate.collection.PersistentCollection;
import org.hibernate.property.Setter;
import org.hibernate.util.ReflectHelper;
-import org.hibernate.engine.SessionImplementor;
/**
* @author Adam Warski (adam at warski dot org)
@@ -84,8 +84,12 @@
}
}
- // And we don't have to set anything on the object - the default value is null
- if (!allNullAndSingle) {
+ if (allNullAndSingle) {
+ // single property, but default value need not be null, so we'll set it to null anyway
+ setter.set(obj, null, null);
+
+ } else {
+ // set the component
try {
Object subObj = ReflectHelper.getDefaultConstructor(
Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
@@ -97,7 +101,7 @@
}
}
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java 2010-06-16 18:11:44 UTC (rev 19751)
@@ -0,0 +1,68 @@
+package org.hibernate.envers.test.entities.components;
+
+import javax.persistence.Embedded;
+
+/**
+ *
+ * @author Erik-Berndt Scheper
+ *
+ */
+public class DefaultValueComponent1 {
+
+ private String str1;
+
+ @Embedded
+ private DefaultValueComponent2 comp2 = new DefaultValueComponent2();
+
+ public static final DefaultValueComponent1 of(String str1,
+ DefaultValueComponent2 comp2) {
+ DefaultValueComponent1 instance = new DefaultValueComponent1();
+ instance.setStr1(str1);
+ instance.setComp2(comp2);
+ return instance;
+ }
+
+ public String getStr1() {
+ return str1;
+ }
+
+ public void setStr1(String str1) {
+ this.str1 = str1;
+ }
+
+ public DefaultValueComponent2 getComp2() {
+ return comp2;
+ }
+
+ public void setComp2(DefaultValueComponent2 comp2) {
+ this.comp2 = comp2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponent1))
+ return false;
+
+ DefaultValueComponent1 that = (DefaultValueComponent1) o;
+
+ if (str1 != null ? !str1.equals(that.str1) : that.str1 != null)
+ return false;
+ if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str1 != null ? str1.hashCode() : 0);
+ result = 31 * result + (comp2 != null ? comp2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp1(str1 = " + str1 + ", comp2 = " + comp2 + ")";
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java 2010-06-16 18:11:44 UTC (rev 19751)
@@ -0,0 +1,64 @@
+package org.hibernate.envers.test.entities.components;
+
+/**
+ *
+ * @author Erik-Berndt Scheper
+ *
+ */
+public class DefaultValueComponent2 {
+
+ private String str1 = "defaultValue";
+
+ private String str2;
+
+ public static final DefaultValueComponent2 of(String str1, String str2) {
+ DefaultValueComponent2 instance = new DefaultValueComponent2();
+ instance.setStr1(str1);
+ instance.setStr2(str2);
+ return instance;
+ }
+
+ public String getStr2() {
+ return str2;
+ }
+
+ public void setStr2(String str2) {
+ this.str2 = str2;
+ }
+
+ public String getStr1() {
+ return str1;
+ }
+
+ public void setStr1(String str1) {
+ this.str1 = str1;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponent2))
+ return false;
+
+ DefaultValueComponent2 that = (DefaultValueComponent2) o;
+
+ if (str1 != null ? !str1.equals(that.str1) : that.str1 != null)
+ return false;
+ if (str2 != null ? !str2.equals(that.str2) : that.str2 != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str1 != null ? str1.hashCode() : 0);
+ result = 31 * result + (str2 != null ? str2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp2(str1 = " + str1 + ", str2 = " + str2 + ")";
+ }
+
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java 2010-06-16 18:11:44 UTC (rev 19751)
@@ -0,0 +1,111 @@
+/*
+ * 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.entities.components;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Erik-Berndt Scheper
+ */
+@Entity
+@Audited
+public class DefaultValueComponentTestEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Embedded
+ @Audited
+ @AttributeOverrides( { @AttributeOverride(name = "comp2.str1", column = @Column(name = "COMP2_STR1")) })
+ private DefaultValueComponent1 comp1 = null;
+
+ public DefaultValueComponentTestEntity() {
+ }
+
+ public static DefaultValueComponentTestEntity of(
+ DefaultValueComponent1 comp1) {
+ DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity();
+ instance.setComp1(comp1);
+ return instance;
+ }
+
+ public static DefaultValueComponentTestEntity of(Integer id,
+ DefaultValueComponent1 comp1) {
+ DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity();
+ instance.setId(id);
+ instance.setComp1(comp1);
+ return instance;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public DefaultValueComponent1 getComp1() {
+ return comp1;
+ }
+
+ public void setComp1(DefaultValueComponent1 comp1) {
+ this.comp1 = comp1;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponentTestEntity))
+ return false;
+
+ DefaultValueComponentTestEntity that = (DefaultValueComponentTestEntity) o;
+
+ if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null)
+ return false;
+ if (id != null ? !id.equals(that.id) : that.id != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (comp1 != null ? comp1.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CTE(id = " + id + ", comp1 = " + comp1 + ")";
+ }
+}
Added: core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java
===================================================================
--- core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java (rev 0)
+++ core/branches/Branch_3_5/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java 2010-06-16 18:11:44 UTC (rev 19751)
@@ -0,0 +1,383 @@
+/*
+ * 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.components;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.components.DefaultValueComponent1;
+import org.hibernate.envers.test.entities.components.DefaultValueComponent2;
+import org.hibernate.envers.test.entities.components.DefaultValueComponentTestEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Test class for components with default values.
+ *
+ * @see <a
+ * href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-5288">
+ * Hibernate JIRA </a>
+ *
+ * @author Erik-Berndt Scheper
+ */
+public class DefaultValueComponents extends AbstractEntityTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(DefaultValueComponents.class);
+
+ private Integer id0;
+ private Integer id1;
+ private Integer id2;
+ private Integer id3;
+ private Integer id4;
+ private Integer id5;
+ private Integer id6;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(DefaultValueComponentTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+
+ DefaultValueComponentTestEntity cte0 = DefaultValueComponentTestEntity
+ .of(null);
+
+ DefaultValueComponentTestEntity cte1 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of("c1-str1", null));
+
+ DefaultValueComponentTestEntity cte2 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of("c1-str1", DefaultValueComponent2
+ .of("c2-str1", "c2-str2")));
+
+ DefaultValueComponentTestEntity cte3 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ "c2-str1", "c2-str2")));
+
+ DefaultValueComponentTestEntity cte4 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ null, "c2-str2")));
+
+ DefaultValueComponentTestEntity cte5 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ "c2-str1", null)));
+
+ DefaultValueComponentTestEntity cte6 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ null, null)));
+
+ em.persist(cte0);
+ em.persist(cte1);
+ em.persist(cte2);
+ em.persist(cte3);
+ em.persist(cte4);
+ em.persist(cte5);
+ em.persist(cte6);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em = getEntityManager();
+ em.getTransaction().begin();
+
+ cte0 = em.find(DefaultValueComponentTestEntity.class, cte0.getId());
+ cte1 = em.find(DefaultValueComponentTestEntity.class, cte1.getId());
+ cte2 = em.find(DefaultValueComponentTestEntity.class, cte2.getId());
+ cte3 = em.find(DefaultValueComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(DefaultValueComponentTestEntity.class, cte4.getId());
+ cte5 = em.find(DefaultValueComponentTestEntity.class, cte5.getId());
+ cte6 = em.find(DefaultValueComponentTestEntity.class, cte6.getId());
+
+ cte0.setComp1(DefaultValueComponent1.of("upd-c1-str1", null));
+ cte1.setComp1(DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "upd-c2-str2")));
+ cte2.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte3.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte4.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte5.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte6.getComp1().getComp2().setStr1("upd-c2-str1");
+
+ em.getTransaction().commit();
+
+ // afterwards
+ id0 = cte0.getId();
+ id1 = cte1.getId();
+ id2 = cte2.getId();
+ id3 = cte3.getId();
+ id4 = cte4.getId();
+ id5 = cte5.getId();
+ id6 = cte6.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id0).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id1).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id2).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id3).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id4).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id5).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id6).toString());
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id0));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id1));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id2));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id3));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id4));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id5));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id6));
+ }
+
+ @Test
+ public void testHistoryOfId0() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id0, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id0, 2);
+
+ log.error("------------ id0 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ checkCorrectlyPersisted(id0, null, null);
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id0, DefaultValueComponent1.of(null, null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id0, DefaultValueComponent1.of("upd-c1-str1", null));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id1, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id1, 2);
+
+ log.error("------------ id1 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ checkCorrectlyPersisted(id1, null, "upd-c2-str1");
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id1, DefaultValueComponent1.of("c1-str1", null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id1, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "upd-c2-str2")));
+
+ assert ent2.equals(expectedVer2);
+ assert ent1.equals(expectedVer1);
+ }
+
+ @Test
+ public void testHistoryOfId2() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id2, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id2, 2);
+
+ log.error("------------ id2 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id2, DefaultValueComponent1.of("c1-str1",
+ DefaultValueComponent2.of("c2-str1", "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id2, DefaultValueComponent1.of("c1-str1",
+ DefaultValueComponent2.of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId3() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id3, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id3, 2);
+
+ log.error("------------ id3 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("c2-str1", "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId4() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id4, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id4, 2);
+
+ log.error("------------ id4 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of(null, "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId5() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id5, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id5, 2);
+
+ log.error("------------ id5 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("c2-str1", null)));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", null)));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId6() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id6, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id6, 2);
+
+ log.error("------------ id6 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id6, DefaultValueComponent1.of(null, null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id6, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", null)));
+
+ assert ent2.equals(expectedVer2);
+ assert ent1.equals(expectedVer1);
+ }
+
+ private void checkCorrectlyPersisted(Integer expectedId,
+ String expectedComp2Str1Rev1, String expectedComp2Str1Rev2) {
+ // Verify that the entity was correctly persisted
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ Long entCount = (Long) em.createQuery(
+ "select count(s) from DefaultValueComponentTestEntity s where s.id = "
+ + expectedId.toString()).getSingleResult();
+ BigInteger auditCount = (BigInteger) em.createNativeQuery(
+ "select count(ID) from DefaultValueComponentTestEntity_AUD s where s.id = "
+ + expectedId.toString()).getSingleResult();
+ String comp2Str1Rev1 = (String) em
+ .createNativeQuery(
+ "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=1 and s.id = "
+ + expectedId.toString()).getSingleResult();
+ String comp2Str1Rev2 = (String) em
+ .createNativeQuery(
+ "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=2 and s.id = "
+ + expectedId.toString()).getSingleResult();
+ assert Long.valueOf(1L).equals(entCount);
+ assert BigInteger.valueOf(2L).equals(auditCount);
+
+ if (expectedComp2Str1Rev1 == null) {
+ assert comp2Str1Rev1 == null;
+ } else {
+ assert expectedComp2Str1Rev1.equals(comp2Str1Rev1);
+ }
+
+ if (expectedComp2Str1Rev2 == null) {
+ assert comp2Str1Rev2 == null;
+ } else {
+ assert expectedComp2Str1Rev2.equals(comp2Str1Rev2);
+ }
+ em.getTransaction().commit();
+ }
+}
13 years, 10 months
Hibernate SVN: r19750 - in core/trunk/envers/src: test/java/org/hibernate/envers/test/entities/components and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: adamw
Date: 2010-06-16 14:06:57 -0400 (Wed, 16 Jun 2010)
New Revision: 19750
Added:
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java
core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java
Modified:
core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
Log:
HHH-5288:
- applying patch by Erik-Berndt Scheper - thanks!
- Envers auditReader.find() returns wrong data for embedded components using fields with default values
Modified: core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java
===================================================================
--- core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-16 16:29:16 UTC (rev 19749)
+++ core/trunk/envers/src/main/java/org/hibernate/envers/entities/mapper/ComponentPropertyMapper.java 2010-06-16 18:06:57 UTC (rev 19750)
@@ -27,16 +27,15 @@
import java.util.List;
import java.util.Map;
+import org.hibernate.collection.PersistentCollection;
+import org.hibernate.engine.SessionImplementor;
+import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.entities.PropertyData;
-import org.hibernate.envers.configuration.AuditConfiguration;
import org.hibernate.envers.exception.AuditException;
import org.hibernate.envers.reader.AuditReaderImplementor;
import org.hibernate.envers.tools.reflection.ReflectionTools;
-
-import org.hibernate.collection.PersistentCollection;
import org.hibernate.property.Setter;
import org.hibernate.util.ReflectHelper;
-import org.hibernate.engine.SessionImplementor;
/**
* @author Adam Warski (adam at warski dot org)
@@ -84,8 +83,11 @@
}
}
- // And we don't have to set anything on the object - the default value is null
- if (!allNullAndSingle) {
+ if (allNullAndSingle) {
+ // single property, but default value need not be null, so we'll set it to null anyway
+ setter.set(obj, null, null);
+ } else {
+ // set the component
try {
Object subObj = ReflectHelper.getDefaultConstructor(
Thread.currentThread().getContextClassLoader().loadClass(componentClassName)).newInstance();
@@ -97,7 +99,7 @@
}
}
- public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
+ public List<PersistentCollectionChangeData> mapCollectionChanges(String referencingPropertyName,
PersistentCollection newColl,
Serializable oldColl,
Serializable id) {
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent1.java 2010-06-16 18:06:57 UTC (rev 19750)
@@ -0,0 +1,68 @@
+package org.hibernate.envers.test.entities.components;
+
+import javax.persistence.Embedded;
+
+/**
+ *
+ * @author Erik-Berndt Scheper
+ *
+ */
+public class DefaultValueComponent1 {
+
+ private String str1;
+
+ @Embedded
+ private DefaultValueComponent2 comp2 = new DefaultValueComponent2();
+
+ public static final DefaultValueComponent1 of(String str1,
+ DefaultValueComponent2 comp2) {
+ DefaultValueComponent1 instance = new DefaultValueComponent1();
+ instance.setStr1(str1);
+ instance.setComp2(comp2);
+ return instance;
+ }
+
+ public String getStr1() {
+ return str1;
+ }
+
+ public void setStr1(String str1) {
+ this.str1 = str1;
+ }
+
+ public DefaultValueComponent2 getComp2() {
+ return comp2;
+ }
+
+ public void setComp2(DefaultValueComponent2 comp2) {
+ this.comp2 = comp2;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponent1))
+ return false;
+
+ DefaultValueComponent1 that = (DefaultValueComponent1) o;
+
+ if (str1 != null ? !str1.equals(that.str1) : that.str1 != null)
+ return false;
+ if (comp2 != null ? !comp2.equals(that.comp2) : that.comp2 != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str1 != null ? str1.hashCode() : 0);
+ result = 31 * result + (comp2 != null ? comp2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp1(str1 = " + str1 + ", comp2 = " + comp2 + ")";
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponent2.java 2010-06-16 18:06:57 UTC (rev 19750)
@@ -0,0 +1,64 @@
+package org.hibernate.envers.test.entities.components;
+
+/**
+ *
+ * @author Erik-Berndt Scheper
+ *
+ */
+public class DefaultValueComponent2 {
+
+ private String str1 = "defaultValue";
+
+ private String str2;
+
+ public static final DefaultValueComponent2 of(String str1, String str2) {
+ DefaultValueComponent2 instance = new DefaultValueComponent2();
+ instance.setStr1(str1);
+ instance.setStr2(str2);
+ return instance;
+ }
+
+ public String getStr2() {
+ return str2;
+ }
+
+ public void setStr2(String str2) {
+ this.str2 = str2;
+ }
+
+ public String getStr1() {
+ return str1;
+ }
+
+ public void setStr1(String str1) {
+ this.str1 = str1;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponent2))
+ return false;
+
+ DefaultValueComponent2 that = (DefaultValueComponent2) o;
+
+ if (str1 != null ? !str1.equals(that.str1) : that.str1 != null)
+ return false;
+ if (str2 != null ? !str2.equals(that.str2) : that.str2 != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (str1 != null ? str1.hashCode() : 0);
+ result = 31 * result + (str2 != null ? str2.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "Comp2(str1 = " + str1 + ", str2 = " + str2 + ")";
+ }
+
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/components/DefaultValueComponentTestEntity.java 2010-06-16 18:06:57 UTC (rev 19750)
@@ -0,0 +1,111 @@
+/*
+ * 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.entities.components;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.envers.Audited;
+
+/**
+ * @author Erik-Berndt Scheper
+ */
+@Entity
+@Audited
+public class DefaultValueComponentTestEntity {
+ @Id
+ @GeneratedValue
+ private Integer id;
+
+ @Embedded
+ @Audited
+ @AttributeOverrides( { @AttributeOverride(name = "comp2.str1", column = @Column(name = "COMP2_STR1")) })
+ private DefaultValueComponent1 comp1 = null;
+
+ public DefaultValueComponentTestEntity() {
+ }
+
+ public static DefaultValueComponentTestEntity of(
+ DefaultValueComponent1 comp1) {
+ DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity();
+ instance.setComp1(comp1);
+ return instance;
+ }
+
+ public static DefaultValueComponentTestEntity of(Integer id,
+ DefaultValueComponent1 comp1) {
+ DefaultValueComponentTestEntity instance = new DefaultValueComponentTestEntity();
+ instance.setId(id);
+ instance.setComp1(comp1);
+ return instance;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public DefaultValueComponent1 getComp1() {
+ return comp1;
+ }
+
+ public void setComp1(DefaultValueComponent1 comp1) {
+ this.comp1 = comp1;
+ }
+
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (!(o instanceof DefaultValueComponentTestEntity))
+ return false;
+
+ DefaultValueComponentTestEntity that = (DefaultValueComponentTestEntity) o;
+
+ if (comp1 != null ? !comp1.equals(that.comp1) : that.comp1 != null)
+ return false;
+ if (id != null ? !id.equals(that.id) : that.id != null)
+ return false;
+
+ return true;
+ }
+
+ public int hashCode() {
+ int result;
+ result = (id != null ? id.hashCode() : 0);
+ result = 31 * result + (comp1 != null ? comp1.hashCode() : 0);
+ return result;
+ }
+
+ public String toString() {
+ return "CTE(id = " + id + ", comp1 = " + comp1 + ")";
+ }
+}
Added: core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java
===================================================================
--- core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java (rev 0)
+++ core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/components/DefaultValueComponents.java 2010-06-16 18:06:57 UTC (rev 19750)
@@ -0,0 +1,383 @@
+/*
+ * 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.components;
+
+import java.math.BigInteger;
+import java.util.Arrays;
+
+import javax.persistence.EntityManager;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.components.DefaultValueComponent1;
+import org.hibernate.envers.test.entities.components.DefaultValueComponent2;
+import org.hibernate.envers.test.entities.components.DefaultValueComponentTestEntity;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Test class for components with default values.
+ *
+ * @see <a
+ * href="http://opensource.atlassian.com/projects/hibernate/browse/HHH-5288">
+ * Hibernate JIRA </a>
+ *
+ * @author Erik-Berndt Scheper
+ */
+public class DefaultValueComponents extends AbstractEntityTest {
+ private static final Logger log = LoggerFactory
+ .getLogger(DefaultValueComponents.class);
+
+ private Integer id0;
+ private Integer id1;
+ private Integer id2;
+ private Integer id3;
+ private Integer id4;
+ private Integer id5;
+ private Integer id6;
+
+ public void configure(Ejb3Configuration cfg) {
+ cfg.addAnnotatedClass(DefaultValueComponentTestEntity.class);
+ }
+
+ @BeforeClass(dependsOnMethods = "init")
+ public void initData() {
+ // Revision 1
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+
+ DefaultValueComponentTestEntity cte0 = DefaultValueComponentTestEntity
+ .of(null);
+
+ DefaultValueComponentTestEntity cte1 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of("c1-str1", null));
+
+ DefaultValueComponentTestEntity cte2 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of("c1-str1", DefaultValueComponent2
+ .of("c2-str1", "c2-str2")));
+
+ DefaultValueComponentTestEntity cte3 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ "c2-str1", "c2-str2")));
+
+ DefaultValueComponentTestEntity cte4 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ null, "c2-str2")));
+
+ DefaultValueComponentTestEntity cte5 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ "c2-str1", null)));
+
+ DefaultValueComponentTestEntity cte6 = DefaultValueComponentTestEntity
+ .of(DefaultValueComponent1.of(null, DefaultValueComponent2.of(
+ null, null)));
+
+ em.persist(cte0);
+ em.persist(cte1);
+ em.persist(cte2);
+ em.persist(cte3);
+ em.persist(cte4);
+ em.persist(cte5);
+ em.persist(cte6);
+
+ em.getTransaction().commit();
+
+ // Revision 2
+ em = getEntityManager();
+ em.getTransaction().begin();
+
+ cte0 = em.find(DefaultValueComponentTestEntity.class, cte0.getId());
+ cte1 = em.find(DefaultValueComponentTestEntity.class, cte1.getId());
+ cte2 = em.find(DefaultValueComponentTestEntity.class, cte2.getId());
+ cte3 = em.find(DefaultValueComponentTestEntity.class, cte3.getId());
+ cte4 = em.find(DefaultValueComponentTestEntity.class, cte4.getId());
+ cte5 = em.find(DefaultValueComponentTestEntity.class, cte5.getId());
+ cte6 = em.find(DefaultValueComponentTestEntity.class, cte6.getId());
+
+ cte0.setComp1(DefaultValueComponent1.of("upd-c1-str1", null));
+ cte1.setComp1(DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "upd-c2-str2")));
+ cte2.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte3.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte4.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte5.getComp1().getComp2().setStr1("upd-c2-str1");
+ cte6.getComp1().getComp2().setStr1("upd-c2-str1");
+
+ em.getTransaction().commit();
+
+ // afterwards
+ id0 = cte0.getId();
+ id1 = cte1.getId();
+ id2 = cte2.getId();
+ id3 = cte3.getId();
+ id4 = cte4.getId();
+ id5 = cte5.getId();
+ id6 = cte6.getId();
+ }
+
+ @Test
+ public void testRevisionsCounts() {
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id0).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id1).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id2).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id3).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id4).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id5).toString());
+ log.error(getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id6).toString());
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id0));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id1));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id2));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id3));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id4));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id5));
+
+ assert Arrays.asList(1, 2).equals(
+ getAuditReader().getRevisions(
+ DefaultValueComponentTestEntity.class, id6));
+ }
+
+ @Test
+ public void testHistoryOfId0() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id0, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id0, 2);
+
+ log.error("------------ id0 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ checkCorrectlyPersisted(id0, null, null);
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id0, DefaultValueComponent1.of(null, null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id0, DefaultValueComponent1.of("upd-c1-str1", null));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId1() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id1, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id1, 2);
+
+ log.error("------------ id1 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ checkCorrectlyPersisted(id1, null, "upd-c2-str1");
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id1, DefaultValueComponent1.of("c1-str1", null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id1, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "upd-c2-str2")));
+
+ assert ent2.equals(expectedVer2);
+ assert ent1.equals(expectedVer1);
+ }
+
+ @Test
+ public void testHistoryOfId2() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id2, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id2, 2);
+
+ log.error("------------ id2 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id2, DefaultValueComponent1.of("c1-str1",
+ DefaultValueComponent2.of("c2-str1", "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id2, DefaultValueComponent1.of("c1-str1",
+ DefaultValueComponent2.of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId3() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id3, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id3, 2);
+
+ log.error("------------ id3 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("c2-str1", "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id3, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId4() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id4, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id4, 2);
+
+ log.error("------------ id4 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of(null, "c2-str2")));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id4, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", "c2-str2")));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId5() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id5, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id5, 2);
+
+ log.error("------------ id5 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("c2-str1", null)));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id5, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", null)));
+
+ assert ent1.equals(expectedVer1);
+ assert ent2.equals(expectedVer2);
+ }
+
+ @Test
+ public void testHistoryOfId6() {
+
+ DefaultValueComponentTestEntity ent1 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id6, 1);
+ DefaultValueComponentTestEntity ent2 = getAuditReader().find(
+ DefaultValueComponentTestEntity.class, id6, 2);
+
+ log.error("------------ id6 -------------");
+ log.error(ent1.toString());
+ log.error(ent2.toString());
+
+ DefaultValueComponentTestEntity expectedVer1 = DefaultValueComponentTestEntity
+ .of(id6, DefaultValueComponent1.of(null, null));
+ DefaultValueComponentTestEntity expectedVer2 = DefaultValueComponentTestEntity
+ .of(id6, DefaultValueComponent1.of(null, DefaultValueComponent2
+ .of("upd-c2-str1", null)));
+
+ assert ent2.equals(expectedVer2);
+ assert ent1.equals(expectedVer1);
+ }
+
+ private void checkCorrectlyPersisted(Integer expectedId,
+ String expectedComp2Str1Rev1, String expectedComp2Str1Rev2) {
+ // Verify that the entity was correctly persisted
+ EntityManager em = getEntityManager();
+ em.getTransaction().begin();
+ Long entCount = (Long) em.createQuery(
+ "select count(s) from DefaultValueComponentTestEntity s where s.id = "
+ + expectedId.toString()).getSingleResult();
+ BigInteger auditCount = (BigInteger) em.createNativeQuery(
+ "select count(ID) from DefaultValueComponentTestEntity_AUD s where s.id = "
+ + expectedId.toString()).getSingleResult();
+ String comp2Str1Rev1 = (String) em
+ .createNativeQuery(
+ "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=1 and s.id = "
+ + expectedId.toString()).getSingleResult();
+ String comp2Str1Rev2 = (String) em
+ .createNativeQuery(
+ "select COMP2_STR1 from DefaultValueComponentTestEntity_AUD s where rev=2 and s.id = "
+ + expectedId.toString()).getSingleResult();
+ assert Long.valueOf(1L).equals(entCount);
+ assert BigInteger.valueOf(2L).equals(auditCount);
+
+ if (expectedComp2Str1Rev1 == null) {
+ assert comp2Str1Rev1 == null;
+ } else {
+ assert expectedComp2Str1Rev1.equals(comp2Str1Rev1);
+ }
+
+ if (expectedComp2Str1Rev2 == null) {
+ assert comp2Str1Rev2 == null;
+ } else {
+ assert expectedComp2Str1Rev2.equals(comp2Str1Rev2);
+ }
+ em.getTransaction().commit();
+ }
+}
13 years, 10 months
Hibernate SVN: r19749 - core/branches/Branch_3_5/parent.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-16 12:29:16 -0400 (Wed, 16 Jun 2010)
New Revision: 19749
Modified:
core/branches/Branch_3_5/parent/pom.xml
Log:
HHH-5312 update the db account used in branch 35 test
Modified: core/branches/Branch_3_5/parent/pom.xml
===================================================================
--- core/branches/Branch_3_5/parent/pom.xml 2010-06-16 16:21:22 UTC (rev 19748)
+++ core/branches/Branch_3_5/parent/pom.xml 2010-06-16 16:29:16 UTC (rev 19749)
@@ -883,8 +883,8 @@
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
<!-- fall back to oracle 11g r1, once the account be setup, we should change this back <jdbc.url>jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg27-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg28-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))</jdbc.url>
- <jdbc.url>
- --> jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
+ --><jdbc.url>
+ jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
13 years, 10 months
Hibernate SVN: r19748 - core/branches/Branch_3_5/parent.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-16 12:21:22 -0400 (Wed, 16 Jun 2010)
New Revision: 19748
Modified:
core/branches/Branch_3_5/parent/pom.xml
Log:
HHH-5312 update the db account used in branch 35 test
Modified: core/branches/Branch_3_5/parent/pom.xml
===================================================================
--- core/branches/Branch_3_5/parent/pom.xml 2010-06-16 10:43:40 UTC (rev 19747)
+++ core/branches/Branch_3_5/parent/pom.xml 2010-06-16 16:21:22 UTC (rev 19748)
@@ -860,7 +860,8 @@
<properties>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
- <jdbc.url>jdbc:oracle:thin:@vmg27.mw.lab.eng.bos.redhat.com:1521:qaora11</jdbc.url>
+ <!-- fall back to oracle 11g r1, once the account be setup, we should change this back <jdbc.url>jdbc:oracle:thin:@vmg27.mw.lab.eng.bos.redhat.com:1521:qaora11</jdbc.url> -->
+<jdbc.url>jdbc:oracle:thin:@dev04.qa.atl2.redhat.com:1521:qaora11</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
@@ -873,15 +874,18 @@
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
- <artifactId>ojdbc6</artifactId>
- <version>11.2.0.1.0</version>
+ <artifactId>ojdbc5</artifactId>
+ <version>11.1.0.7.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
- <jdbc.url>jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg27-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg28-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))</jdbc.url>
+<!-- fall back to oracle 11g r1, once the account be setup, we should change this back <jdbc.url>jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg27-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg28-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))</jdbc.url>
+ <jdbc.url>
+ --> jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
+ </jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
@@ -902,7 +906,7 @@
<properties>
<db.dialect>org.hibernate.dialect.SybaseASE15Dialect</db.dialect>
<jdbc.driver>com.sybase.jdbc3.jdbc.SybDriver</jdbc.driver>
- <jdbc.url>jdbc:sybase:Tds:dev77.qa.atl2.redhat.com:5000/hibbr35</jdbc.url>
+ <jdbc.url>jdbc:sybase:Tds:vmg07.mw.lab.eng.bos.redhat.com:5000/hibbr35</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
13 years, 10 months
Hibernate SVN: r19747 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/beanvalidation and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-16 06:43:40 -0400 (Wed, 16 Jun 2010)
New Revision: 19747
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java
Log:
HHH-5281 apply @Length ddl constraints (without loading HV classes)
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2010-06-16 10:39:31 UTC (rev 19746)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2010-06-16 10:43:40 UTC (rev 19747)
@@ -39,6 +39,7 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
class TypeSafeActivator {
@@ -148,12 +149,17 @@
if ( canApplyNotNull ) {
hasNotNull = hasNotNull || applyNotNull( property, descriptor );
}
+
+ // apply bean validation specific constraints
applyDigits( property, descriptor );
applySize( property, descriptor, propertyDesc );
applyMin( property, descriptor );
applyMax( property, descriptor );
- //pass an empty set as composing constraints inherit the main constraint and thus are matching already
+ // apply hibernate validator specific constraints - we cannot import any HV specific classes though!
+ applyLength( property, descriptor, propertyDesc );
+
+ // pass an empty set as composing constraints inherit the main constraint and thus are matching already
hasNotNull = hasNotNull || applyConstraints(
descriptor.getComposingConstraints(),
property, propertyDesc, null,
@@ -213,17 +219,31 @@
}
}
- private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDesc) {
+ private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
- && String.class.equals( propertyDesc.getElementClass() ) ) {
- @SuppressWarnings( "unchecked" )
- ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
+ && String.class.equals( propertyDescriptor.getElementClass() ) ) {
+ @SuppressWarnings("unchecked")
+ ConstraintDescriptor<Size> sizeConstraint = ( ConstraintDescriptor<Size> ) descriptor;
int max = sizeConstraint.getAnnotation().max();
- Column col = (Column) property.getColumnIterator().next();
- if ( max < Integer.MAX_VALUE ) col.setLength( max );
+ Column col = ( Column ) property.getColumnIterator().next();
+ if ( max < Integer.MAX_VALUE ) {
+ col.setLength( max );
+ }
}
}
+ private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
+ if ( "org.hibernate.validator.constraints.Length".equals(descriptor.getAnnotation().annotationType().getName())
+ && String.class.equals( propertyDescriptor.getElementClass() ) ) {
+ @SuppressWarnings("unchecked")
+ int max = (Integer) descriptor.getAttributes().get( "max" );
+ Column col = ( Column ) property.getColumnIterator().next();
+ if ( max < Integer.MAX_VALUE ) {
+ col.setLength( max );
+ }
+ }
+ }
+
/**
* Retrieve the property by path in a recursive way, including IndentifierProperty in the loop
* If propertyName is null or empty, the IdentifierProperty is returned
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java 2010-06-16 10:39:31 UTC (rev 19746)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java 2010-06-16 10:43:40 UTC (rev 19747)
@@ -6,13 +6,15 @@
import org.hibernate.test.annotations.TestCase;
/**
+ * Test verifying that DDL constraints get applied when Bean Validation / Hibernate Validator are enabled.
+ *
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class DDLTest extends TestCase {
public void testBasicDDL() {
PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
assertEquals( stateColumn.getLength(), 3 );
Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
@@ -23,9 +25,20 @@
public void testApplyOnIdColumn() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next();
- assertEquals( "Vaidator annotation not applied on ids", 2, serialColumn.getLength() );
+ assertEquals( "Validator annotation not applied on ids", 2, serialColumn.getLength() );
}
+ /**
+ * HHH-5281
+ *
+ * @throws Exception in case the test fails
+ */
+ public void testLengthConstraint() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
+ Column modelColumn = (Column) classMapping.getProperty( "model" ).getColumnIterator().next();
+ assertEquals( modelColumn.getLength(), 5 );
+ }
+
public void testApplyOnManyToOne() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next();
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java 2010-06-16 10:39:31 UTC (rev 19746)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java 2010-06-16 10:43:40 UTC (rev 19747)
@@ -1,19 +1,22 @@
package org.hibernate.test.annotations.beanvalidation;
+import java.math.BigDecimal;
import java.math.BigInteger;
-import java.math.BigDecimal;
import java.util.Date;
+import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
-import javax.persistence.Embeddable;
+import javax.validation.Valid;
import javax.validation.constraints.Future;
import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
-import javax.validation.constraints.NotNull;
-import javax.validation.Valid;
+import org.hibernate.validator.constraints.Length;
+
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
@Entity
public class Tv {
@@ -21,17 +24,28 @@
@Id
@Size(max = 2)
public String serial;
+
+ @Length(max=5)
+ public String model;
+
public int size;
+
@Size(max = 2)
public String name;
+
@Future
public Date expDate;
+
@Size(min = 0)
public String description;
+
@Min(1000)
public BigInteger lifetime;
- @NotNull @Valid
+
+ @NotNull
+ @Valid
public Tuner tuner;
+
@Valid
public Recorder recorder;
@@ -46,5 +60,4 @@
@NotNull
public BigDecimal time;
}
-
}
13 years, 10 months
Hibernate SVN: r19746 - in core/branches/Branch_3_5/annotations/src: test/java/org/hibernate/test/annotations/beanvalidation and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-06-16 06:39:31 -0400 (Wed, 16 Jun 2010)
New Revision: 19746
Modified:
core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java
Log:
HHH-5281 Added ddl constraint generation for @Length without importing HV classes
Modified: core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2010-06-16 09:04:23 UTC (rev 19745)
+++ core/branches/Branch_3_5/annotations/src/main/java/org/hibernate/cfg/beanvalidation/TypeSafeActivator.java 2010-06-16 10:39:31 UTC (rev 19746)
@@ -39,6 +39,7 @@
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
class TypeSafeActivator {
@@ -148,12 +149,17 @@
if ( canApplyNotNull ) {
hasNotNull = hasNotNull || applyNotNull( property, descriptor );
}
+
+ // apply bean validation specific constraints
applyDigits( property, descriptor );
applySize( property, descriptor, propertyDesc );
applyMin( property, descriptor );
applyMax( property, descriptor );
- //pass an empty set as composing constraints inherit the main constraint and thus are matching already
+ // apply hibernate validator specific constraints - we cannot import any HV specific classes though!
+ applyLength( property, descriptor, propertyDesc );
+
+ // pass an empty set as composing constraints inherit the main constraint and thus are matching already
hasNotNull = hasNotNull || applyConstraints(
descriptor.getComposingConstraints(),
property, propertyDesc, null,
@@ -213,17 +219,31 @@
}
}
- private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDesc) {
+ private static void applySize(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
if ( Size.class.equals( descriptor.getAnnotation().annotationType() )
- && String.class.equals( propertyDesc.getElementClass() ) ) {
- @SuppressWarnings( "unchecked" )
- ConstraintDescriptor<Size> sizeConstraint = (ConstraintDescriptor<Size>) descriptor;
+ && String.class.equals( propertyDescriptor.getElementClass() ) ) {
+ @SuppressWarnings("unchecked")
+ ConstraintDescriptor<Size> sizeConstraint = ( ConstraintDescriptor<Size> ) descriptor;
int max = sizeConstraint.getAnnotation().max();
- Column col = (Column) property.getColumnIterator().next();
- if ( max < Integer.MAX_VALUE ) col.setLength( max );
+ Column col = ( Column ) property.getColumnIterator().next();
+ if ( max < Integer.MAX_VALUE ) {
+ col.setLength( max );
+ }
}
}
+ private static void applyLength(Property property, ConstraintDescriptor<?> descriptor, PropertyDescriptor propertyDescriptor) {
+ if ( "org.hibernate.validator.constraints.Length".equals(descriptor.getAnnotation().annotationType().getName())
+ && String.class.equals( propertyDescriptor.getElementClass() ) ) {
+ @SuppressWarnings("unchecked")
+ int max = (Integer) descriptor.getAttributes().get( "max" );
+ Column col = ( Column ) property.getColumnIterator().next();
+ if ( max < Integer.MAX_VALUE ) {
+ col.setLength( max );
+ }
+ }
+ }
+
/**
* Retrieve the property by path in a recursive way, including IndentifierProperty in the loop
* If propertyName is null or empty, the IdentifierProperty is returned
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java 2010-06-16 09:04:23 UTC (rev 19745)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/DDLTest.java 2010-06-16 10:39:31 UTC (rev 19746)
@@ -6,13 +6,15 @@
import org.hibernate.test.annotations.TestCase;
/**
+ * Test verifying that DDL constraints get applied when Bean Validation / Hibernate Validator are enabled.
+ *
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
public class DDLTest extends TestCase {
public void testBasicDDL() {
PersistentClass classMapping = getCfg().getClassMapping( Address.class.getName() );
- //new ClassValidator( Address.class, ResourceBundle.getBundle("messages", Locale.ENGLISH) ).apply( classMapping );
Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next();
assertEquals( stateColumn.getLength(), 3 );
Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next();
@@ -23,9 +25,20 @@
public void testApplyOnIdColumn() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
Column serialColumn = (Column) classMapping.getIdentifierProperty().getColumnIterator().next();
- assertEquals( "Vaidator annotation not applied on ids", 2, serialColumn.getLength() );
+ assertEquals( "Validator annotation not applied on ids", 2, serialColumn.getLength() );
}
+ /**
+ * HHH-5281
+ *
+ * @throws Exception in case the test fails
+ */
+ public void testLengthConstraint() throws Exception {
+ PersistentClass classMapping = getCfg().getClassMapping( Tv.class.getName() );
+ Column modelColumn = (Column) classMapping.getProperty( "model" ).getColumnIterator().next();
+ assertEquals( modelColumn.getLength(), 5 );
+ }
+
public void testApplyOnManyToOne() throws Exception {
PersistentClass classMapping = getCfg().getClassMapping( TvOwner.class.getName() );
Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next();
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java 2010-06-16 09:04:23 UTC (rev 19745)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/beanvalidation/Tv.java 2010-06-16 10:39:31 UTC (rev 19746)
@@ -1,19 +1,22 @@
package org.hibernate.test.annotations.beanvalidation;
+import java.math.BigDecimal;
import java.math.BigInteger;
-import java.math.BigDecimal;
import java.util.Date;
+import javax.persistence.Embeddable;
import javax.persistence.Entity;
import javax.persistence.Id;
-import javax.persistence.Embeddable;
+import javax.validation.Valid;
import javax.validation.constraints.Future;
import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
-import javax.validation.constraints.NotNull;
-import javax.validation.Valid;
+import org.hibernate.validator.constraints.Length;
+
/**
* @author Emmanuel Bernard
+ * @author Hardy Ferentschik
*/
@Entity
public class Tv {
@@ -21,17 +24,28 @@
@Id
@Size(max = 2)
public String serial;
+
+ @Length(max=5)
+ public String model;
+
public int size;
+
@Size(max = 2)
public String name;
+
@Future
public Date expDate;
+
@Size(min = 0)
public String description;
+
@Min(1000)
public BigInteger lifetime;
- @NotNull @Valid
+
+ @NotNull
+ @Valid
public Tuner tuner;
+
@Valid
public Recorder recorder;
@@ -46,5 +60,4 @@
@NotNull
public BigDecimal time;
}
-
}
13 years, 10 months
Hibernate SVN: r19745 - core/branches/Branch_3_5/parent.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-06-16 05:04:23 -0400 (Wed, 16 Jun 2010)
New Revision: 19745
Modified:
core/branches/Branch_3_5/parent/pom.xml
Log:
HHH-5312 update the db account used in branch 35 test
Modified: core/branches/Branch_3_5/parent/pom.xml
===================================================================
--- core/branches/Branch_3_5/parent/pom.xml 2010-06-15 20:50:02 UTC (rev 19744)
+++ core/branches/Branch_3_5/parent/pom.xml 2010-06-16 09:04:23 UTC (rev 19745)
@@ -619,7 +619,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
- <version>5.0.5</version>
+ <version>5.0.8</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -628,7 +628,7 @@
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
<jdbc.url>jdbc:mysql://vmg08.mw.lab.eng.bos.redhat.com/hibbr35</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
- <jdbc.pass>hibbr35hibbr35</jdbc.pass>
+ <jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
</properties>
</profile>
@@ -640,7 +640,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
- <version>5.0.5</version>
+ <version>5.1.12</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -683,7 +683,7 @@
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
- <version>8.2-504.jdbc3</version>
+ <version>8.2-510</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -704,7 +704,7 @@
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
- <version>8.2-504.jdbc3</version>
+ <version>8.3-605</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -783,7 +783,7 @@
<dependency>
<groupId>com.ibm</groupId>
<artifactId>db2jcc</artifactId>
- <version>3.57.86</version>
+ <version>3.58.82</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -832,7 +832,7 @@
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<!-- use the 10g drivers which are surprisingly largely bug free -->
- <version>10.0.2.0</version>
+ <version>10.2.0.4</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -852,15 +852,15 @@
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
- <artifactId>ojdbc5</artifactId>
- <version>11.1.0.7.0</version>
+ <artifactId>ojdbc6</artifactId>
+ <version>11.2.0.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
- <jdbc.url>jdbc:oracle:thin:@dev04.qa.atl2.redhat.com:1521:qaora11</jdbc.url>
+ <jdbc.url>jdbc:oracle:thin:@vmg27.mw.lab.eng.bos.redhat.com:1521:qaora11</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
@@ -873,17 +873,15 @@
<dependencies>
<dependency>
<groupId>com.oracle</groupId>
- <artifactId>ojdbc5</artifactId>
- <version>11.1.0.7.0</version>
+ <artifactId>ojdbc6</artifactId>
+ <version>11.2.0.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
- <jdbc.url>
- jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
- </jdbc.url>
+ <jdbc.url>jdbc:oracle:thin:@(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg27-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg28-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
@@ -904,7 +902,7 @@
<properties>
<db.dialect>org.hibernate.dialect.SybaseASE15Dialect</db.dialect>
<jdbc.driver>com.sybase.jdbc3.jdbc.SybDriver</jdbc.driver>
- <jdbc.url>jdbc:sybase:Tds:vmg07.mw.lab.eng.bos.redhat.com:5000/hibbr35</jdbc.url>
+ <jdbc.url>jdbc:sybase:Tds:dev77.qa.atl2.redhat.com:5000/hibbr35</jdbc.url>
<jdbc.user>hibbr35</jdbc.user>
<jdbc.pass>hibbr35</jdbc.pass>
<jdbc.isolation />
13 years, 10 months
Hibernate SVN: r19744 - core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-06-15 16:50:02 -0400 (Tue, 15 Jun 2010)
New Revision: 19744
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
Log:
HHH-5231 : Unit test locks up on postgresql on Branch_3_5
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-06-15 18:52:54 UTC (rev 19743)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java 2010-06-15 20:50:02 UTC (rev 19744)
@@ -99,9 +99,11 @@
s.close();
s = openSession();
+ tx = s.beginTransaction();
List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add(
Restrictions.eq( "s.name", "Fnac" ) ).list();
assertEquals( 1, result.size() );
+ tx.commit();
s.close();
}
public void testDefaultCompositePk() throws Exception {
@@ -771,4 +773,4 @@
};
}
-}
\ No newline at end of file
+}
13 years, 10 months
Hibernate SVN: r19743 - core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/subselect.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-06-15 14:52:54 -0400 (Tue, 15 Jun 2010)
New Revision: 19743
Modified:
core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/subselect/SubselectTest.java
Log:
HHH-5231 : Unit test locks up on postgresql on Branch_3_5
Modified: core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/subselect/SubselectTest.java
===================================================================
--- core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/subselect/SubselectTest.java 2010-06-15 17:24:12 UTC (rev 19742)
+++ core/branches/Branch_3_5/annotations/src/test/java/org/hibernate/test/annotations/subselect/SubselectTest.java 2010-06-15 18:52:54 UTC (rev 19743)
@@ -71,7 +71,7 @@
HighestBid highestBid = (HighestBid) query.list().iterator().next();
assertEquals(200.0, highestBid.getAmount());
-
+ s.getTransaction().rollback();
s.close();
13 years, 10 months
Hibernate SVN: r19742 - core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/naturalid/immutable.
by hibernate-commits@lists.jboss.org
Author: gbadner
Date: 2010-06-15 13:24:12 -0400 (Tue, 15 Jun 2010)
New Revision: 19742
Modified:
core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java
Log:
HHH-5231 : Unit test locks up on postgresql on Branch_3_5
Modified: core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java
===================================================================
--- core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java 2010-06-15 15:53:37 UTC (rev 19741)
+++ core/branches/Branch_3_5/testsuite/src/test/java/org/hibernate/test/naturalid/immutable/ImmutableNaturalIdTest.java 2010-06-15 17:24:12 UTC (rev 19742)
@@ -227,6 +227,8 @@
.setCacheable( true )
.uniqueResult();
assertNotNull( u );
+ s.getTransaction().commit();
+ s.close();
assertEquals( getSessions().getStatistics().getQueryExecutionCount(), 1 );
assertEquals( getSessions().getStatistics().getQueryCacheHitCount(), 0 );
13 years, 10 months