[hibernate-commits] Hibernate SVN: r18792 - in core/branches/envers-hibernate-3.3/src: test/java/org/hibernate/envers/test/entities/ids and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Feb 12 07:51:02 EST 2010


Author: adamw
Date: 2010-02-12 07:51:01 -0500 (Fri, 12 Feb 2010)
New Revision: 18792

Added:
   core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java
   core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java
   core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java
Modified:
   core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
Log:
svn merge -r 18765:18791 https://svn.jboss.org/repos/hibernate/core/trunk/envers .

Modified: core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java
===================================================================
--- core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java	2010-02-12 12:47:15 UTC (rev 18791)
+++ core/branches/envers-hibernate-3.3/src/main/java/org/hibernate/envers/configuration/metadata/IdMetadataGenerator.java	2010-02-12 12:51:01 UTC (rev 18792)
@@ -61,12 +61,12 @@
             Property property = properties.next();
             Type propertyType = property.getType();
             if (!"_identifierMapper".equals(property.getName())) {
-                if (!propertyType.isMutable()) {
-                    // Last but one parameter: ids are always insertable
-                    mainGenerator.getBasicMetadataGenerator().addBasic(parent,
-                            getIdPersistentPropertyAuditingData(property),
-                            property.getValue(), mapper, true, key);
-                } else {
+                // Last but one parameter: ids are always insertable
+                boolean added =  mainGenerator.getBasicMetadataGenerator().addBasic(parent,
+                        getIdPersistentPropertyAuditingData(property),
+                        property.getValue(), mapper, true, key);
+
+                if (!added) {
                     throw new MappingException("Type not supported: " + propertyType.getClass().getName());
                 }
             }

Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java (from rev 18791, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java	                        (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/CompositeDateIdTestEntity.java	2010-02-12 12:51:01 UTC (rev 18792)
@@ -0,0 +1,89 @@
+/*
+ * 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.ids;
+
+import org.hibernate.envers.Audited;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Entity
+public class CompositeDateIdTestEntity {
+    @EmbeddedId
+    private DateEmbId id;
+
+    @Audited
+    private String str1;
+
+    public CompositeDateIdTestEntity() {
+    }
+
+    public CompositeDateIdTestEntity(String str1) {
+        this.str1 = str1;
+    }
+
+    public CompositeDateIdTestEntity(DateEmbId id, String str1) {
+        this.id = id;
+        this.str1 = str1;
+    }
+
+    public DateEmbId getId() {
+        return id;
+    }
+
+    public void setId(DateEmbId id) {
+        this.id = id;
+    }
+
+    public String getStr1() {
+        return str1;
+    }
+
+    public void setStr1(String str1) {
+        this.str1 = str1;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        CompositeDateIdTestEntity that = (CompositeDateIdTestEntity) o;
+
+        if (id != null ? !id.equals(that.id) : that.id != null) return false;
+        if (str1 != null ? !str1.equals(that.str1) : that.str1 != null) return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = id != null ? id.hashCode() : 0;
+        result = 31 * result + (str1 != null ? str1.hashCode() : 0);
+        return result;
+    }
+}
\ No newline at end of file

Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java (from rev 18791, core/trunk/envers/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java	                        (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/entities/ids/DateEmbId.java	2010-02-12 12:51:01 UTC (rev 18792)
@@ -0,0 +1,84 @@
+/*
+ * 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.ids;
+
+import javax.persistence.Embeddable;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+ at Embeddable
+public class DateEmbId implements Serializable {
+    private Date x;
+    private Date y;
+
+    public DateEmbId() {
+    }
+
+    public DateEmbId(Date x, Date y) {
+        this.x = x;
+        this.y = y;
+    }
+
+    public Date getX() {
+        return x;
+    }
+
+    public void setX(Date x) {
+        this.x = x;
+    }
+
+    public Date getY() {
+        return y;
+    }
+
+    public void setY(Date y) {
+        this.y = y;
+    }
+
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof DateEmbId)) return false;
+
+        DateEmbId embId = (DateEmbId) o;
+
+        if (x != null ? !x.equals(embId.x) : embId.x != null) return false;
+        if (y != null ? !y.equals(embId.y) : embId.y != null) return false;
+
+        return true;
+    }
+
+    public int hashCode() {
+        int result;
+        result = (x != null ? x.hashCode() : 0);
+        result = 31 * result + (y != null ? y.hashCode() : 0);
+        return result;
+    }
+
+    public String toString() {
+        return "DateEmbId(" + x + ", " + y + ")";
+    }
+}
\ No newline at end of file

Copied: core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java (from rev 18791, core/trunk/envers/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java)
===================================================================
--- core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java	                        (rev 0)
+++ core/branches/envers-hibernate-3.3/src/test/java/org/hibernate/envers/test/integration/ids/CompositeDateId.java	2010-02-12 12:51:01 UTC (rev 18792)
@@ -0,0 +1,84 @@
+/*
+ * 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.ids;
+
+import org.hibernate.ejb.Ejb3Configuration;
+import org.hibernate.envers.test.AbstractEntityTest;
+import org.hibernate.envers.test.entities.ids.CompositeDateIdTestEntity;
+import org.hibernate.envers.test.entities.ids.DateEmbId;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import javax.persistence.EntityManager;
+import java.util.Arrays;
+import java.util.Date;
+
+/**
+ * @author Adam Warski (adam at warski dot org)
+ */
+public class CompositeDateId extends AbstractEntityTest {
+    private DateEmbId id1;
+
+    public void configure(Ejb3Configuration cfg) {
+        cfg.addAnnotatedClass(CompositeDateIdTestEntity.class);
+    }
+
+    @BeforeClass(dependsOnMethods = "init")
+    public void initData() {
+
+        // Revision 1
+        EntityManager em = getEntityManager();
+        em.getTransaction().begin();
+
+        CompositeDateIdTestEntity dite = new CompositeDateIdTestEntity(new DateEmbId(new Date(), new Date()), "x");
+        em.persist(dite);
+
+        id1 = dite.getId();
+
+        em.getTransaction().commit();
+
+        // Revision 2
+        em = getEntityManager();
+        em.getTransaction().begin();
+
+        dite = em.find(CompositeDateIdTestEntity.class, id1);
+        dite.setStr1("y");
+
+        em.getTransaction().commit();
+    }
+
+    @Test
+    public void testRevisionsCounts() {
+        assert Arrays.asList(1, 2).equals(getAuditReader().getRevisions(CompositeDateIdTestEntity.class, id1));
+    }
+
+    @Test
+    public void testHistoryOfId1() {
+        CompositeDateIdTestEntity ver1 = new CompositeDateIdTestEntity(id1, "x");
+        CompositeDateIdTestEntity ver2 = new CompositeDateIdTestEntity(id1, "y");
+
+        assert getAuditReader().find(CompositeDateIdTestEntity.class, id1, 1).getStr1().equals("x");
+        assert getAuditReader().find(CompositeDateIdTestEntity.class, id1, 2).getStr1().equals("y");
+    }
+}
\ No newline at end of file



More information about the hibernate-commits mailing list