HHH-4606 Functionality was actually already there. Just added a test
git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@18870 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
7a26f5862c
commit
523842514f
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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;
|
||||
|
@ -105,7 +111,7 @@ public class OneToOneTest extends TestCase {
|
|||
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;
|
||||
|
@ -196,8 +202,8 @@ public class OneToOneTest extends TestCase {
|
|||
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 );
|
||||
|
@ -241,6 +247,30 @@ public class OneToOneTest extends TestCase {
|
|||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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()
|
||||
*/
|
||||
|
@ -265,4 +295,7 @@ public class OneToOneTest extends TestCase {
|
|||
};
|
||||
}
|
||||
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/onetoone/orm.xml" };
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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>
|
Loading…
Reference in New Issue