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;
|
||||
|
@ -37,7 +43,7 @@ public class OneToOneTest extends TestCase {
|
|||
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 @@ public class OneToOneTest extends TestCase {
|
|||
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 @@ public class OneToOneTest extends TestCase {
|
|||
|
||||
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 @@ 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;
|
||||
|
@ -118,7 +124,7 @@ public class OneToOneTest extends TestCase {
|
|||
|
||||
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 @@ public class OneToOneTest extends TestCase {
|
|||
|
||||
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 @@ public class OneToOneTest extends TestCase {
|
|||
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 @@ 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 );
|
||||
|
@ -207,13 +213,13 @@ public class OneToOneTest extends TestCase {
|
|||
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 @@ public class OneToOneTest extends TestCase {
|
|||
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() );
|
||||
|
@ -241,11 +247,35 @@ 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()
|
||||
*/
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[]{
|
||||
return new Class[] {
|
||||
PartyAffiliate.class,
|
||||
Party.class,
|
||||
Trousers.class,
|
||||
|
@ -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