[hibernate-commits] Hibernate SVN: r18542 - in core/trunk/annotations/src/test: java/org/hibernate/test/annotations/idclass/xml and 3 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Jan 13 13:04:02 EST 2010


Author: hardy.ferentschik
Date: 2010-01-13 13:04:02 -0500 (Wed, 13 Jan 2010)
New Revision: 18542

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/xml/
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml
Log:
HHH-4282 Added the test attched to the jira issue to ensure the problems is really fixed by HHH-4528

Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.java	2010-01-13 18:04:02 UTC (rev 18542)
@@ -0,0 +1,148 @@
+// $Id: $
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.hibernate.test.annotations.idclass.xml;
+
+import java.io.Serializable;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class HabitatSpeciesLink implements Serializable {
+	private static final long serialVersionUID = -7079021236893433038L;
+
+	private Long habitatId;
+
+	private Long speciesId;
+
+	public Long getHabitatId() {
+		return this.habitatId;
+	}
+
+	public void setHabitatId(Long newHabitatId) {
+		this.habitatId = newHabitatId;
+	}
+
+	public Long getSpeciesId() {
+		return this.speciesId;
+	}
+
+	public void setSpeciesId(Long newSpeciesId) {
+		this.speciesId = newSpeciesId;
+	}
+
+	@Override
+	public int hashCode() {
+		final int prime = 31;
+		int result = 1;
+		result = prime * result + ( ( this.getHabitatId() == null ) ? 0
+				: this.getHabitatId().hashCode() );
+		result = prime * result + ( ( this.getSpeciesId() == null ) ? 0
+				: this.getSpeciesId().hashCode() );
+		return result;
+	}
+
+	@Override
+	public boolean equals(Object obj) {
+		if ( this == obj ) {
+			return true;
+		}
+		if ( obj == null ) {
+			return false;
+		}
+		if ( !( obj instanceof HabitatSpeciesLink ) ) {
+			return false;
+		}
+		final HabitatSpeciesLink other = ( HabitatSpeciesLink ) obj;
+		if ( this.getHabitatId() == null ) {
+			if ( other.getHabitatId() != null ) {
+				return false;
+			}
+		}
+		else if ( !this.getHabitatId().equals( other.getHabitatId() ) ) {
+			return false;
+		}
+		if ( this.getSpeciesId() == null ) {
+			if ( other.getSpeciesId() != null ) {
+				return false;
+			}
+		}
+		else if ( !this.getSpeciesId().equals( other.getSpeciesId() ) ) {
+			return false;
+		}
+		return true;
+	}
+
+	public static class HabitatSpeciesLinkId implements Serializable {
+		private Long habitatId;
+
+		private Long speciesId;
+
+		public Long getHabitatId() {
+			return this.habitatId;
+		}
+
+		public void setHabitatId(Long newHabitatId) {
+			this.habitatId = newHabitatId;
+		}
+
+		public Long getSpeciesId() {
+			return this.speciesId;
+		}
+
+		public void setSpeciesId(Long newSpeciesId) {
+			this.speciesId = newSpeciesId;
+		}
+
+		/**
+		 * Equality must be implemented in terms of identity field equality, and
+		 * must use instanceof rather than comparing classes directly (some JPA
+		 * implementations may subclass the identity class).
+		 */
+		public boolean equals(Object other) {
+			if ( other == this ) {
+				return true;
+			}
+			if ( !( other instanceof HabitatSpeciesLinkId ) ) {
+				return false;
+			}
+			HabitatSpeciesLinkId mi = ( HabitatSpeciesLinkId ) other;
+			return ( habitatId == mi.habitatId || ( habitatId != null && habitatId
+					.equals( mi.habitatId ) ) )
+					&& ( speciesId == mi.speciesId || ( speciesId != null && speciesId
+					.equals( mi.speciesId ) ) );
+		}
+
+		/**
+		 * Hashcode must also depend on identity values.
+		 */
+		public int hashCode() {
+			return ( ( habitatId == null ) ? 0
+					: habitatId.hashCode() ) ^ ( ( speciesId == null ) ? 0
+					: speciesId.hashCode() );
+		}
+
+		public String toString() {
+			return "habitatId[" + habitatId + "],speciesId[" + speciesId + "]";
+		}
+	}
+}
\ No newline at end of file

Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java (from rev 18523, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/IdClassCompositePKTest.java)
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclass/xml/IdClassXmlTest.java	2010-01-13 18:04:02 UTC (rev 18542)
@@ -0,0 +1,64 @@
+// $Id$
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.hibernate.test.annotations.idclass.xml;
+
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.annotations.TestCase;
+
+/**
+ * HHH-4282
+ *
+ * @author Hardy Ferentschik
+ */
+public class IdClassXmlTest extends TestCase {
+
+	public void testEntityMappningPropertiesAreNotIgnored() {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+
+		HabitatSpeciesLink link = new HabitatSpeciesLink();
+		link.setHabitatId( 1l );
+		link.setSpeciesId( 1l );
+		s.persist( link );
+
+		Query q = s.getNamedQuery( "testQuery" );
+		assertEquals( 1, q.list().size() );
+
+		tx.rollback();
+		s.close();
+	}
+
+	protected Class[] getMappings() {
+		return new Class[] {
+				HabitatSpeciesLink.class
+		};
+	}
+
+	protected String[] getXmlFiles() {
+		return new String[] {
+				"org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml"
+		};
+	}
+}
\ No newline at end of file

Added: core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml
===================================================================
--- core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml	                        (rev 0)
+++ core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/idclass/xml/HabitatSpeciesLink.xml	2010-01-13 18:04:02 UTC (rev 18542)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_1_0.xsd"
+                 version="1.0">
+    <entity class="org.hibernate.test.annotations.idclass.xml.HabitatSpeciesLink" access="FIELD">
+        <table name="HABITAT_SPECIES_LINK"/>
+        <id-class
+                class="org.hibernate.test.annotations.idclass.xml.HabitatSpeciesLink$HabitatSpeciesLinkId"/>
+        <named-native-query name="testQuery"
+                            result-class="org.hibernate.test.annotations.idclass.xml.HabitatSpeciesLink">
+            <query>select * from HABITAT_SPECIES_LINK link where link.HABITAT_LINK = 1</query>
+        </named-native-query>
+        <attributes>
+            <id name="habitatId">
+                <column name="HABITAT_LINK"/>
+            </id>
+            <id name="speciesId">
+                <column name="SPECIES_LINK"/>
+            </id>
+        </attributes>
+    </entity>
+</entity-mappings>
+



More information about the hibernate-commits mailing list