[hibernate-commits] Hibernate SVN: r18560 - in core/trunk: core/src/main/java/org/hibernate/engine and 6 other directories.
hibernate-commits at lists.jboss.org
hibernate-commits at lists.jboss.org
Fri Jan 15 00:38:59 EST 2010
Author: steve.ebersole at jboss.com
Date: 2010-01-15 00:38:57 -0500 (Fri, 15 Jan 2010)
New Revision: 18560
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
Log:
HHH-4726 - Add support for delete-orphan cascading to <one-to-one/>
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-14 21:32:33 UTC (rev 18559)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -1615,13 +1615,9 @@
Attribute fkNode = node.attribute( "foreign-key" );
if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() );
- validateCascade( node, path );
- }
-
- private static void validateCascade(Element node, String path) {
String cascade = node.attributeValue( "cascade" );
if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
- throw new MappingException( "single-valued associations do not support orphan delete: " + path );
+ throw new MappingException( "many-to-one attributes do not support orphan delete: " + path );
}
}
@@ -1687,8 +1683,6 @@
oneToOne.setPropertyName( node.attributeValue( "name" ) );
oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );
-
- validateCascade( node, path );
}
public static void bindOneToMany(Element node, OneToMany oneToMany, Mappings mappings)
Modified: core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-14 21:32:33 UTC (rev 18559)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -109,6 +109,10 @@
this.action = action;
}
+ private SessionFactoryImplementor getFactory() {
+ return eventSource.getFactory();
+ }
+
/**
* Cascade an action from the parent entity instance to all its children.
*
@@ -206,8 +210,56 @@
cascadeComponent( parent, child, (AbstractComponentType) type, anything );
}
}
+ else {
+ // potentially we need to handle orphan deletes for one-to-ones here...
+ if ( isLogicalOneToOne( type ) ) {
+ // We have a physical or logical one-to-one and from previous checks we know we
+ // have a null value. See if the attribute cascade settings and action-type require
+ // orphan checking
+ if ( style.hasOrphanDelete() && action.deleteOrphans() ) {
+ // value is orphaned if loaded state for this property shows not null
+ // because it is currently null.
+ final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
+ if ( entry != null ) {
+ final EntityType entityType = (EntityType) type;
+ final Object loadedValue = entry.getLoadedValue( entityType.getPropertyName() );
+ if ( loadedValue != null ) {
+ final String entityName = entityType.getAssociatedEntityName();
+ if ( log.isTraceEnabled() ) {
+ log.trace( "deleting orphaned entity instance: " + entityName );
+ }
+ eventSource.delete( entityName, loadedValue, false, new HashSet() );
+ }
+ }
+ }
+ }
+ }
}
+ /**
+ * Check if the association is a one to one in the logical model (either a shared-pk
+ * or unique fk).
+ *
+ * @param type The type representing the attribute metadata
+ *
+ * @return True if the attribute represents a logical one to one association
+ */
+ private boolean isLogicalOneToOne(Type type) {
+ if ( ! type.isEntityType() ) {
+ return false;
+ }
+ final EntityType entityType = (EntityType) type;
+ if ( entityType.isOneToOne() ) {
+ // physical one-to-one
+ return true;
+ }
+ // todo : still need to handle the many-to-one w/ property-ref
+ // actually there is a question about whether the constrained side
+ // can declare the orphan-delete. If not, then the side declaring
+ // the orphan-delete can only ever be a <one-to-one/>
+ return false;
+ }
+
private boolean cascadeAssociationNow(AssociationType associationType) {
return associationType.getForeignKeyDirection().cascadeNow(cascadeTo) &&
( eventSource.getEntityMode()!=EntityMode.DOM4J || associationType.isEmbeddedInXML() );
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.fk.bidirectional;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteOneToOneOrphansTest extends FunctionalTestCase {
+ public DeleteOneToOneOrphansTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "orphan/one2one/fk/bidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo( emp ) );
+ session.save( emp );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private void cleanupData() {
+ Session session = openSession();
+ session.beginTransaction();
+ session.createQuery( "delete EmployeeInfo" ).executeUpdate();
+ session.createQuery( "delete Employee" ).executeUpdate();
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testOrphanedWhileManaged() {
+ createData();
+
+ Session session = openSession();
+ session.beginTransaction();
+ List results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 1, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ Employee emp = ( Employee ) results.get( 0 );
+ assertNotNull( emp.getInfo() );
+ emp.setInfo( null );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ emp = ( Employee ) session.get( Employee.class, emp.getId() );
+ assertNull( emp.getInfo() );
+ results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 0, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ session.getTransaction().commit();
+ session.close();
+
+ cleanupData();
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,50 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.fk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+ private Long id;
+ private EmployeeInfo info;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public EmployeeInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(EmployeeInfo info) {
+ this.info = info;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.fk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+ private Employee employee;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Employee employee) {
+ this.employee = employee;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ ~
+ ~ 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
+ -->
+
+<!DOCTYPE hibernate-mapping PUBLIC
+ '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
+ 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
+
+<hibernate-mapping package="org.hibernate.test.orphan.one2one.fk.bidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <one-to-one name="info"
+ property-ref="employee"
+ class="EmployeeInfo"
+ cascade="all,delete-orphan"
+ constrained="false" />
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <many-to-one name="employee"
+ column="employee_id"
+ unique="true"
+ not-null="true" />
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.pk.bidirectional;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteOneToOneOrphansTest extends FunctionalTestCase {
+ public DeleteOneToOneOrphansTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "orphan/one2one/pk/bidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo( emp ) );
+ session.save( emp );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private void cleanupData() {
+ Session session = openSession();
+ session.beginTransaction();
+ session.createQuery( "delete EmployeeInfo" ).executeUpdate();
+ session.createQuery( "delete Employee" ).executeUpdate();
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testOrphanedWhileManaged() {
+ createData();
+
+ Session session = openSession();
+ session.beginTransaction();
+ List results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 1, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ Employee emp = ( Employee ) results.get( 0 );
+ assertNotNull( emp.getInfo() );
+ emp.setInfo( null );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ emp = ( Employee ) session.get( Employee.class, emp.getId() );
+ assertNull( emp.getInfo() );
+ results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 0, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ session.getTransaction().commit();
+ session.close();
+
+ cleanupData();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,50 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.pk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+ private Long id;
+ private EmployeeInfo info;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public EmployeeInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(EmployeeInfo info) {
+ this.info = info;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ *
+ * 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.orphan.one2one.pk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+ private Employee employee;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Employee employee) {
+ this.employee = employee;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. 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 Inc.
+ ~
+ ~ 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
+ -->
+
+<!DOCTYPE hibernate-mapping PUBLIC
+ '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
+ 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
+
+<hibernate-mapping package="org.hibernate.test.orphan.one2one.pk.bidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <one-to-one name="info"
+ class="EmployeeInfo"
+ cascade="all,delete-orphan"
+ constrained="false" />
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="foreign">
+ <param name="property">employee</param>
+ </generator>
+ </id>
+ <one-to-one name="employee"
+ class="Employee"
+ constrained="true" />
+ </class>
+
+</hibernate-mapping>
More information about the hibernate-commits
mailing list