[hibernate-commits] Hibernate SVN: r18870 - in core/trunk/annotations/src/test: resources/org/hibernate/test/annotations and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Wed Feb 24 13:45:12 EST 2010


Author: hardy.ferentschik
Date: 2010-02-24 13:45:11 -0500 (Wed, 24 Feb 2010)
New Revision: 18870

Added:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Father.java
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Son.java
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetoone/
   core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetoone/orm.xml
Modified:
   core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
Log:
HHH-4606 Functionality was actually already there. Just added a test

Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Father.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Father.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Father.java	2010-02-24 18:45:11 UTC (rev 18870)
@@ -0,0 +1,52 @@
+// $Id$
+/*
+ * 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.test.annotations.onetoone;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Father {
+	private int id;
+
+	private String name;
+	
+	public int getId() {
+		return id;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+}
+
+


Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Father.java
___________________________________________________________________
Name: svn:keywords
   + Id

Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java	2010-02-24 17:11:05 UTC (rev 18869)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java	2010-02-24 18:45:11 UTC (rev 18870)
@@ -1,9 +1,15 @@
 //$Id$
 package org.hibernate.test.annotations.onetoone;
 
+import java.util.Iterator;
+
 import org.hibernate.Query;
 import org.hibernate.Session;
 import org.hibernate.Transaction;
+import org.hibernate.mapping.Column;
+import org.hibernate.mapping.Join;
+import org.hibernate.mapping.PersistentClass;
+import org.hibernate.mapping.Table;
 import org.hibernate.test.annotations.Customer;
 import org.hibernate.test.annotations.Discount;
 import org.hibernate.test.annotations.Passport;
@@ -37,7 +43,7 @@
 		tx = s.beginTransaction();
 		Query q = s.createQuery( "select c from Client c where c.name = :name" );
 		q.setString( "name", c.getName() );
-		c = (Client) q.uniqueResult();
+		c = ( Client ) q.uniqueResult();
 		//c = (Client) s.get(Client.class, c.getId());
 		assertNotNull( c );
 		tx.commit();
@@ -65,7 +71,7 @@
 		s.close();
 		s = openSession();
 		tx = s.beginTransaction();
-		c = (Customer) s.get( Customer.class, c.getId() );
+		c = ( Customer ) s.get( Customer.class, c.getId() );
 		assertNotNull( c );
 		p = c.getPassport();
 		assertNotNull( p );
@@ -93,7 +99,7 @@
 
 		s = openSession();
 		tx = s.beginTransaction();
-		c = (Client) s.get( Client.class, c.getId() );
+		c = ( Client ) s.get( Client.class, c.getId() );
 		assertNotNull( c );
 		assertNotNull( c.getAddress() );
 		assertEquals( "Paris", c.getAddress().getCity() );
@@ -105,7 +111,7 @@
 		Body b = new Body();
 		Heart h = new Heart();
 		b.setHeart( h );
-		b.setId( new Integer( 1 ) );
+		b.setId( 1 );
 		h.setId( b.getId() ); //same PK
 		Session s;
 		Transaction tx;
@@ -118,7 +124,7 @@
 
 		s = openSession();
 		tx = s.beginTransaction();
-		b = (Body) s.get( Body.class, b.getId() );
+		b = ( Body ) s.get( Body.class, b.getId() );
 		assertNotNull( b );
 		assertNotNull( b.getHeart() );
 		assertEquals( h.getId(), b.getHeart().getId() );
@@ -151,7 +157,7 @@
 
 		s = openSession();
 		tx = s.beginTransaction();
-		c = (Computer) s.get( Computer.class, cid );
+		c = ( Computer ) s.get( Computer.class, cid );
 		assertNotNull( c );
 		assertNotNull( c.getSerial() );
 		assertEquals( sn.getValue(), c.getSerial().getValue() );
@@ -175,13 +181,13 @@
 		s.clear();
 
 		Transaction tx = s.beginTransaction();
-		affiliate = (PartyAffiliate) s.get( PartyAffiliate.class, "id" );
+		affiliate = ( PartyAffiliate ) s.get( PartyAffiliate.class, "id" );
 		assertNotNull( affiliate.party );
 		assertEquals( affiliate.partyId, affiliate.party.partyId );
 
 		s.clear();
 
-		party = (Party) s.get( Party.class, "id" );
+		party = ( Party ) s.get( Party.class, "id" );
 		assertNotNull( party.partyAffiliate );
 		assertEquals( party.partyId, party.partyAffiliate.partyId );
 
@@ -196,8 +202,8 @@
 		s.getTransaction().begin();
 		Trousers trousers = new Trousers();
 		TrousersZip zip = new TrousersZip();
-		trousers.id = new Integer( 1 );
-		zip.id = new Integer( 2 );
+		trousers.id = 1;
+		zip.id = 2;
 		trousers.zip = zip;
 		zip.trousers = trousers;
 		s.persist( trousers );
@@ -207,13 +213,13 @@
 		s.clear();
 
 		Transaction tx = s.beginTransaction();
-		trousers = (Trousers) s.get( Trousers.class, trousers.id );
+		trousers = ( Trousers ) s.get( Trousers.class, trousers.id );
 		assertNotNull( trousers.zip );
 		assertEquals( zip.id, trousers.zip.id );
 
 		s.clear();
 
-		zip = (TrousersZip) s.get( TrousersZip.class, zip.id );
+		zip = ( TrousersZip ) s.get( TrousersZip.class, zip.id );
 		assertNotNull( zip.trousers );
 		assertEquals( trousers.id, zip.trousers.id );
 
@@ -233,7 +239,7 @@
 		s.persist( owner );
 		s.flush();
 		s.clear();
-		owner = (Owner) s.get( Owner.class, owner.getId() );
+		owner = ( Owner ) s.get( Owner.class, owner.getId() );
 		assertNotNull( owner );
 		assertNotNull( owner.getAddress() );
 		assertEquals( owner.getId(), owner.getAddress().getId() );
@@ -242,10 +248,34 @@
 	}
 
 	/**
+	 * HHH-4606
+	 */
+	public void testJoinColumnConfiguredInXml() {
+		PersistentClass pc = cfg.getClassMapping( Son.class.getName() );
+		Iterator iter = pc.getJoinIterator();
+		Table table = ( ( Join ) iter.next() ).getTable();
+		Iterator columnIter = table.getColumnIterator();
+		boolean fooFound = false;
+		boolean barFound = false;
+		while ( columnIter.hasNext() ) {
+			Column column = ( Column ) columnIter.next();
+			if ( column.getName().equals( "foo" ) ) {
+				fooFound = true;
+			}
+			if ( column.getName().equals( "bar" ) ) {
+				barFound = true;
+			}
+		}
+		assertTrue(
+				"The mapping defines join columns which could not be found in the metadata.", fooFound && barFound
+		);
+	}
+
+	/**
 	 * @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses()
 	 */
 	protected Class[] getAnnotatedClasses() {
-		return new Class[]{
+		return new Class[] {
 				PartyAffiliate.class,
 				Party.class,
 				Trousers.class,
@@ -265,4 +295,7 @@
 		};
 	}
 
+	protected String[] getXmlFiles() {
+		return new String[] { "org/hibernate/test/annotations/onetoone/orm.xml" };
+	}
 }


Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java
___________________________________________________________________
Name: svn:keywords
   - Date Revision Author Id
   + Id

Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Son.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Son.java	                        (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Son.java	2010-02-24 18:45:11 UTC (rev 18870)
@@ -0,0 +1,62 @@
+// $Id$
+/*
+ * 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.test.annotations.onetoone;
+
+/**
+ * @author Hardy Ferentschik
+ */
+public class Son {
+		private int id;
+
+	private String name;
+
+	private Father father;
+
+	public int getId() {
+		return id;
+	}
+
+	public void setId(int id) {
+		this.id = id;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Father getFather() {
+		return father;
+	}
+
+	public void setFather(Father father) {
+		this.father = father;
+	}
+}
+
+


Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/onetoone/Son.java
___________________________________________________________________
Name: svn:keywords
   + Id

Copied: core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetoone/orm.xml (from rev 18869, core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetomany/orm.xml)
===================================================================
--- core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetoone/orm.xml	                        (rev 0)
+++ core/trunk/annotations/src/test/resources/org/hibernate/test/annotations/onetoone/orm.xml	2010-02-24 18:45:11 UTC (rev 18870)
@@ -0,0 +1,29 @@
+<?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"
+                 version="2.0">
+    <package>org.hibernate.test.annotations.onetoone</package>
+    <entity class="Father">
+        <attributes>
+            <id name="id">
+                <generated-value strategy="AUTO"/>
+            </id>
+            <basic name="name"/>
+        </attributes>
+    </entity>
+    <entity class="Son">
+        <attributes>
+            <id name="id">
+                <generated-value strategy="AUTO"/>
+            </id>
+            <basic name="name"/>
+            <one-to-one name="father">
+                <join-table name="father_son">
+                    <join-column name="foo"/>
+                    <inverse-join-column name="bar"/>
+                </join-table>
+            </one-to-one>
+        </attributes>
+    </entity>
+</entity-mappings>
\ No newline at end of file



More information about the hibernate-commits mailing list