Hibernate SVN: r18573 - in core/trunk: testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-18 13:27:12 -0500 (Mon, 18 Jan 2010)
New Revision: 18573
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Mapping.hbm.xml
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.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-18 16:32:46 UTC (rev 18572)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-18 18:27:12 UTC (rev 18573)
@@ -1101,6 +1101,16 @@
simpleValue.addFormula( formula );
}
}
+
+ // todo : another GoodThing would be to go back after all parsing and see if all the columns
+ // (and no formulas) are contained in a defined unique key that only contains these columns.
+ // That too would mark this as a logical one-to-one
+ final Attribute uniqueAttribute = node.attribute( "unique" );
+ if ( uniqueAttribute != null
+ && "true".equals( uniqueAttribute.getValue() )
+ && ManyToOne.class.isInstance( simpleValue ) ) {
+ ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
+ }
}
else {
if ( node.elementIterator( "column" ).hasNext() ) {
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/DeleteOneToOneOrphansTest.java (from rev 18568, core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java)
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/DeleteOneToOneOrphansTest.java 2010-01-18 18:27:12 UTC (rev 18573)
@@ -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.composite;
+
+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/composite/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo( 1L, 1L) );
+ 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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Employee.java (from rev 18560, 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/composite/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Employee.java 2010-01-18 18:27:12 UTC (rev 18573)
@@ -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.composite;
+
+/**
+ * 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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/EmployeeInfo.java (from rev 18560, 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/composite/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/EmployeeInfo.java 2010-01-18 18:27:12 UTC (rev 18573)
@@ -0,0 +1,106 @@
+/*
+ * 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.composite;
+
+import java.io.Serializable;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ public static class Id implements Serializable {
+ private Long companyId;
+ private Long personId;
+
+ public Id() {
+ }
+
+ public Id(Long companyId, Long personId) {
+ this.companyId = companyId;
+ this.personId = personId;
+ }
+
+ public Long getCompanyId() {
+ return companyId;
+ }
+
+ public void setCompanyId(Long companyId) {
+ this.companyId = companyId;
+ }
+
+ public Long getPersonId() {
+ return personId;
+ }
+
+ public void setPersonId(Long personId) {
+ this.personId = personId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() ) {
+ return false;
+ }
+
+ Id id = (Id) o;
+
+ return companyId.equals( id.companyId )
+ && personId.equals( id.personId );
+
+ }
+
+ @Override
+ public int hashCode() {
+ int result = companyId.hashCode();
+ result = 31 * result + personId.hashCode();
+ return result;
+ }
+ }
+
+ private Id id;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Long companyId, Long personId) {
+ this( new Id( companyId, personId ) );
+ }
+
+ public EmployeeInfo(Id id) {
+ this.id = id;
+ }
+
+ public Id getId() {
+ return id;
+ }
+
+ public void setId(Id id) {
+ this.id = id;
+ }
+}
\ No newline at end of file
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Mapping.hbm.xml (from rev 18560, 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/composite/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/composite/Mapping.hbm.xml 2010-01-18 18:27:12 UTC (rev 18573)
@@ -0,0 +1,49 @@
+<?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.composite" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <many-to-one name="info" unique="true" cascade="all,delete-orphan">
+ <column name="COMP_ID" />
+ <column name="PERS_ID" />
+ </many-to-one>
+ </class>
+
+ <class name="EmployeeInfo">
+ <composite-id class="EmployeeInfo$Id" name="id">
+ <key-property name="companyId" column="COMP_ID" />
+ <key-property name="personId" column="PERS_ID" />
+ </composite-id>
+ </class>
+
+</hibernate-mapping>
14 years, 3 months
Hibernate SVN: r18572 - in validator/trunk/hibernate-validator/src: main/java/org/hibernate/validator/constraints/impl and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-18 11:32:46 -0500 (Mon, 18 Jan 2010)
New Revision: 18572
Added:
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/URL.java
validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/URLValidator.java
validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/URLValidatorTest.java
Log:
HV-229 -first cut of @URL using java.net.URL to implemenet its logic
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/URL.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/URL.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/URL.java 2010-01-18 16:32:46 UTC (rev 18572)
@@ -0,0 +1,48 @@
+// $Id: Length.java 17427 2009-08-27 09:47:28Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.constraints;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+import javax.validation.Constraint;
+import javax.validation.Payload;
+
+import org.hibernate.validator.constraints.impl.URLValidator;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Validate that the string is a valid URL.
+ *
+ * @author Hardy Ferentschik
+ */
+@Documented
+@Constraint(validatedBy = URLValidator.class)
+@Target({ METHOD, FIELD, TYPE })
+@Retention(RUNTIME)
+public @interface URL {
+ public abstract String message() default "{org.hibernate.validator.constraints.URL.message}";
+
+ public abstract Class<?>[] groups() default { };
+
+ public abstract Class<? extends Payload>[] payload() default { };
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/URLValidator.java
===================================================================
--- validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/URLValidator.java (rev 0)
+++ validator/trunk/hibernate-validator/src/main/java/org/hibernate/validator/constraints/impl/URLValidator.java 2010-01-18 16:32:46 UTC (rev 18572)
@@ -0,0 +1,47 @@
+// $Id: LengthValidator.java 17521 2009-09-16 12:50:41Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.constraints.impl;
+
+import java.net.MalformedURLException;
+import javax.validation.ConstraintValidator;
+import javax.validation.ConstraintValidatorContext;
+
+import org.hibernate.validator.constraints.URL;
+
+/**
+ * Validate that the string is a valid URL.
+ *
+ * @author Hardy Ferentschik
+ */
+public class URLValidator implements ConstraintValidator<URL, String> {
+ public void initialize(URL url) {
+ }
+
+ public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
+ if ( value == null ) {
+ return true;
+ }
+ try {
+ new java.net.URL( value );
+ return true;
+ }
+ catch ( MalformedURLException e ) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
Added: validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/URLValidatorTest.java
===================================================================
--- validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/URLValidatorTest.java (rev 0)
+++ validator/trunk/hibernate-validator/src/test/java/org/hibernate/validator/constraints/impl/URLValidatorTest.java 2010-01-18 16:32:46 UTC (rev 18572)
@@ -0,0 +1,48 @@
+// $Id: LengthValidatorTest.java 17521 2009-09-16 12:50:41Z hardy.ferentschik $
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.validator.constraints.impl;
+
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+import org.testng.annotations.Test;
+
+import org.hibernate.validator.constraints.URL;
+import org.hibernate.validator.util.annotationfactory.AnnotationDescriptor;
+import org.hibernate.validator.util.annotationfactory.AnnotationFactory;
+
+/**
+ * Tests the {@code Url} constraint.
+ *
+ * @author Hardy Ferentschik
+ */
+public class URLValidatorTest {
+
+ @Test
+ public void testIsValidUrl() {
+ AnnotationDescriptor<URL> descriptor = new AnnotationDescriptor<URL>( URL.class );
+ descriptor.setValue( "message", "{org.hibernate.validator.constraints.URL.message}" );
+ URL url = AnnotationFactory.create( descriptor );
+ URLValidator validator = new URLValidator();
+ validator.initialize( url );
+ assertTrue( validator.isValid( null, null ) );
+ assertFalse( validator.isValid( "", null ) );
+ assertFalse( validator.isValid( "http", null ) );
+ assertFalse( validator.isValid( "ftp//abc.de", null ) );
+ assertTrue( validator.isValid( "ftp://abc.de", null ) );
+ }
+}
\ No newline at end of file
14 years, 3 months
Hibernate SVN: r18571 - in core/trunk: testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-18 10:18:16 -0500 (Mon, 18 Jan 2010)
New Revision: 18571
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Mapping.hbm.xml
Modified:
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/engine/Cascade.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-18 14:15:38 UTC (rev 18570)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-18 15:18:16 UTC (rev 18571)
@@ -225,8 +225,7 @@
// 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;
+ if ( entry != null && entry.getStatus() != Status.SAVING ) {
final Object loadedValue;
if ( componentPathStack.isEmpty() ) {
// association defined on entity
@@ -245,6 +244,7 @@
// set of SQL statements though since we do not know the
// orphaned value, something a delete with a subquery to
// match the owner.
+// final EntityType entityType = (EntityType) type;
// final String propertyPath = composePropertyPath( entityType.getPropertyName() );
loadedValue = null;
}
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/DeleteOneToOneOrphansTest.java (from rev 18560, 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/unidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/DeleteOneToOneOrphansTest.java 2010-01-18 15:18:16 UTC (rev 18571)
@@ -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.unidirectional;
+
+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/unidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ session.save( emp );
+ emp.setInfo( new EmployeeInfo( emp.getId() ) );
+ 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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Employee.java (from rev 18560, 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/unidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Employee.java 2010-01-18 15:18:16 UTC (rev 18571)
@@ -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.unidirectional;
+
+/**
+ * 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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/EmployeeInfo.java (from rev 18560, 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/unidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/EmployeeInfo.java 2010-01-18 15:18:16 UTC (rev 18571)
@@ -0,0 +1,48 @@
+/*
+ * 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.unidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Long id) {
+ this.id = id;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+}
\ No newline at end of file
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Mapping.hbm.xml (from rev 18560, 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/unidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/unidirectional/Mapping.hbm.xml 2010-01-18 15:18:16 UTC (rev 18571)
@@ -0,0 +1,48 @@
+<?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.unidirectional" >
+
+ <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="assigned" />
+ </id>
+ </class>
+
+</hibernate-mapping>
14 years, 3 months
Hibernate SVN: r18570 - search/trunk/src/main/java/org/hibernate/search/impl.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-18 09:15:38 -0500 (Mon, 18 Jan 2010)
New Revision: 18570
Modified:
search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
Log:
Added isReadOnly(Object)
Modified: search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-01-16 21:04:34 UTC (rev 18569)
+++ search/trunk/src/main/java/org/hibernate/search/impl/FullTextSessionImpl.java 2010-01-18 14:15:38 UTC (rev 18570)
@@ -638,6 +638,10 @@
return session.getStatistics();
}
+ public boolean isReadOnly(Object entityOrProxy) {
+ return session.isReadOnly( entityOrProxy );
+ }
+
public Transaction getTransaction() {
return session.getTransaction();
}
14 years, 3 months
Hibernate SVN: r18569 - core/trunk/core/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-16 16:04:34 -0500 (Sat, 16 Jan 2010)
New Revision: 18569
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.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-16 20:27:04 UTC (rev 18568)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-16 21:04:34 UTC (rev 18569)
@@ -1621,7 +1621,9 @@
String cascade = node.attributeValue( "cascade" );
if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
if ( !manyToOne.isLogicalOneToOne() ) {
- throw new MappingException( "many-to-one attributes do not support orphan delete: " + path );
+ throw new MappingException(
+ "many-to-one attribute [" + path + "] does not support orphan delete as it is not unique"
+ );
}
}
}
@@ -1688,6 +1690,15 @@
oneToOne.setPropertyName( node.attributeValue( "name" ) );
oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );
+
+ String cascade = node.attributeValue( "cascade" );
+ if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
+ if ( oneToOne.isConstrained() ) {
+ throw new MappingException(
+ "one-to-one attribute [" + path + "] does not support orphan delete as it is constrained"
+ );
+ }
+ }
}
public static void bindOneToMany(Element node, OneToMany oneToMany, Mappings mappings)
14 years, 4 months
Hibernate SVN: r18568 - in core/trunk: core/src/main/java/org/hibernate/engine and 8 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-16 15:27:04 -0500 (Sat, 16 Jan 2010)
New Revision: 18568
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Mapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/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
core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java
core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
core/trunk/core/src/main/java/org/hibernate/type/EntityType.java
core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java
core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomPersister.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-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -1064,10 +1064,10 @@
// COLUMN(S)
Attribute columnAttribute = node.attribute( "column" );
if ( columnAttribute == null ) {
- Iterator iter = node.elementIterator();
+ Iterator itr = node.elementIterator();
int count = 0;
- while ( iter.hasNext() ) {
- Element columnElement = (Element) iter.next();
+ while ( itr.hasNext() ) {
+ Element columnElement = (Element) itr.next();
if ( columnElement.getName().equals( "column" ) ) {
Column column = new Column();
column.setValue( simpleValue );
@@ -1115,6 +1115,9 @@
Column column = new Column();
column.setValue( simpleValue );
bindColumn( node, column, isNullable );
+ if ( column.isUnique() && ManyToOne.class.isInstance( simpleValue ) ) {
+ ( (ManyToOne) simpleValue ).markAsLogicalOneToOne();
+ }
final String columnName = columnAttribute.getValue();
String logicalColumnName = mappings.getNamingStrategy().logicalColumnName(
columnName, propertyPath
@@ -1617,7 +1620,9 @@
String cascade = node.attributeValue( "cascade" );
if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
- throw new MappingException( "many-to-one attributes do not support orphan delete: " + path );
+ if ( !manyToOne.isLogicalOneToOne() ) {
+ throw new MappingException( "many-to-one attributes do not support orphan delete: " + path );
+ }
}
}
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-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,13 +20,14 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.engine;
+import java.io.Serializable;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.Stack;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -36,6 +37,7 @@
import org.hibernate.event.EventSource;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.entity.EntityPersister;
+import org.hibernate.pretty.MessageHelper;
import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
@@ -148,7 +150,8 @@
EntityMode entityMode = eventSource.getEntityMode();
boolean hasUninitializedLazyProperties = persister.hasUninitializedLazyProperties( parent, entityMode );
for ( int i=0; i<types.length; i++) {
- CascadeStyle style = cascadeStyles[i];
+ final CascadeStyle style = cascadeStyles[i];
+ final String propertyName = persister.getPropertyNames()[i];
if ( hasUninitializedLazyProperties && persister.getPropertyLaziness()[i] && ! action.performOnLazyProperty() ) {
//do nothing to avoid a lazy property initialization
continue;
@@ -160,6 +163,7 @@
persister.getPropertyValue( parent, i, entityMode ),
types[i],
style,
+ propertyName,
anything,
false
);
@@ -189,6 +193,7 @@
final Object child,
final Type type,
final CascadeStyle style,
+ final String propertyName,
final Object anything,
final boolean isCascadeDeleteEnabled) throws HibernateException {
@@ -207,7 +212,7 @@
}
}
else if ( type.isComponentType() ) {
- cascadeComponent( parent, child, (AbstractComponentType) type, anything );
+ cascadeComponent( parent, child, (AbstractComponentType) type, propertyName, anything );
}
}
else {
@@ -222,11 +227,34 @@
final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
if ( entry != null ) {
final EntityType entityType = (EntityType) type;
- final Object loadedValue = entry.getLoadedValue( entityType.getPropertyName() );
+ final Object loadedValue;
+ if ( componentPathStack.isEmpty() ) {
+ // association defined on entity
+ loadedValue = entry.getLoadedValue( propertyName );
+ }
+ else {
+ // association defined on component
+ // todo : this is currently unsupported because of the fact that
+ // we do not know the loaded state of this value properly
+ // and doing so would be very difficult given how components and
+ // entities are loaded (and how 'loaded state' is put into the
+ // EntityEntry). Solutions here are to either:
+ // 1) properly account for components as a 2-phase load construct
+ // 2) just assume the association was just now orphaned and
+ // issue the orphan delete. This would require a special
+ // set of SQL statements though since we do not know the
+ // orphaned value, something a delete with a subquery to
+ // match the owner.
+// final String propertyPath = composePropertyPath( entityType.getPropertyName() );
+ loadedValue = null;
+ }
if ( loadedValue != null ) {
- final String entityName = entityType.getAssociatedEntityName();
+ final String entityName = entry.getPersister().getEntityName();
if ( log.isTraceEnabled() ) {
- log.trace( "deleting orphaned entity instance: " + entityName );
+ final Serializable id = entry.getPersister()
+ .getIdentifier( loadedValue, eventSource.getEntityMode() );
+ final String description = MessageHelper.infoString( entityName, id );
+ log.trace( "deleting orphaned entity instance: " + description );
}
eventSource.delete( entityName, loadedValue, false, new HashSet() );
}
@@ -245,21 +273,26 @@
* @return True if the attribute represents a logical one to one association
*/
private boolean isLogicalOneToOne(Type type) {
- if ( ! type.isEntityType() ) {
- return false;
+ return type.isEntityType() && ( (EntityType) type ).isLogicalOneToOne();
+ }
+
+ private String composePropertyPath(String propertyName) {
+ if ( componentPathStack.isEmpty() ) {
+ return propertyName;
}
- final EntityType entityType = (EntityType) type;
- if ( entityType.isOneToOne() ) {
- // physical one-to-one
- return true;
+ else {
+ StringBuffer buffer = new StringBuffer();
+ Iterator itr = componentPathStack.iterator();
+ while ( itr.hasNext() ) {
+ buffer.append( itr.next() ).append( '.' );
+ }
+ buffer.append( propertyName );
+ return buffer.toString();
}
- // 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 Stack componentPathStack = new Stack();
+
private boolean cascadeAssociationNow(AssociationType associationType) {
return associationType.getForeignKeyDirection().cascadeNow(cascadeTo) &&
( eventSource.getEntityMode()!=EntityMode.DOM4J || associationType.isEmbeddedInXML() );
@@ -269,22 +302,27 @@
final Object parent,
final Object child,
final AbstractComponentType componentType,
+ final String componentPropertyName,
final Object anything) {
- Object[] children = componentType.getPropertyValues(child, eventSource);
+ componentPathStack.push( componentPropertyName );
+ Object[] children = componentType.getPropertyValues( child, eventSource );
Type[] types = componentType.getSubtypes();
for ( int i=0; i<types.length; i++ ) {
- CascadeStyle componentPropertyStyle = componentType.getCascadeStyle(i);
+ final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle(i);
+ final String subPropertyName = componentType.getPropertyNames()[i];
if ( componentPropertyStyle.doCascade(action) ) {
cascadeProperty(
parent,
children[i],
types[i],
componentPropertyStyle,
+ subPropertyName,
anything,
false
);
}
}
+ componentPathStack.pop();
}
private void cascadeAssociation(
@@ -389,7 +427,8 @@
parent,
iter.next(),
elemType,
- style,
+ style,
+ null,
anything,
isCascadeDeleteEnabled
);
Modified: core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/engine/EntityEntry.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.engine;
@@ -29,7 +28,6 @@
import java.io.IOException;
import java.io.ObjectInputStream;
-
import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.LockMode;
@@ -84,13 +82,9 @@
this.loadedWithLazyPropertiesUnfetched = lazyPropertiesAreUnfetched;
this.persister=persister;
this.entityMode = entityMode;
- this.entityName = persister == null ?
- null : persister.getEntityName();
+ this.entityName = persister == null ? null : persister.getEntityName();
}
- /**
- * Used during custom deserialization
- */
private EntityEntry(
final SessionFactoryImplementor factory,
final String entityName,
@@ -104,6 +98,7 @@
final boolean existsInDatabase,
final boolean isBeingReplicated,
final boolean loadedWithLazyPropertiesUnfetched) {
+ // Used during custom deserialization
this.entityName = entityName;
this.persister = ( factory == null ? null : factory.getEntityPersister( entityName ) );
this.id = id;
@@ -181,10 +176,6 @@
return cachedEntityKey;
}
- void afterDeserialize(SessionFactoryImplementor factory) {
- persister = factory.getEntityPersister( entityName );
- }
-
public String getEntityName() {
return entityName;
}
@@ -198,24 +189,29 @@
}
/**
- * After actually updating the database, update the snapshot information,
- * and escalate the lock mode
+ * Handle updating the internal state of the entry after actually performing
+ * the database update. Specifically we update the snapshot information and
+ * escalate the lock mode
+ *
+ * @param entity The entity instance
+ * @param updatedState The state calculated after the update (becomes the
+ * new {@link #getLoadedState() loaded state}.
+ * @param nextVersion The new version.
*/
public void postUpdate(Object entity, Object[] updatedState, Object nextVersion) {
this.loadedState = updatedState;
-
setLockMode(LockMode.WRITE);
-
+
if ( getPersister().isVersioned() ) {
this.version = nextVersion;
- getPersister().setPropertyValue(
- entity,
+ getPersister().setPropertyValue(
+ entity,
getPersister().getVersionProperty(),
nextVersion,
entityMode
- );
+ );
}
-
+
FieldInterceptionHelper.clearDirty( entity );
}
@@ -249,8 +245,7 @@
int propertyIndex = ( (UniqueKeyLoadable) persister ).getPropertyIndex(propertyName);
return loadedState[propertyIndex];
}
-
-
+
public boolean requiresDirtyCheck(Object entity) {
boolean isMutableInstance =
@@ -268,6 +263,7 @@
public void forceLocked(Object entity, Object nextVersion) {
version = nextVersion;
loadedState[ persister.getVersionProperty() ] = version;
+ //noinspection deprecation
setLockMode( LockMode.FORCE ); // TODO: use LockMode.PESSIMISTIC_FORCE_INCREMENT
persister.setPropertyValue(
entity,
@@ -309,13 +305,13 @@
return loadedWithLazyPropertiesUnfetched;
}
-
/**
* Custom serialization routine used during serialization of a
* Session/PersistenceContext for increased performance.
*
* @param oos The stream to which we should write the serial data.
- * @throws java.io.IOException
+ *
+ * @throws IOException If a stream error occurs
*/
void serialize(ObjectOutputStream oos) throws IOException {
oos.writeObject( entityName );
@@ -338,9 +334,12 @@
*
* @param ois The stream from which to read the entry.
* @param session The session being deserialized.
+ *
* @return The deserialized EntityEntry
- * @throws IOException
- * @throws ClassNotFoundException
+ *
+ * @throws IOException If a stream error occurs
+ * @throws ClassNotFoundException If any of the classes declared in the stream
+ * cannot be found
*/
static EntityEntry deserialize(
ObjectInputStream ois,
@@ -353,7 +352,7 @@
Status.parse( ( String ) ois.readObject() ),
( Object[] ) ois.readObject(),
( Object[] ) ois.readObject(),
- ( Object ) ois.readObject(),
+ ois.readObject(),
LockMode.parse( ( String ) ois.readObject() ),
ois.readBoolean(),
ois.readBoolean(),
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/ManyToOne.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -38,8 +38,8 @@
* @author Gavin King
*/
public class ManyToOne extends ToOne {
-
private boolean ignoreNotFound;
+ private boolean isLogicalOneToOne;
public ManyToOne(Table table) {
super(table);
@@ -52,8 +52,9 @@
isLazy(),
isUnwrapProxy(),
isEmbedded(),
- isIgnoreNotFound()
- );
+ isIgnoreNotFound(),
+ isLogicalOneToOne
+ );
}
public void createForeignKey() throws MappingException {
@@ -110,5 +111,11 @@
this.ignoreNotFound = ignoreNotFound;
}
-
+ public void markAsLogicalOneToOne() {
+ this.isLogicalOneToOne = true;
+ }
+
+ public boolean isLogicalOneToOne() {
+ return isLogicalOneToOne;
+ }
}
Modified: core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
+ * 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 Middleware LLC.
+ * 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
@@ -20,7 +20,6 @@
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
- *
*/
package org.hibernate.tuple.entity;
@@ -29,7 +28,6 @@
import java.util.Map;
import java.util.Set;
-import org.hibernate.EntityMode;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.tuple.Instantiator;
@@ -132,12 +130,12 @@
getters = new Getter[propertySpan];
setters = new Setter[propertySpan];
- Iterator iter = mappingInfo.getPropertyClosureIterator();
+ Iterator itr = mappingInfo.getPropertyClosureIterator();
boolean foundCustomAccessor=false;
int i=0;
- while ( iter.hasNext() ) {
+ while ( itr.hasNext() ) {
//TODO: redesign how PropertyAccessors are acquired...
- Property property = (Property) iter.next();
+ Property property = (Property) itr.next();
getters[i] = buildPropertyGetter(property, mappingInfo);
setters[i] = buildPropertySetter(property, mappingInfo);
if ( !property.isBasicPropertyAccessor() ) {
@@ -172,7 +170,7 @@
}
/**
- * Retreives the defined entity-names for any subclasses defined for this
+ * Retrieves the defined entity-names for any subclasses defined for this
* entity.
*
* @return Any subclass entity-names.
@@ -208,7 +206,7 @@
catch ( ClassCastException cce ) {
StringBuffer msg = new StringBuffer( "Identifier classes must be serializable. " );
if ( id != null ) {
- msg.append( id.getClass().getName() + " is not serializable. " );
+ msg.append( id.getClass().getName() ).append( " is not serializable. " );
}
if ( cce.getMessage() != null ) {
msg.append( cce.getMessage() );
@@ -296,16 +294,21 @@
}
public Object getPropertyValue(Object entity, String propertyPath) throws HibernateException {
-
- int loc = propertyPath.indexOf('.');
- String basePropertyName = loc>0 ?
- propertyPath.substring(0, loc) : propertyPath;
-
- int index = entityMetamodel.getPropertyIndex( basePropertyName );
- Object baseValue = getPropertyValue( entity, index );
- if ( loc>0 ) {
- ComponentType type = (ComponentType) entityMetamodel.getPropertyTypes()[index];
- return getComponentValue( type, baseValue, propertyPath.substring(loc+1) );
+ final int loc = propertyPath.indexOf('.');
+ final String basePropertyName = loc > 0
+ ? propertyPath.substring( 0, loc )
+ : propertyPath;
+ final int index = entityMetamodel.getPropertyIndex( basePropertyName );
+ final Object baseValue = getPropertyValue( entity, index );
+ if ( loc > 0 ) {
+ if ( baseValue == null ) {
+ return null;
+ }
+ return getComponentValue(
+ (ComponentType) entityMetamodel.getPropertyTypes()[index],
+ baseValue,
+ propertyPath.substring(loc+1)
+ );
}
else {
return baseValue;
@@ -321,32 +324,38 @@
* @return The property value extracted.
*/
protected Object getComponentValue(ComponentType type, Object component, String propertyPath) {
-
- int loc = propertyPath.indexOf('.');
- String basePropertyName = loc>0 ?
- propertyPath.substring(0, loc) : propertyPath;
-
- String[] propertyNames = type.getPropertyNames();
- int index=0;
- for ( ; index<propertyNames.length; index++ ) {
- if ( basePropertyName.equals( propertyNames[index] ) ) break;
+ final int loc = propertyPath.indexOf( '.' );
+ final String basePropertyName = loc > 0
+ ? propertyPath.substring( 0, loc )
+ : propertyPath;
+ final int index = findSubPropertyIndex( type, basePropertyName );
+ final Object baseValue = type.getPropertyValue( component, index, getEntityMode() );
+ if ( loc > 0 ) {
+ if ( baseValue == null ) {
+ return null;
+ }
+ return getComponentValue(
+ (ComponentType) type.getSubtypes()[index],
+ baseValue,
+ propertyPath.substring(loc+1)
+ );
}
- if (index==propertyNames.length) {
- throw new MappingException( "component property not found: " + basePropertyName );
- }
-
- Object baseValue = type.getPropertyValue( component, index, getEntityMode() );
-
- if ( loc>0 ) {
- ComponentType subtype = (ComponentType) type.getSubtypes()[index];
- return getComponentValue( subtype, baseValue, propertyPath.substring(loc+1) );
- }
else {
return baseValue;
}
}
+ private int findSubPropertyIndex(ComponentType type, String subPropertyName) {
+ final String[] propertyNames = type.getPropertyNames();
+ for ( int index = 0; index<propertyNames.length; index++ ) {
+ if ( subPropertyName.equals( propertyNames[index] ) ) {
+ return index;
+ }
+ }
+ throw new MappingException( "component property not found: " + subPropertyName );
+ }
+
public void setPropertyValues(Object entity, Object[] values) throws HibernateException {
boolean setAll = !entityMetamodel.hasLazyProperties();
Modified: core/trunk/core/src/main/java/org/hibernate/type/EntityType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/EntityType.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/type/EntityType.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -508,9 +508,23 @@
return result.toString();
}
+ /**
+ * Is the association modeled here defined as a 1-1 in the database (physical model)?
+ *
+ * @return True if a 1-1 in the database; false otherwise.
+ */
public abstract boolean isOneToOne();
/**
+ * Is the association modeled here a 1-1 according to the logical moidel?
+ *
+ * @return True if a 1-1 in the logical model; false otherwise.
+ */
+ public boolean isLogicalOneToOne() {
+ return isOneToOne();
+ }
+
+ /**
* Convenience method to locate the identifier type of the associated entity.
*
* @param factory The mappings...
Modified: core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -45,27 +45,54 @@
* @author Gavin King
*/
public class ManyToOneType extends EntityType {
-
private final boolean ignoreNotFound;
+ private boolean isLogicalOneToOne;
- public ManyToOneType(String className) {
- this( className, false );
+ /**
+ * Creates a many-to-one association type with the given referenced entity.
+ *
+ * @param referencedEntityName The name iof the referenced entity
+ */
+ public ManyToOneType(String referencedEntityName) {
+ this( referencedEntityName, false );
}
- public ManyToOneType(String className, boolean lazy) {
- super( className, null, !lazy, true, false );
- this.ignoreNotFound = false;
+ /**
+ * Creates a many-to-one association type with the given referenced entity and the
+ * given laziness characteristic
+ *
+ * @param referencedEntityName The name iof the referenced entity
+ * @param lazy Should the association be handled lazily
+ */
+ public ManyToOneType(String referencedEntityName, boolean lazy) {
+ this( referencedEntityName, null, !lazy, true, false, false );
}
+ /**
+ * @deprecated use {@link #ManyToOneType(String, String, boolean, boolean, boolean, boolean, boolean)}
+ * @noinspection JavaDoc
+ */
public ManyToOneType(
- String entityName,
+ String referencedEntityName,
String uniqueKeyPropertyName,
boolean lazy,
boolean unwrapProxy,
boolean isEmbeddedInXML,
boolean ignoreNotFound) {
- super( entityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy );
+ this( referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy, ignoreNotFound, false );
+ }
+
+ public ManyToOneType(
+ String referencedEntityName,
+ String uniqueKeyPropertyName,
+ boolean lazy,
+ boolean unwrapProxy,
+ boolean isEmbeddedInXML,
+ boolean ignoreNotFound,
+ boolean isLogicalOneToOne) {
+ super( referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy );
this.ignoreNotFound = ignoreNotFound;
+ this.isLogicalOneToOne = isLogicalOneToOne;
}
protected boolean isNullable() {
@@ -82,7 +109,11 @@
public boolean isOneToOne() {
return false;
}
-
+
+ public boolean isLogicalOneToOne() {
+ return isLogicalOneToOne;
+ }
+
public int getColumnSpan(Mapping mapping) throws MappingException {
// our column span is the number of columns in the PK
return getIdentifierOrUniqueKeyType( mapping ).getColumnSpan( mapping );
Modified: core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/core/src/main/java/org/hibernate/type/TypeFactory.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -201,6 +201,8 @@
/**
* A many-to-one association type for the given class
+ *
+ * @deprecated Use {@link #manyToOne(String, String, boolean, boolean, boolean, boolean, boolean)}
*/
public static EntityType manyToOne(
String persistentClass,
@@ -208,8 +210,8 @@
boolean lazy,
boolean unwrapProxy,
boolean isEmbeddedInXML,
- boolean ignoreNotFound
- ) {
+ boolean ignoreNotFound) {
+ //noinspection deprecation
return new ManyToOneType(
persistentClass,
uniqueKeyPropertyName,
@@ -217,10 +219,32 @@
unwrapProxy,
isEmbeddedInXML,
ignoreNotFound
- );
+ );
}
/**
+ * A many-to-one association type for the given class
+ */
+ public static EntityType manyToOne(
+ String persistentClass,
+ String uniqueKeyPropertyName,
+ boolean lazy,
+ boolean unwrapProxy,
+ boolean isEmbeddedInXML,
+ boolean ignoreNotFound,
+ boolean isLogicalOneToOne) {
+ return new ManyToOneType(
+ persistentClass,
+ uniqueKeyPropertyName,
+ lazy,
+ unwrapProxy,
+ isEmbeddedInXML,
+ ignoreNotFound,
+ isLogicalOneToOne
+ );
+ }
+
+ /**
* Given the name of a Hibernate basic type, return an instance of
* <tt>org.hibernate.type.Type</tt>.
*/
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomPersister.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomPersister.java 2010-01-15 20:59:56 UTC (rev 18567)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/legacy/CustomPersister.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -629,6 +629,10 @@
return false;
}
+ public String[] getOrphanRemovalOneToOnePaths() {
+ return null;
+ }
+
public Object[] getNaturalIdentifierSnapshot(Serializable id, SessionImplementor session) throws HibernateException {
return null;
}
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/DeleteOneToOneOrphansTest.java (from rev 18560, 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/reversed/bidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/DeleteOneToOneOrphansTest.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -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.reversed.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/reversed/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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Employee.java (from rev 18560, 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/reversed/bidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Employee.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -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.reversed.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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/EmployeeInfo.java (from rev 18560, 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/reversed/bidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/EmployeeInfo.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -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.reversed.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
Copied: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Mapping.hbm.xml (from rev 18560, 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/reversed/bidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/bidirectional/Mapping.hbm.xml 2010-01-16 20:27:04 UTC (rev 18568)
@@ -0,0 +1,51 @@
+<?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.reversed.bidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <many-to-one name="info"
+ column="info_id"
+ unique="true"
+ cascade="all,delete-orphan"/>
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <one-to-one name="employee"
+ property-ref="info"
+ class="Employee" />
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/DeleteOneToOneOrphansTest.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -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.reversed.unidirectional;
+
+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/reversed/unidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo() );
+ 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/reversed/unidirectional/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Employee.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -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.reversed.unidirectional;
+
+/**
+ * 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/reversed/unidirectional/EmployeeInfo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/EmployeeInfo.java 2010-01-16 20:27:04 UTC (rev 18568)
@@ -0,0 +1,44 @@
+/*
+ * 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.reversed.unidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+
+ public EmployeeInfo() {
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Mapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/reversed/unidirectional/Mapping.hbm.xml 2010-01-16 20:27:04 UTC (rev 18568)
@@ -0,0 +1,48 @@
+<?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.reversed.unidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <many-to-one name="info"
+ column="info_id"
+ unique="true"
+ cascade="all,delete-orphan"/>
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ </class>
+
+</hibernate-mapping>
14 years, 4 months
Hibernate SVN: r18567 - in core/trunk/entitymanager/src: main/java/org/hibernate/ejb/packaging and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-15 15:59:56 -0500 (Fri, 15 Jan 2010)
New Revision: 18567
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java
Log:
HHH-4677 - just some import cleanups and addition of source headers. no code changes
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Ejb3Configuration.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
@@ -19,8 +20,6 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
-
-//$Id$
package org.hibernate.ejb;
import java.io.BufferedInputStream;
@@ -31,20 +30,20 @@
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.lang.annotation.Annotation;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.StringTokenizer;
-import java.util.HashSet;
-import java.lang.annotation.Annotation;
import javax.naming.BinaryRefAddr;
import javax.naming.NamingException;
import javax.naming.Reference;
@@ -55,7 +54,6 @@
import javax.persistence.EntityNotFoundException;
import javax.persistence.MappedSuperclass;
import javax.persistence.PersistenceException;
-import javax.persistence.ValidationMode;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.sql.DataSource;
@@ -63,6 +61,11 @@
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.SAXException;
+
import org.hibernate.HibernateException;
import org.hibernate.Interceptor;
import org.hibernate.MappingException;
@@ -77,12 +80,12 @@
import org.hibernate.cfg.annotations.reflection.XMLContext;
import org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider;
import org.hibernate.ejb.instrument.InterceptFieldClassFileTransformer;
+import org.hibernate.ejb.packaging.JarVisitorFactory;
import org.hibernate.ejb.packaging.NamedInputStream;
+import org.hibernate.ejb.packaging.NativeScanner;
import org.hibernate.ejb.packaging.PersistenceMetadata;
import org.hibernate.ejb.packaging.PersistenceXmlLoader;
-import org.hibernate.ejb.packaging.JarVisitorFactory;
import org.hibernate.ejb.packaging.Scanner;
-import org.hibernate.ejb.packaging.NativeScanner;
import org.hibernate.ejb.transaction.JoinableCMTTransactionFactory;
import org.hibernate.ejb.util.ConfigurationHelper;
import org.hibernate.ejb.util.LogHelper;
@@ -98,10 +101,6 @@
import org.hibernate.util.ReflectHelper;
import org.hibernate.util.StringHelper;
import org.hibernate.util.XMLHelper;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.SAXException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Allow a fine tuned configuration of an EJB 3.0 EntityManagerFactory
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/HibernatePersistence.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -43,7 +44,6 @@
*/
public static final String PROVIDER = "javax.persistence.provider";
/**
- * �
* transaction type
*/
public static final String TRANSACTION_TYPE = "javax.persistence.transactionType";
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Copyright (c) 2009, Red Hat Middleware LLC or third-party contributors as
* indicated by the @author tags or express copyright attribution
@@ -33,17 +34,14 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.transform.dom.DOMSource;
+import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
-import javax.xml.validation.Schema;
import javax.xml.validation.Validator;
-import javax.xml.validation.ValidatorHandler;
-import org.hibernate.cfg.EJB3DTDEntityResolver;
-import org.hibernate.ejb.HibernatePersistence;
-import org.hibernate.ejb.util.ConfigurationHelper;
-import org.hibernate.util.StringHelper;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -52,11 +50,13 @@
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.hibernate.ejb.HibernatePersistence;
+import org.hibernate.ejb.util.ConfigurationHelper;
+import org.hibernate.util.StringHelper;
+
/**
- * Persistence.xml handler
+ * Handler for persistence.xml files.
*
* @author <a href="mailto:bill@jboss.org">Bill Burke</a>
* @author Emmanuel Bernard
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/DataSourceInjectionTest.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,4 +1,25 @@
//$Id$
+/*
+ * Copyright (c) 2009, 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.ejb.test.connection;
import java.io.File;
@@ -17,7 +38,7 @@
sub.mkdir();
PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl( sub.toURI().toURL(), new String[]{} );
try {
- EntityManagerFactory emf = ( new HibernatePersistence() ).createContainerEntityManagerFactory( info, null );
+ new HibernatePersistence().createContainerEntityManagerFactory( info, null );
fail( "FakeDatasource should have been used" );
}
catch (FakeDataSourceException fde) {
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2010-01-15 18:47:54 UTC (rev 18566)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/connection/PersistenceUnitInfoImpl.java 2010-01-15 20:59:56 UTC (rev 18567)
@@ -1,15 +1,37 @@
//$Id$
+/*
+ * Copyright (c) 2009, 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.ejb.test.connection;
import java.net.URL;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Properties;
+import javax.persistence.SharedCacheMode;
+import javax.persistence.ValidationMode;
import javax.persistence.spi.ClassTransformer;
import javax.persistence.spi.PersistenceUnitInfo;
import javax.persistence.spi.PersistenceUnitTransactionType;
-import javax.persistence.SharedCacheMode;
-import javax.persistence.ValidationMode;
import javax.sql.DataSource;
import org.hibernate.cfg.Environment;
@@ -29,9 +51,7 @@
public PersistenceUnitInfoImpl(URL puRoot, String[] mappingFiles) {
this.mappingFiles = new ArrayList<String>( mappingFiles.length );
- for ( String mappingFile : mappingFiles ) {
- this.mappingFiles.add( mappingFile );
- }
+ this.mappingFiles.addAll( Arrays.asList( mappingFiles ) );
this.puRoot = puRoot;
}
@@ -74,7 +94,7 @@
}
public String getPersistenceXMLSchemaVersion() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
public ClassLoader getClassLoader() {
@@ -94,13 +114,11 @@
}
public SharedCacheMode getSharedCacheMode() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
public ValidationMode getValidationMode() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
public void addTransformer(ClassTransformer transformer) {
14 years, 4 months
Hibernate SVN: r18566 - in core/trunk/entitymanager: src/main/java/org/hibernate/ejb/metamodel and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 13:47:54 -0500 (Fri, 15 Jan 2010)
New Revision: 18566
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Being.java
Modified:
core/trunk/entitymanager/pom.xml
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java
Log:
HHH-4805 take better care of generics.
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2010-01-15 17:58:18 UTC (rev 18565)
+++ core/trunk/entitymanager/pom.xml 2010-01-15 18:47:54 UTC (rev 18566)
@@ -60,7 +60,7 @@
-->
<groupId>${project.groupId}</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
- <version>1.0.0-Beta-2</version>
+ <version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
<exclusions>
<exclusion>
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-01-15 17:58:18 UTC (rev 18565)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-01-15 18:47:54 UTC (rev 18566)
@@ -27,6 +27,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.TypeVariable;
import java.util.Iterator;
import javax.persistence.ManyToMany;
import javax.persistence.OneToOne;
@@ -733,12 +734,12 @@
ParameterizedType signatureType = getSignatureType( member );
if ( keyPersistentAttributeType == null ) {
- elementJavaType = (Class) signatureType.getActualTypeArguments()[0];
+ elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] );
keyJavaType = null;
}
else {
- keyJavaType = (Class) signatureType.getActualTypeArguments()[0];
- elementJavaType = (Class) signatureType.getActualTypeArguments()[1];
+ keyJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[0] );
+ elementJavaType = getClassFromGenericArgument( signatureType.getActualTypeArguments()[1] );
}
this.elementValueContext = new ValueContext() {
@@ -804,6 +805,23 @@
}
}
+ private Class<?> getClassFromGenericArgument(java.lang.reflect.Type type) {
+ Class<?> javaType;
+ Object unsafeElementType = type;
+ if ( unsafeElementType instanceof Class ) {
+ javaType = (Class) unsafeElementType;
+ }
+ else if ( unsafeElementType instanceof TypeVariable ) {
+ final java.lang.reflect.Type upperBound = ( ( TypeVariable ) unsafeElementType ).getBounds()[0];
+ javaType = getClassFromGenericArgument( upperBound );
+ }
+ else {
+ throw new AssertionFailure("Fail to process type argument in a generic declaration. Type: "
+ + type.getClass() );
+ }
+ return javaType;
+ }
+
public ValueContext getElementValueContext() {
return elementValueContext;
}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Being.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Being.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Being.java 2010-01-15 18:47:54 UTC (rev 18566)
@@ -0,0 +1,10 @@
+package org.hibernate.ejb.test.metadata;
+
+import javax.persistence.MappedSuperclass;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@MappedSuperclass
+public class Being {
+}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java 2010-01-15 17:58:18 UTC (rev 18565)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java 2010-01-15 18:47:54 UTC (rev 18566)
@@ -10,7 +10,7 @@
*/
@Entity
@Table(name="ejb_child")
-public class Child {
+public class Child extends Being {
private Integer id;
private String name;
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2010-01-15 17:58:18 UTC (rev 18565)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2010-01-15 18:47:54 UTC (rev 18566)
@@ -274,16 +274,26 @@
assertNull( thing.getSupertype() );
}
- public void testOneToManyJoinColumnUnidirectional() throws Exception {
+ public void testBackrefAndGenerics() throws Exception {
final EntityType<Parent> parent = factory.getMetamodel().entity( Parent.class );
assertNotNull( parent );
final SetAttribute<? super Parent, ?> children = parent.getSet( "children" );
assertNotNull( children );
assertEquals( 1, parent.getPluralAttributes().size() );
- assertEquals( 3, parent.getAttributes().size() );
+ assertEquals( 4, parent.getAttributes().size() );
final EntityType<Child> child = factory.getMetamodel().entity( Child.class );
assertNotNull( child );
assertEquals( 2, child.getAttributes().size() );
+ final SingularAttribute<? super Parent, Parent.Relatives> attribute = parent.getSingularAttribute(
+ "siblings", Parent.Relatives.class
+ );
+ final EmbeddableType<Parent.Relatives> siblings = (EmbeddableType<Parent.Relatives>) attribute.getType();
+ assertNotNull(siblings);
+ final SetAttribute<? super Parent.Relatives, ?> siblingsCollection = siblings.getSet( "siblings" );
+ assertNotNull( siblingsCollection );
+ final Type<?> collectionElement = siblingsCollection.getElementType();
+ assertNotNull( collectionElement );
+ assertEquals( collectionElement, child );
}
private void ensureProperMember(Set<?> attributes) {
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java 2010-01-15 17:58:18 UTC (rev 18565)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java 2010-01-15 18:47:54 UTC (rev 18566)
@@ -1,12 +1,15 @@
package org.hibernate.ejb.test.metadata;
import java.util.Set;
+import javax.persistence.Embeddable;
+import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
+import javax.persistence.Transient;
/**
@@ -15,10 +18,28 @@
@Entity
@Table(name="ejb_parent")
public class Parent {
+
+ @Embeddable
+ public static class Relatives<T extends Being> {
+ private Set<T> siblings;
+
+ @OneToMany
+ @JoinColumn(name="siblings_fk")
+ public Set<T> getSiblings() {
+ return siblings;
+ }
+
+ public void setSiblings(Set<T> siblings) {
+ this.siblings = siblings;
+ }
+ }
+
private Integer id;
private String name;
private Set<Child> children;
+ private Relatives<Child> siblings;
+
@Id
@GeneratedValue
public Integer getId() {
@@ -46,4 +67,14 @@
public void setChildren(Set<Child> children) {
this.children = children;
}
+
+ //@Transient
+ @Embedded
+ public Relatives<Child> getSiblings() {
+ return siblings;
+ }
+
+ public void setSiblings(Relatives<Child> siblings) {
+ this.siblings = siblings;
+ }
}
14 years, 4 months
Hibernate SVN: r18565 - in jpamodelgen/trunk/src: main/java/org/hibernate/jpamodelgen/annotation and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 12:58:18 -0500 (Fri, 15 Jan 2010)
New Revision: 18565
Added:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Child.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java
Modified:
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaAttribute.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
Log:
METAGEN-15 use the first upper bound when the type to be exported is a generic.
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/ClassWriter.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -62,7 +62,7 @@
}
catch ( FilerException filerEx ) {
context.logMessage(
- Diagnostic.Kind.ERROR, "Problem with Processing Environment Filer: " + filerEx.getMessage()
+ Diagnostic.Kind.WARNING, "Problem with Processing Environment Filer: " + filerEx.getMessage()
);
}
catch ( IOException ioEx ) {
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/Context.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -110,6 +110,7 @@
return;
}
ClassWriter.writeFile( new AnnotationMetaEntity( element, this, defaultAccessTypeForHierarchy ), this );
+ TypeUtils.extractClosestRealTypeAsString( element.asType(), this );
elementsAlreadyProcessed.add( element.getQualifiedName().toString() );
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/JPAMetaModelEntityProcessor.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -226,7 +226,8 @@
}
XmlMetaEntity metaEntity = new XmlMetaEntity(
- entity, packageName, getXmlMappedType( fullyQualifiedClassName )
+ entity, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
);
if ( context.getMetaEntitiesToProcess().containsKey( fullyQualifiedClassName ) ) {
@@ -264,7 +265,8 @@
}
XmlMetaEntity metaEntity = new XmlMetaEntity(
- embeddable, packageName, getXmlMappedType( fullyQualifiedClassName )
+ embeddable, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
);
if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
@@ -292,7 +294,8 @@
}
XmlMetaEntity metaEntity = new XmlMetaEntity(
- mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName )
+ mappedSuperClass, packageName, getXmlMappedType( fullyQualifiedClassName ),
+ context
);
if ( context.getMetaSuperclassAndEmbeddableToProcess().containsKey( fullyQualifiedClassName ) ) {
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaAttribute.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaAttribute.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/MetaAttribute.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -21,11 +21,11 @@
* @author Hardy Ferentschik
*/
public interface MetaAttribute {
- String getDeclarationString();
+ String getDeclarationString();
- String getMetaType();
+ String getMetaType();
- String getPropertyName();
+ String getPropertyName();
- String getTypeDeclaration();
+ String getTypeDeclaration();
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/TypeUtils.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -18,6 +18,7 @@
package org.hibernate.jpamodelgen;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import javax.lang.model.type.TypeMirror;
@@ -25,6 +26,8 @@
import javax.lang.model.type.DeclaredType;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.Element;
+import javax.lang.model.type.TypeVariable;
+import javax.lang.model.util.Types;
/**
* Utility class.
@@ -72,4 +75,24 @@
return null;
}
}
+
+ public static String extractClosestRealTypeAsString(TypeMirror type, Context context) {
+ if ( type instanceof TypeVariable ) {
+ final TypeMirror compositeUpperBound = ( ( TypeVariable ) type ).getUpperBound();
+ final Types types = context.getProcessingEnvironment()
+ .getTypeUtils();
+ final List<? extends TypeMirror> upperBounds = types.directSupertypes( compositeUpperBound );
+ if (upperBounds.size() == 0) {
+ return compositeUpperBound.toString();
+ }
+ else {
+ //take the first one
+ return extractClosestRealTypeAsString( upperBounds.get( 0 ), context );
+ }
+
+ }
+ else {
+ return type.toString();
+ }
+ }
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/annotation/AnnotationMetaEntity.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -435,15 +435,18 @@
}
private String getKeyType(DeclaredType t) {
- return t.getTypeArguments().get( 0 ).toString();
+ return TypeUtils.extractClosestRealTypeAsString( t.getTypeArguments().get( 0 ), context );
}
private String getElementType(DeclaredType declaredType) {
if ( declaredType.getTypeArguments().size() == 1 ) {
- return declaredType.getTypeArguments().get( 0 ).toString();
+ final TypeMirror type = declaredType.getTypeArguments().get( 0 );
+ return TypeUtils.extractClosestRealTypeAsString( type, context );
}
else {
- return declaredType.getTypeArguments().get( 1 ).toString();
+ return TypeUtils.extractClosestRealTypeAsString( declaredType.getTypeArguments().get( 1 ), context );
}
}
+
+
}
Modified: jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java
===================================================================
--- jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java 2010-01-15 15:24:50 UTC (rev 18564)
+++ jpamodelgen/trunk/src/main/java/org/hibernate/jpamodelgen/xml/XmlMetaEntity.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -26,10 +26,12 @@
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
+import org.hibernate.jpamodelgen.Context;
import org.hibernate.jpamodelgen.MetaAttribute;
import org.hibernate.jpamodelgen.ImportContextImpl;
import org.hibernate.jpamodelgen.MetaEntity;
import org.hibernate.jpamodelgen.ImportContext;
+import org.hibernate.jpamodelgen.TypeUtils;
import org.hibernate.jpamodelgen.xml.jaxb.Attributes;
import org.hibernate.jpamodelgen.xml.jaxb.Basic;
import org.hibernate.jpamodelgen.xml.jaxb.ElementCollection;
@@ -65,31 +67,35 @@
final private List<MetaAttribute> members = new ArrayList<MetaAttribute>();
private TypeElement element;
+ private Context context;
- public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element) {
+ public XmlMetaEntity(Entity ormEntity, String packageName, TypeElement element, Context context) {
this.clazzName = ormEntity.getClazz();
this.packageName = packageName;
- importContext = new ImportContextImpl( getPackageName() );
+ this.context = context;
+ this.importContext = new ImportContextImpl( getPackageName() );
this.element = element;
Attributes attributes = ormEntity.getAttributes();
parseAttributes( attributes );
}
- public XmlMetaEntity(MappedSuperclass mappedSuperclass, String packageName, TypeElement element) {
+ public XmlMetaEntity(MappedSuperclass mappedSuperclass, String packageName, TypeElement element, Context context) {
this.clazzName = mappedSuperclass.getClazz();
this.packageName = packageName;
- importContext = new ImportContextImpl( getPackageName() );
+ this.context = context;
+ this.importContext = new ImportContextImpl( getPackageName() );
this.element = element;
Attributes attributes = mappedSuperclass.getAttributes();
parseAttributes( attributes );
}
- public XmlMetaEntity(Embeddable embeddable, String packageName, TypeElement element) {
+ public XmlMetaEntity(Embeddable embeddable, String packageName, TypeElement element, Context context) {
this.clazzName = embeddable.getClazz();
this.packageName = packageName;
- importContext = new ImportContextImpl( getPackageName() );
+ this.context = context;
+ this.importContext = new ImportContextImpl( getPackageName() );
this.element = element;
EmbeddableAttributes attributes = embeddable.getAttributes();
@@ -164,7 +170,7 @@
for ( Element elem : element.getEnclosedElements() ) {
if ( elem.getSimpleName().toString().equals( propertyName ) ) {
DeclaredType type = ( ( DeclaredType ) elem.asType() );
- types[0] = type.getTypeArguments().get( 0 ).toString();
+ types[0] = TypeUtils.extractClosestRealTypeAsString(type.getTypeArguments().get( 0 ), context);
types[1] = COLLECTIONS.get( type.asElement().toString() );
}
}
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Child.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Child.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Child.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -0,0 +1,35 @@
+package org.hibernate.jpamodelgen.test.generics;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name="ejb_child")
+public class Child {
+ private Integer id;
+ private String name;
+
+ @Id
+ @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
+
Copied: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java (from rev 18541, jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/elementcollection/ElementCollectionTest.java)
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/GenericsTest.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -0,0 +1,43 @@
+// $Id$
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+* http://www.apache.org/licenses/LICENSE-2.0
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.hibernate.jpamodelgen.test.generics;
+
+import org.testng.annotations.Test;
+
+import org.hibernate.jpamodelgen.test.elementcollection.House;
+import org.hibernate.jpamodelgen.test.util.CompilationTest;
+
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertClassGenerated;
+import static org.hibernate.jpamodelgen.test.util.TestUtil.assertNoGeneratedSourceFile;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class GenericsTest extends CompilationTest {
+
+ @Test
+ public void testGenerics() {
+ assertClassGenerated( Parent.class.getName() + "_" );
+ assertClassGenerated( Child.class.getName() + "_" );
+ }
+
+ @Override
+ protected String getTestPackage() {
+ return Parent.class.getPackage().getName();
+ }
+}
\ No newline at end of file
Added: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java (rev 0)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/generics/Parent.java 2010-01-15 17:58:18 UTC (rev 18565)
@@ -0,0 +1,77 @@
+package org.hibernate.jpamodelgen.test.generics;
+
+import java.util.Set;
+import javax.persistence.Embeddable;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table(name="ejb_parent")
+public class Parent {
+
+ @Embeddable
+ public static class Relatives<T> {
+ private Set<T> siblings;
+
+ @OneToMany
+ @JoinColumn(name="siblings_fk")
+ public Set<T> getSiblings() {
+ return siblings;
+ }
+
+ public void setSiblings(Set<T> siblings) {
+ this.siblings = siblings;
+ }
+ }
+
+ private Integer id;
+ private String name;
+ private Set<Child> children;
+ private Relatives<Child> siblings;
+
+
+ @Id
+ @GeneratedValue
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @OneToMany
+ @JoinColumn(name="parent_fk", nullable = false)
+ public Set<Child> getChildren() {
+ return children;
+ }
+
+ public void setChildren(Set<Child> children) {
+ this.children = children;
+ }
+
+ @Embedded
+ public Relatives<Child> getSiblings() {
+ return siblings;
+ }
+
+ public void setSiblings(Relatives<Child> siblings) {
+ this.siblings = siblings;
+ }
+}
14 years, 4 months
Hibernate SVN: r18564 - jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 10:24:50 -0500 (Fri, 15 Jan 2010)
New Revision: 18564
Modified:
jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
Log:
Better error report when the test directory is wrong. A NPE was kinda lame :)
Modified: jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java
===================================================================
--- jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2010-01-15 12:57:47 UTC (rev 18563)
+++ jpamodelgen/trunk/src/test/java/org/hibernate/jpamodelgen/test/util/CompilationTest.java 2010-01-15 15:24:50 UTC (rev 18564)
@@ -58,6 +58,7 @@
compile();
}
catch ( Exception e ) {
+ e.printStackTrace( );
fail( "Unable to compile test sources. " + e.getMessage() );
}
}
@@ -114,7 +115,11 @@
return name.endsWith( ".java" ) && !name.endsWith( "Test.java" );
}
};
- for ( File file : packageDir.listFiles( javaFileFilter ) ) {
+ final File[] files = packageDir.listFiles( javaFileFilter );
+ if (files == null) {
+ throw new RuntimeException( "Cannot find package directory (is your base dir correct?): " + packageDirName );
+ }
+ for ( File file : files ) {
javaFiles.add( file );
}
return javaFiles;
14 years, 4 months