Hibernate SVN: r18563 - in core/trunk: core/src/main/java/org/hibernate/cfg and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 07:57:47 -0500 (Fri, 15 Jan 2010)
New Revision: 18563
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationActivator.java
core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java
Log:
HHH-4807 only switch CHECK_NULLABILITY's default if Bean Validation is in the class path
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationActivator.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationActivator.java 2010-01-15 12:53:35 UTC (rev 18562)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/beanvalidation/BeanValidationActivator.java 2010-01-15 12:57:47 UTC (rev 18563)
@@ -28,18 +28,12 @@
public static void activateBeanValidation(EventListeners eventListeners, Properties properties) {
Set<ValidationMode> modes = ValidationMode.getModes( properties.get( MODE_PROPERTY ) );
- if ( modes.contains( ValidationMode.NONE ) ) return;
- //de-activate not-null tracking at the core level when Bean Validation is on unless the user really ask for it
- if ( properties.getProperty( Environment.CHECK_NULLABILITY ) == null ) {
- properties.setProperty( Environment.CHECK_NULLABILITY, "false" );
- }
try {
//load Validation
ReflectHelper.classForName( BV_DISCOVERY_CLASS, BeanValidationActivator.class );
}
catch ( ClassNotFoundException e ) {
-
if ( modes.contains( ValidationMode.CALLBACK ) ) {
throw new HibernateException( "Bean Validation not available in the class path but required in " + MODE_PROPERTY );
}
@@ -48,6 +42,16 @@
return;
}
}
+
+ //de-activate not-null tracking at the core level when Bean Validation
+ // is present unless the user really asks for it
+ //Note that if BV is not present, the behavior is backward compatible
+ if ( properties.getProperty( Environment.CHECK_NULLABILITY ) == null ) {
+ properties.setProperty( Environment.CHECK_NULLABILITY, "false" );
+ }
+
+ if ( modes.contains( ValidationMode.NONE ) ) return;
+
try {
Class<?> activator = ReflectHelper.classForName( TYPE_SAFE_ACTIVATOR_CLASS, BeanValidationActivator.class );
Method activateBeanValidation =
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java 2010-01-15 12:53:35 UTC (rev 18562)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Environment.java 2010-01-15 12:57:47 UTC (rev 18563)
@@ -509,7 +509,8 @@
/**
* Enable nullability checking.
* Raises an exception if a property marked as not-null is null.
- * Default to true.
+ * Default to false if Bean Validation is present in the classpath and Hibernate Annotations is used,
+ * true otherwise.
*/
public static final String CHECK_NULLABILITY = "hibernate.check_nullability";
14 years, 4 months
Hibernate SVN: r18562 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 07:53:35 -0500 (Fri, 15 Jan 2010)
New Revision: 18562
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java
Log:
HHH-4806 Wrap all .commit() exceptions in a RollbackException
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java 2010-01-15 10:47:18 UTC (rev 18561)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/TransactionImpl.java 2010-01-15 12:53:35 UTC (rev 18562)
@@ -77,12 +77,9 @@
}
catch (Exception e) {
Exception wrappedException;
- if (e instanceof StaleStateException) {
- wrappedException = entityManager.wrapStaleStateException( (StaleStateException) e );
+ if (e instanceof HibernateException) {
+ wrappedException = entityManager.convert( (HibernateException)e );
}
- else if (e instanceof HibernateException) {
- throw entityManager.convert( (HibernateException)e );
- }
else {
wrappedException = e;
}
@@ -93,7 +90,7 @@
catch (Exception re) {
//swallow
}
- throw new RollbackException( "Error while commiting the transaction", wrappedException );
+ throw new RollbackException( "Error while committing the transaction", wrappedException );
}
finally {
rollbackOnly = false;
14 years, 4 months
Hibernate SVN: r18561 - in core/trunk/entitymanager/src: test/java/org/hibernate/ejb/test/metadata and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-15 05:47:18 -0500 (Fri, 15 Jan 2010)
New Revision: 18561
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java
Log:
HHH-4797 Ignore backref properties for JPA 2 model
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 05:38:57 UTC (rev 18560)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2010-01-15 10:47:18 UTC (rev 18561)
@@ -73,10 +73,12 @@
* @param property The Hibernate property descriptor for the attribute
* @param <X> The type of the owner
* @param <Y> The attribute type
- * @return The built attribute descriptor
+ * @return The built attribute descriptor or null if the attribute is not part of the JPA 2 model (eg backrefs)
*/
@SuppressWarnings({ "unchecked" })
public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
+ //a back ref is a virtual property created by Hibernate, let's hide it from the JPA model.
+ if ( property.isBackRef() ) return null;
final AttributeContext<X> attributeContext = wrap( ownerType, property );
final AttributeMetadata<X,Y> attributeMetadata =
determineAttributeMetadata( attributeContext, NORMAL_MEMBER_RESOLVER );
@@ -208,7 +210,10 @@
final Iterator<Property> subProperties = component.getPropertyIterator();
while ( subProperties.hasNext() ) {
final Property property = subProperties.next();
- embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property) );
+ final AttributeImplementor<Y, Object> attribute = buildAttribute( embeddableType, property );
+ if ( attribute != null ) {
+ embeddableType.getBuilder().addAttribute( attribute );
+ }
}
embeddableType.lock();
return embeddableType;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-01-15 05:38:57 UTC (rev 18560)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2010-01-15 10:47:18 UTC (rev 18561)
@@ -175,7 +175,9 @@
continue;
}
final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
- jpa2Mapping.getBuilder().addAttribute( attribute );
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
jpa2Mapping.lock();
populateStaticMetamodel( jpa2Mapping );
@@ -192,7 +194,9 @@
while ( properties.hasNext() ) {
final Property property = properties.next();
final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
- jpa2Mapping.getBuilder().addAttribute( attribute );
+ if ( attribute != null ) {
+ jpa2Mapping.getBuilder().addAttribute( attribute );
+ }
}
jpa2Mapping.lock();
populateStaticMetamodel( jpa2Mapping );
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Child.java 2010-01-15 10:47:18 UTC (rev 18561)
@@ -0,0 +1,34 @@
+package org.hibernate.ejb.test.metadata;
+
+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;
+ }
+}
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 05:38:57 UTC (rev 18560)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/MetadataTest.java 2010-01-15 10:47:18 UTC (rev 18561)
@@ -274,6 +274,18 @@
assertNull( thing.getSupertype() );
}
+ public void testOneToManyJoinColumnUnidirectional() 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() );
+ final EntityType<Child> child = factory.getMetamodel().entity( Child.class );
+ assertNotNull( child );
+ assertEquals( 2, child.getAttributes().size() );
+ }
+
private void ensureProperMember(Set<?> attributes) {
//we do not update the set so we are safe
@SuppressWarnings( "unchecked" )
@@ -321,7 +333,9 @@
Feline.class,
Garden.class,
Flower.class,
- JoinedManyToOneOwner.class
+ JoinedManyToOneOwner.class,
+ Parent.class,
+ Child.class
};
}
Added: 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 (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/metadata/Parent.java 2010-01-15 10:47:18 UTC (rev 18561)
@@ -0,0 +1,49 @@
+package org.hibernate.ejb.test.metadata;
+
+import java.util.Set;
+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 {
+ private Integer id;
+ private String name;
+ private Set<Child> children;
+
+ @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;
+ }
+}
14 years, 4 months
Hibernate SVN: r18560 - in core/trunk: core/src/main/java/org/hibernate/engine and 6 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-15 00:38:57 -0500 (Fri, 15 Jan 2010)
New Revision: 18560
Added:
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java
core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
Log:
HHH-4726 - Add support for delete-orphan cascading to <one-to-one/>
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-14 21:32:33 UTC (rev 18559)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/HbmBinder.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -1615,13 +1615,9 @@
Attribute fkNode = node.attribute( "foreign-key" );
if ( fkNode != null ) manyToOne.setForeignKeyName( fkNode.getValue() );
- validateCascade( node, path );
- }
-
- private static void validateCascade(Element node, String path) {
String cascade = node.attributeValue( "cascade" );
if ( cascade != null && cascade.indexOf( "delete-orphan" ) >= 0 ) {
- throw new MappingException( "single-valued associations do not support orphan delete: " + path );
+ throw new MappingException( "many-to-one attributes do not support orphan delete: " + path );
}
}
@@ -1687,8 +1683,6 @@
oneToOne.setPropertyName( node.attributeValue( "name" ) );
oneToOne.setReferencedEntityName( getEntityName( node, mappings ) );
-
- validateCascade( node, path );
}
public static void bindOneToMany(Element node, OneToMany oneToMany, Mappings mappings)
Modified: core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-14 21:32:33 UTC (rev 18559)
+++ core/trunk/core/src/main/java/org/hibernate/engine/Cascade.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -109,6 +109,10 @@
this.action = action;
}
+ private SessionFactoryImplementor getFactory() {
+ return eventSource.getFactory();
+ }
+
/**
* Cascade an action from the parent entity instance to all its children.
*
@@ -206,8 +210,56 @@
cascadeComponent( parent, child, (AbstractComponentType) type, anything );
}
}
+ else {
+ // potentially we need to handle orphan deletes for one-to-ones here...
+ if ( isLogicalOneToOne( type ) ) {
+ // We have a physical or logical one-to-one and from previous checks we know we
+ // have a null value. See if the attribute cascade settings and action-type require
+ // orphan checking
+ if ( style.hasOrphanDelete() && action.deleteOrphans() ) {
+ // value is orphaned if loaded state for this property shows not null
+ // because it is currently null.
+ final EntityEntry entry = eventSource.getPersistenceContext().getEntry( parent );
+ if ( entry != null ) {
+ final EntityType entityType = (EntityType) type;
+ final Object loadedValue = entry.getLoadedValue( entityType.getPropertyName() );
+ if ( loadedValue != null ) {
+ final String entityName = entityType.getAssociatedEntityName();
+ if ( log.isTraceEnabled() ) {
+ log.trace( "deleting orphaned entity instance: " + entityName );
+ }
+ eventSource.delete( entityName, loadedValue, false, new HashSet() );
+ }
+ }
+ }
+ }
+ }
}
+ /**
+ * Check if the association is a one to one in the logical model (either a shared-pk
+ * or unique fk).
+ *
+ * @param type The type representing the attribute metadata
+ *
+ * @return True if the attribute represents a logical one to one association
+ */
+ private boolean isLogicalOneToOne(Type type) {
+ if ( ! type.isEntityType() ) {
+ return false;
+ }
+ final EntityType entityType = (EntityType) type;
+ if ( entityType.isOneToOne() ) {
+ // physical one-to-one
+ return true;
+ }
+ // todo : still need to handle the many-to-one w/ property-ref
+ // actually there is a question about whether the constrained side
+ // can declare the orphan-delete. If not, then the side declaring
+ // the orphan-delete can only ever be a <one-to-one/>
+ return false;
+ }
+
private boolean cascadeAssociationNow(AssociationType associationType) {
return associationType.getForeignKeyDirection().cascadeNow(cascadeTo) &&
( eventSource.getEntityMode()!=EntityMode.DOM4J || associationType.isEmbeddedInXML() );
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/DeleteOneToOneOrphansTest.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.fk.bidirectional;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteOneToOneOrphansTest extends FunctionalTestCase {
+ public DeleteOneToOneOrphansTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "orphan/one2one/fk/bidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo( emp ) );
+ session.save( emp );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private void cleanupData() {
+ Session session = openSession();
+ session.beginTransaction();
+ session.createQuery( "delete EmployeeInfo" ).executeUpdate();
+ session.createQuery( "delete Employee" ).executeUpdate();
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testOrphanedWhileManaged() {
+ createData();
+
+ Session session = openSession();
+ session.beginTransaction();
+ List results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 1, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ Employee emp = ( Employee ) results.get( 0 );
+ assertNotNull( emp.getInfo() );
+ emp.setInfo( null );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ emp = ( Employee ) session.get( Employee.class, emp.getId() );
+ assertNull( emp.getInfo() );
+ results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 0, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ session.getTransaction().commit();
+ session.close();
+
+ cleanupData();
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Employee.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,50 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.fk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+ private Long id;
+ private EmployeeInfo info;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public EmployeeInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(EmployeeInfo info) {
+ this.info = info;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/EmployeeInfo.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.fk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+ private Employee employee;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Employee employee) {
+ this.employee = employee;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+}
\ No newline at end of file
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/fk/bidirectional/Mapping.hbm.xml 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+
+<!DOCTYPE hibernate-mapping PUBLIC
+ '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
+ 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
+
+<hibernate-mapping package="org.hibernate.test.orphan.one2one.fk.bidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <one-to-one name="info"
+ property-ref="employee"
+ class="EmployeeInfo"
+ cascade="all,delete-orphan"
+ constrained="false" />
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <many-to-one name="employee"
+ column="employee_id"
+ unique="true"
+ not-null="true" />
+ </class>
+
+</hibernate-mapping>
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/DeleteOneToOneOrphansTest.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,92 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.pk.bidirectional;
+
+import java.util.List;
+
+import org.hibernate.Session;
+import org.hibernate.junit.functional.FunctionalTestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class DeleteOneToOneOrphansTest extends FunctionalTestCase {
+ public DeleteOneToOneOrphansTest(String string) {
+ super( string );
+ }
+
+ public String[] getMappings() {
+ return new String[] { "orphan/one2one/pk/bidirectional/Mapping.hbm.xml" };
+ }
+
+ private void createData() {
+ Session session = openSession();
+ session.beginTransaction();
+ Employee emp = new Employee();
+ emp.setInfo( new EmployeeInfo( emp ) );
+ session.save( emp );
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ private void cleanupData() {
+ Session session = openSession();
+ session.beginTransaction();
+ session.createQuery( "delete EmployeeInfo" ).executeUpdate();
+ session.createQuery( "delete Employee" ).executeUpdate();
+ session.getTransaction().commit();
+ session.close();
+ }
+
+ public void testOrphanedWhileManaged() {
+ createData();
+
+ Session session = openSession();
+ session.beginTransaction();
+ List results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 1, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ Employee emp = ( Employee ) results.get( 0 );
+ assertNotNull( emp.getInfo() );
+ emp.setInfo( null );
+ session.getTransaction().commit();
+ session.close();
+
+ session = openSession();
+ session.beginTransaction();
+ emp = ( Employee ) session.get( Employee.class, emp.getId() );
+ assertNull( emp.getInfo() );
+ results = session.createQuery( "from EmployeeInfo" ).list();
+ assertEquals( 0, results.size() );
+ results = session.createQuery( "from Employee" ).list();
+ assertEquals( 1, results.size() );
+ session.getTransaction().commit();
+ session.close();
+
+ cleanupData();
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Employee.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,50 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.pk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class Employee {
+ private Long id;
+ private EmployeeInfo info;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public EmployeeInfo getInfo() {
+ return info;
+ }
+
+ public void setInfo(EmployeeInfo info) {
+ this.info = info;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/EmployeeInfo.java 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,57 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.test.orphan.one2one.pk.bidirectional;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmployeeInfo {
+ private Long id;
+ private Employee employee;
+
+ public EmployeeInfo() {
+ }
+
+ public EmployeeInfo(Employee employee) {
+ this.employee = employee;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Employee getEmployee() {
+ return employee;
+ }
+
+ public void setEmployee(Employee employee) {
+ this.employee = employee;
+ }
+}
Added: core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml (rev 0)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/orphan/one2one/pk/bidirectional/Mapping.hbm.xml 2010-01-15 05:38:57 UTC (rev 18560)
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Hibernate, Relational Persistence for Idiomatic Java
+ ~
+ ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ ~ indicated by the @author tags or express copyright attribution
+ ~ statements applied by the authors. All third-party contributions are
+ ~ distributed under license by Red Hat Inc.
+ ~
+ ~ This copyrighted material is made available to anyone wishing to use, modify,
+ ~ copy, or redistribute it subject to the terms and conditions of the GNU
+ ~ Lesser General Public License, as published by the Free Software Foundation.
+ ~
+ ~ This program is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ ~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ ~ for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public License
+ ~ along with this distribution; if not, write to:
+ ~ Free Software Foundation, Inc.
+ ~ 51 Franklin Street, Fifth Floor
+ ~ Boston, MA 02110-1301 USA
+ -->
+
+<!DOCTYPE hibernate-mapping PUBLIC
+ '-//Hibernate/Hibernate Mapping DTD 3.0//EN'
+ 'http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd'>
+
+<hibernate-mapping package="org.hibernate.test.orphan.one2one.pk.bidirectional" >
+
+ <class name="Employee">
+ <id name="id" type="long" column="id">
+ <generator class="increment" />
+ </id>
+ <one-to-one name="info"
+ class="EmployeeInfo"
+ cascade="all,delete-orphan"
+ constrained="false" />
+ </class>
+
+ <class name="EmployeeInfo">
+ <id name="id" type="long" column="id">
+ <generator class="foreign">
+ <param name="property">employee</param>
+ </generator>
+ </id>
+ <one-to-one name="employee"
+ class="Employee"
+ constrained="true" />
+ </class>
+
+</hibernate-mapping>
14 years, 4 months
Hibernate SVN: r18559 - core/trunk/annotations/src/main/docbook/en/modules.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-14 16:32:33 -0500 (Thu, 14 Jan 2010)
New Revision: 18559
Modified:
core/trunk/annotations/src/main/docbook/en/modules/entity.xml
Log:
HHH-4527 added some doc updates
Modified: core/trunk/annotations/src/main/docbook/en/modules/entity.xml
===================================================================
--- core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-01-14 19:30:04 UTC (rev 18558)
+++ core/trunk/annotations/src/main/docbook/en/modules/entity.xml 2010-01-14 21:32:33 UTC (rev 18559)
@@ -1,4 +1,4 @@
-<?xml version='1.0' encoding="UTF-8"?>
+<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
@@ -22,8 +22,8 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-
-<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
+"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
<chapter id="entity">
<title>Entity Beans</title>
@@ -463,10 +463,10 @@
}
</programlisting>
- <para>A embeddable object inherit the access type of its owning entity
- (note that you can override that using the Hibernate specific
- <literal>@AccessType</literal> annotations (see <xref
- linkend="entity-hibspec" />).</para>
+ <para>An embeddable object inherits the access type of its owning
+ entity (note that you can override that using
+ <literal>@Access</literal> or the Hibernate specific
+ <literal>@AccessType</literal> annotation.</para>
<para>The <literal>Person</literal> entity bean has two component
properties, <literal>homeAddress</literal> and
@@ -939,8 +939,8 @@
</note>
<note>
- <para>The access type (field or methods), is inherited from the root
- entity, unless you use the Hibernate annotation
+ <para>The default access type (field or methods) is used, unless you
+ use the <literal>@Access</literal> or
<literal>@AccessType</literal></para>
</note>
@@ -1799,14 +1799,14 @@
</programlisting>
<para><literal>@Embeddable</literal> inherit the access type of its
- owning entity unless the Hibernate specific annotation
- <literal>@AccessType</literal> is used. Composite foreign keys (if not
- using the default sensitive values) are defined on associations using
- the <literal>@JoinColumns</literal> element, which is basically an array
- of <literal>@JoinColumn</literal>. It is considered a good practice to
- express <literal>referencedColumnNames</literal> explicitly. Otherwise,
- Hibernate will suppose that you use the same order of columns as in the
- primary key declaration.</para>
+ owning entity unless <literal>@Access</literal> or the Hibernate
+ specific annotation <literal>@AccessType</literal> is used. Composite
+ foreign keys (if not using the default sensitive values) are defined on
+ associations using the <literal>@JoinColumns</literal> element, which is
+ basically an array of <literal>@JoinColumn</literal>. It is considered a
+ good practice to express <literal>referencedColumnNames</literal>
+ explicitly. Otherwise, Hibernate will suppose that you use the same
+ order of columns as in the primary key declaration.</para>
<programlisting>
@Entity
@@ -2528,67 +2528,129 @@
<sect3>
<title>Access type</title>
- <para>The access type is guessed from the position of
- <literal>@Id</literal> or <literal>@EmbeddedId</literal> in the entity
- hierarchy. Sub-entities, embedded objects and mapped superclass
- inherit the access type from the root entity.</para>
+ <para>The default access type is determined from the position of the
+ <literal>@Id</literal> or <literal>@EmbeddedId</literal> annotation in
+ the entity hierarchy. </para>
- <para>In Hibernate, you can override the access type to:</para>
+ <note>
+ <para>The placement of annotations within a class hierarchy has to
+ be consistent (either field or on property) to be able to determine
+ the default access type. It is recommended to stick to one single
+ annotation placement strategy throughout your whole
+ application.</para>
+ </note>
+ <para>To finetune the access strategy JPA 2 introduces the @Access
+ annotation. With its help you can define the access type on:</para>
+
<itemizedlist>
<listitem>
- <para>use a custom access type strategy</para>
+ <para>an entity</para>
</listitem>
<listitem>
- <para>fine tune the access type at the class level or at the
- property level</para>
+ <para>a superclass</para>
</listitem>
- </itemizedlist>
- <para>An @AccessType annotation has been introduced to support this
- behavior. You can define the access type on</para>
-
- <itemizedlist>
<listitem>
- <para>an entity</para>
+ <para>an embeddable object</para>
</listitem>
<listitem>
- <para>a superclass</para>
+ <para>a property</para>
</listitem>
+ </itemizedlist>
+ <para>Prior to JPA 2 Hibernate used the Hibernate specific annotation
+ <literal>@org.hibernate.annotations.AccessType</literal> to change
+ specific access types. @AccessType still exists to support legacy
+ systems, but the usage of @Access is recommended for new applications.
+ The behaviour of @Access and @AccessType are similar, but there are
+ differences. For both annotations applies:</para>
+
+ <itemizedlist>
<listitem>
- <para>an embeddable object</para>
+ <para>The access type is overriden for the annotated element, if
+ overriden on a class, all the properties of the given class
+ inherit the access type. </para>
</listitem>
<listitem>
- <para>a property</para>
+ <para>If an entity is marked as
+ <literal>@Access(AccessType.PROPERTY)</literal> or
+ <literal>@AccessType("property")</literal> respectively, the
+ getters are scanned for annotations, if the enitiy is marked as
+ <literal>@Access(AccessType.FIELD)</literal> or
+ <literal>@AccessType("field")</literal> respectively, the fields
+ are scanned for annotations. </para>
</listitem>
</itemizedlist>
- <para>The access type is overriden for the annotated element, if
- overriden on a class, all the properties of the given class inherit
- the access type. For root entities, the access type is considered to
- be the default one for the whole hierarchy (overridable at class or
- property level).</para>
+ <para>In the case where you want to override the access type for a
+ property of an entity which already defines an explicit access type
+ the annotation placement between @Access and @AccessType
+ differs:</para>
- <para>If the access type is marked as "property", the getters are
- scanned for annotations, if the access type is marked as "field", the
- fields are scanned for annotations. Otherwise the elements marked with
- @Id or @embeddedId are scanned.</para>
+ <programlisting><emphasis role="bold">@AccessType("property")</emphasis> // set access type for all properties in Country
+public class Country implements Serializable {
+ private String iso2;
+ private String name;
- <para>You can override an access type for a property, but the element
- to annotate will not be influenced: for example an entity having
- access type <literal>field</literal>, can annotate a field with
- <literal>@AccessType("property")</literal>, the access type will then
- be property for this attribute, the the annotations still have to be
- carried on the field.</para>
+ public String getIso2() {
+ return iso2;
+ }
+ public void setIso2(String iso2) {
+ this.iso2 = iso2;
+ }
+
+ @Column(name = "countryName")
+ <emphasis role="bold">@AccessType("field")</emphasis> // set the access type for name to field
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
+</programlisting>
+
+ <programlisting><emphasis role="bold">@Access(AccessType.PROPERTY)</emphasis> // set access type for all properties in Country
+public class Country implements Serializable {
+ private String iso2;
+
+ <emphasis role="bold">@Access(AccessType.FIELD)</emphasis> // set the access type for name to field
+ private String name;
+
+ public String getIso2() {
+ return iso2;
+ }
+
+ public void setIso2(String iso2) {
+ this.iso2 = iso2;
+ }
+
+ @Column(name = "countryName")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
+</programlisting>
+
+ <note>
+ <para>Watch out for the different annotation placement strategy. In
+ the case of <literal>@Access</literal> the field has to be annotated
+ with the overriding access strategy whereas with
+ <literal>@AccessType</literal> the property gets annotated.</para>
+ </note>
+
<para>If a superclass or an embeddable object is not annotated, the
- root entity access type is used (even if an access type has been
- define on an intermediate superclass or embeddable object). The
- russian doll principle does not apply.</para>
+ default entity access type is used.</para>
<programlisting>@Entity
public class Person implements Serializable {
@@ -2655,14 +2717,28 @@
<para><literal>@org.hibernate.annotations.TypeDef</literal> and
<literal>@org.hibernate.annotations.TypeDefs</literal> allows you to
- declare type definitions. These annotations can be placed at the class or
- package level. Note that these definitions are global for the
- session factory (even when defined at the class level). If the type is used on a single entity, you can place the definition on the entity itself. Otherwise, it is recommended to place the definition at the package level. In the example below, when Hibernate encounters a property of class <literal>PhoneNumer</literal>, it delegates the persistence strategy to the custom mapping type <literal>PhoneNumberType</literal>. However, properties belonging to other classes, too, can delegate their persistence strategy to <literal>PhoneNumberType</literal>, by explicitly using the <literal>@Type</literal> annotation. </para>
+ declare type definitions. These annotations can be placed at the class
+ or package level. Note that these definitions are global for the
+ session factory (even when defined at the class level). If the type is
+ used on a single entity, you can place the definition on the entity
+ itself. Otherwise, it is recommended to place the definition at the
+ package level. In the example below, when Hibernate encounters a
+ property of class <literal>PhoneNumer</literal>, it delegates the
+ persistence strategy to the custom mapping type
+ <literal>PhoneNumberType</literal>. However, properties belonging to
+ other classes, too, can delegate their persistence strategy to
+ <literal>PhoneNumberType</literal>, by explicitly using the
+ <literal>@Type</literal> annotation.</para>
- <note>Package level annotations are placed in a file named <filename>package-info.java</filename>
- in the appropriate package. Place your annotations before the package declaration.</note>
+ <note>
+ Package level annotations are placed in a file named
-<programlisting>
+ <filename>package-info.java</filename>
+
+ in the appropriate package. Place your annotations before the package declaration.
+ </note>
+
+ <programlisting>
@TypeDef(
name = "phoneNumber",
defaultForType = PhoneNumber.class,
@@ -2681,11 +2757,10 @@
</programlisting>
-<para>
-The following example shows the usage of the <literal>parameters</literal> attribute to customize the TypeDef.
-</para>
+ <para>The following example shows the usage of the
+ <literal>parameters</literal> attribute to customize the
+ TypeDef.</para>
-
<programlisting>//in org/hibernate/test/annotations/entity/package-info.java
@TypeDefs(
{
@@ -3863,4 +3938,4 @@
}</programlisting>
</sect2>
</sect1>
-</chapter>
\ No newline at end of file
+</chapter>
14 years, 4 months
Hibernate SVN: r18558 - in core/trunk: entitymanager and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-14 14:30:04 -0500 (Thu, 14 Jan 2010)
New Revision: 18558
Modified:
core/trunk/annotations/pom.xml
core/trunk/entitymanager/pom.xml
core/trunk/parent/pom.xml
Log:
HHH-4789 Made sure that the plugins are configured in the parent pom. Made the em docbook generation work. xml formatting
Modified: core/trunk/annotations/pom.xml
===================================================================
--- core/trunk/annotations/pom.xml 2010-01-14 19:10:50 UTC (rev 18557)
+++ core/trunk/annotations/pom.xml 2010-01-14 19:30:04 UTC (rev 18558)
@@ -22,7 +22,9 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -103,14 +105,6 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-test-ext-plugin</artifactId>
- <version>1.1.0</version>
- <executions>
- <execution>
- <goals>
- <goal>extend</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.twdata.maven</groupId>
@@ -145,19 +139,9 @@
<id>doc</id>
<build>
<plugins>
- <plugin>
+ <plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.2.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-jdocbook-style</artifactId>
- <version>2.0.0</version>
- <type>jdocbook-style</type>
- </dependency>
- </dependencies>
<configuration>
<sourceDocumentName>master.xml</sourceDocumentName>
<sourceDirectory>${basedir}/src/main/docbook</sourceDirectory>
@@ -165,33 +149,6 @@
<imageResource>
<directory>${basedir}/src/main/docbook/en/images</directory>
</imageResource>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/pdf.xsl</stylesheetResource>
- <finalName>hibernate_reference.pdf</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml-single.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>true</xincludeSupported>
- <xmlTransformerType>saxon</xmlTransformerType>
- <!-- needed for uri-resolvers; can be ommitted if using 'current' uri scheme -->
- <!-- could also locate the docbook dependency and inspect its version... -->
- <docbookVersion>1.72.0</docbookVersion>
- <localeSeparator>-</localeSeparator>
- </options>
</configuration>
<executions>
<execution>
@@ -207,7 +164,5 @@
</plugins>
</build>
</profile>
-
</profiles>
-
</project>
Modified: core/trunk/entitymanager/pom.xml
===================================================================
--- core/trunk/entitymanager/pom.xml 2010-01-14 19:10:50 UTC (rev 18557)
+++ core/trunk/entitymanager/pom.xml 2010-01-14 19:30:04 UTC (rev 18558)
@@ -72,21 +72,6 @@
</dependency>
</dependencies>
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>hibernate-core</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>hibernate-annotations</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<build>
<testResources>
<testResource>
@@ -158,14 +143,6 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-test-ext-plugin</artifactId>
- <version>1.1.0</version>
- <executions>
- <execution>
- <goals>
- <goal>extend</goal>
- </goals>
- </execution>
- </executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -210,47 +187,13 @@
<plugin>
<groupId>org.jboss.maven.plugins</groupId>
<artifactId>maven-jdocbook-plugin</artifactId>
- <version>2.1.0</version>
- <extensions>true</extensions>
- <dependencies>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-jdocbook-style</artifactId>
- <version>1.0.2</version>
- <type>jdocbook-style</type>
- </dependency>
- </dependencies>
<configuration>
<sourceDocumentName>master.xml</sourceDocumentName>
- <sourceDirectory>${basedir}/src/main/docbook/en</sourceDirectory>
- <masterTranslation>en-US</masterTranslation>
+ <sourceDirectory>${basedir}/src/main/docbook</sourceDirectory>
+ <masterTranslation>en</masterTranslation>
<imageResource>
<directory>${basedir}/src/main/docbook/en/images</directory>
</imageResource>
- <formats>
- <format>
- <formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/hibernate/pdf/main-pdf.xsl</stylesheetResource>
- <finalName>hibernate-validator-legacy-guide.pdf</finalName>
- </format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/hibernate/html/main-single.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/hibernate/html/main-chunk.xsl
- </stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>true</xincludeSupported>
- <localeSeparator>-</localeSeparator>
- <useRelativeImageUris>true</useRelativeImageUris>
- </options>
</configuration>
<executions>
<execution>
@@ -267,5 +210,4 @@
</build>
</profile>
</profiles>
-
</project>
Modified: core/trunk/parent/pom.xml
===================================================================
--- core/trunk/parent/pom.xml 2010-01-14 19:10:50 UTC (rev 18557)
+++ core/trunk/parent/pom.xml 2010-01-14 19:30:04 UTC (rev 18558)
@@ -22,7 +22,9 @@
~ 51 Franklin Street, Fifth Floor
~ Boston, MA 02110-1301 USA
-->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -198,39 +200,42 @@
<version>2.2.0</version>
<extensions>true</extensions>
<dependencies>
- <dependency>
- <groupId>org.hibernate</groupId>
- <artifactId>hibernate-jdocbook-style</artifactId>
- <version>2.0.0</version>
- <type>jdocbook-style</type>
- </dependency>
+ <dependency>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-jdocbook-style</artifactId>
+ <version>2.0.0</version>
+ <type>jdocbook-style</type>
+ </dependency>
</dependencies>
<configuration>
<formats>
<format>
<formatName>pdf</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/pdf.xsl</stylesheetResource>
+ <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/pdf.xsl
+ </stylesheetResource>
<finalName>hibernate_reference.pdf</finalName>
</format>
- <format>
- <formatName>html_single</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml-single.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- <format>
- <formatName>html</formatName>
- <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml.xsl</stylesheetResource>
- <finalName>index.html</finalName>
- </format>
- </formats>
- <options>
- <xincludeSupported>true</xincludeSupported>
- <xmlTransformerType>saxon</xmlTransformerType>
- <!-- needed for uri-resolvers; can be ommitted if using 'current' uri scheme -->
- <!-- could also locate the docbook dependency and inspect its version... -->
- <docbookVersion>1.72.0</docbookVersion>
- <localeSeparator>-</localeSeparator>
- </options>
+ <format>
+ <formatName>html_single</formatName>
+ <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml-single.xsl
+ </stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+ <stylesheetResource>classpath:/xslt/org/hibernate/jdocbook/xslt/xhtml.xsl
+ </stylesheetResource>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>true</xincludeSupported>
+ <xmlTransformerType>saxon</xmlTransformerType>
+ <!-- needed for uri-resolvers; can be ommitted if using 'current' uri scheme -->
+ <!-- could also locate the docbook dependency and inspect its version... -->
+ <docbookVersion>1.72.0</docbookVersion>
+ <localeSeparator>-</localeSeparator>
+ </options>
</configuration>
</plugin>
<plugin>
@@ -306,6 +311,18 @@
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-test-ext-plugin</artifactId>
+ <version>1.1.0</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>extend</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</pluginManagement>
@@ -342,7 +359,7 @@
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.4.3</version>
</plugin>
-<!--
+ <!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
@@ -529,7 +546,7 @@
<jdbc.url>jdbc:hsqldb:.</jdbc.url>
<jdbc.user>sa</jdbc.user>
<jdbc.pass/>
- <jdbc.isolation/>
+ <jdbc.isolation/>
</properties>
</profile>
@@ -551,7 +568,7 @@
<jdbc.url>jdbc:h2:mem:db1</jdbc.url>
<jdbc.user>sa</jdbc.user>
<jdbc.pass/>
- <jdbc.isolation/>
+ <jdbc.isolation/>
</properties>
</profile>
<!--
@@ -618,7 +635,8 @@
<properties>
<db.dialect>org.hibernate.dialect.MySQL5Dialect</db.dialect>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
- <jdbc.url>jdbc:mysql:loadbalance://dev61.qa.atl2.redhat.com:3306,dev62.qa.atl2.redhat.com:3306/hibbrtru</jdbc.url>
+ <jdbc.url>jdbc:mysql:loadbalance://dev61.qa.atl2.redhat.com:3306,dev62.qa.atl2.redhat.com:3306/hibbrtru
+ </jdbc.url>
<jdbc.user>hibbrtru</jdbc.user>
<jdbc.pass>hibbrtru</jdbc.pass>
<jdbc.isolation/>
@@ -830,7 +848,9 @@
<properties>
<db.dialect>org.hibernate.dialect.Oracle10gDialect</db.dialect>
<jdbc.driver>oracle.jdbc.driver.OracleDriver</jdbc.driver>
- <jdbc.url>jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))</jdbc.url>
+ <jdbc.url>
+ jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS_LIST=(LOAD_BALANCE=ON)(ADDRESS=(PROTOCOL=TCP)(HOST=vmg24-vip.mw.lab.eng.bos.redhat.com)(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=vmg25-vip.mw.lab.eng.bos.redhat.com)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=qarac.jboss)))
+ </jdbc.url>
<jdbc.user>hibbrtru</jdbc.user>
<jdbc.pass>hibbrtru</jdbc.pass>
<jdbc.isolation/>
14 years, 4 months
Hibernate SVN: r18557 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity.
by hibernate-commits@lists.jboss.org
Author: smarlow(a)redhat.com
Date: 2010-01-14 14:10:50 -0500 (Thu, 14 Jan 2010)
New Revision: 18557
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java
Log:
HHH-4725 implement orphanRemoval for OneToOne and HHH-4726 Add support for delete-orphan cascading to one-to-one
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2010-01-14 15:20:50 UTC (rev 18556)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/BasicHibernateAnnotationsTest.java 2010-01-14 19:10:50 UTC (rev 18557)
@@ -362,6 +362,55 @@
s.close();
}
+ public void testCascadedDeleteOfChildOneToOne() {
+ // create two single player teams (for one versus one match of soccer)
+ // and associate teams with players via the special OneVOne methods.
+ // Clear the Team reference to players, which should orphan the teams.
+ // Orphaning the team should delete the team.
+
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+
+ SoccerTeam team = new SoccerTeam();
+ team.setName("Shalrie's team");
+ Player player1 = new Player();
+ player1.setName("Shalrie Joseph");
+ team.setOneVonePlayer(player1);
+ player1.setOneVoneTeam(team);
+
+ s.persist(team);
+
+ SoccerTeam team2 = new SoccerTeam();
+ team2.setName("Taylor's team");
+ Player player2 = new Player();
+ player2.setName("Taylor Twellman");
+ team2.setOneVonePlayer(player2);
+ player2.setOneVoneTeam(team2);
+ s.persist(team2);
+ tx.commit();
+
+ tx = s.beginTransaction();
+ s.clear();
+ team2 = (SoccerTeam)s.load(team2.getClass(), team2.getId());
+ team = (SoccerTeam)s.load(team.getClass(), team.getId());
+ int count = ( (Long) s.createQuery( "select count(*) from Player" ).iterate().next() ).intValue();
+ assertEquals("expected count of 2 but got = " + count, count, 2);
+
+ // clear references to players, this should orphan the players which should
+ // in turn trigger orphanRemoval logic.
+ team.setOneVonePlayer(null);
+ team2.setOneVonePlayer(null);
+ tx.commit();
+ s.close();
+
+ s = openSession();
+ tx = s.beginTransaction();
+ count = ( (Long) s.createQuery( "select count(*) from Player" ).iterate().next() ).intValue();
+ assertEquals("expected count of 0 but got = " + count, count, 0);
+ tx.commit();
+ s.close();
+ }
+
public void testFilter() throws Exception {
Session s;
Transaction tx;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java 2010-01-14 15:20:50 UTC (rev 18556)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/Player.java 2010-01-14 19:10:50 UTC (rev 18557)
@@ -29,6 +29,7 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
@Entity
@@ -38,6 +39,10 @@
private String name;
private SoccerTeam team;
+ // For the world cup of one versus one matches, we have
+ // teams with one player (1v1 team).
+ private SoccerTeam oneVoneTeam;
+
@Id
@GeneratedValue
public int getId() {
@@ -62,4 +67,13 @@
public void setTeam(SoccerTeam team) {
this.team = team;
}
+
+ @OneToOne
+ public SoccerTeam getOneVoneTeam() {
+ return oneVoneTeam;
+ }
+
+ public void setOneVoneTeam(SoccerTeam oneVoneTeam) {
+ this.oneVoneTeam = oneVoneTeam;
+ }
}
\ No newline at end of file
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java 2010-01-14 15:20:50 UTC (rev 18556)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/entity/SoccerTeam.java 2010-01-14 19:10:50 UTC (rev 18557)
@@ -32,17 +32,26 @@
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
+import javax.persistence.OneToOne;
@Entity
public class SoccerTeam {
@Id
@GeneratedValue
private int id;
+
+ String name;
+
@OneToMany(mappedBy="team",
orphanRemoval=true,
cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
private Set<Player> players = new HashSet<Player>();
+ @OneToOne(mappedBy="oneVoneTeam",
+ orphanRemoval=true,
+ cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH, CascadeType.DETACH})
+ private Player oneVonePlayer;
+
public int getId() {
return id;
}
@@ -60,4 +69,20 @@
val.setTeam(this);
}
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Player getOneVonePlayer() {
+ return oneVonePlayer;
+ }
+
+ public void setOneVonePlayer(Player oneVonePlayer) {
+ this.oneVonePlayer = oneVonePlayer;
+ }
+
}
\ No newline at end of file
14 years, 4 months
Hibernate SVN: r18556 - core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-14 10:20:50 -0500 (Thu, 14 Jan 2010)
New Revision: 18556
Modified:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
Log:
Add more test on ConstraintViolationException and transaction behavior
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java 2010-01-14 10:33:11 UTC (rev 18555)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/beanvalidation/BeanValidationTest.java 2010-01-14 15:20:50 UTC (rev 18556)
@@ -3,6 +3,7 @@
import java.math.BigDecimal;
import javax.persistence.EntityManager;
+import javax.persistence.RollbackException;
import javax.validation.ConstraintViolationException;
import org.hibernate.ejb.test.TestCase;
@@ -12,7 +13,7 @@
*/
public class BeanValidationTest extends TestCase {
- public void testBeanValidationIntegration() {
+ public void testBeanValidationIntegrationOnFlush() {
CupHolder ch = new CupHolder();
ch.setRadius( new BigDecimal( "12" ) );
EntityManager em = getOrCreateEntityManager();
@@ -33,6 +34,26 @@
em.close();
}
+ public void testBeanValidationIntegrationOnCommit() {
+ CupHolder ch = new CupHolder();
+ ch.setRadius( new BigDecimal( "9" ) );
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ em.persist( ch );
+ em.flush();
+ try {
+ ch.setRadius( new BigDecimal( "12" ) );
+ em.getTransaction().commit();
+ fail("invalid object should not be persisted");
+ }
+ catch ( RollbackException e ) {
+ final Throwable cve = e.getCause();
+ assertTrue( cve instanceof ConstraintViolationException );
+ assertEquals( 1, ( (ConstraintViolationException) cve ).getConstraintViolations().size() );
+ }
+ em.close();
+ }
+
@Override
public Class[] getAnnotatedClasses() {
return new Class[] {
14 years, 4 months
Hibernate SVN: r18555 - in core/trunk: entitymanager/src/main/java/org/hibernate/ejb and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-14 05:33:11 -0500 (Thu, 14 Jan 2010)
New Revision: 18555
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/Version.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java
Log:
Bump version numbers
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/Version.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/Version.java 2010-01-14 10:18:00 UTC (rev 18554)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/Version.java 2010-01-14 10:33:11 UTC (rev 18555)
@@ -23,6 +23,8 @@
*/
package org.hibernate.cfg.annotations;
+import java.util.Date;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,7 +32,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.5.0.Beta1";
+ public static final String VERSION = "3.5.0." + new Date();
private static Logger log = LoggerFactory.getLogger( Version.class );
static {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java 2010-01-14 10:18:00 UTC (rev 18554)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/Version.java 2010-01-14 10:33:11 UTC (rev 18555)
@@ -23,6 +23,8 @@
//$Id$
package org.hibernate.ejb;
+import java.util.Date;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -31,7 +33,7 @@
* @author Emmanuel Bernard
*/
public class Version {
- public static final String VERSION = "3.5.0.Beta1";
+ public static final String VERSION = "3.5.0." + new Date();
private static final Logger log = LoggerFactory.getLogger( Version.class );
static {
14 years, 4 months
Hibernate SVN: r18554 - core/trunk/annotations/src/main/java/org/hibernate/cfg.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-14 05:18:00 -0500 (Thu, 14 Jan 2010)
New Revision: 18554
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
Log:
HHH-4796 fix NPE when an @AssociationOverride joinColumn is set but no @AssociationOverride joinTable is on a given property
Fix minor issues
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java 2010-01-14 03:12:47 UTC (rev 18553)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AbstractPropertyHolder.java 2010-01-14 10:18:00 UTC (rev 18554)
@@ -199,7 +199,7 @@
private JoinColumn[] getExactOverriddenJoinColumn(String propertyName) {
JoinColumn[] override = null;
if ( parent != null ) {
- override = parent.getOverriddenJoinColumn( propertyName );
+ override = parent.getExactOverriddenJoinColumn( propertyName );
}
if ( override == null && currentPropertyJoinColumnOverride != null ) {
override = currentPropertyJoinColumnOverride.get( propertyName );
@@ -249,9 +249,9 @@
private JoinTable getExactOverriddenJoinTable(String propertyName) {
JoinTable override = null;
if ( parent != null ) {
- override = parent.getOverriddenJoinTable( propertyName );
+ override = parent.getExactOverriddenJoinTable( propertyName );
}
- if ( override == null && currentPropertyJoinColumnOverride != null ) {
+ if ( override == null && currentPropertyJoinTableOverride != null ) {
override = currentPropertyJoinTableOverride.get( propertyName );
}
if ( override == null && holderJoinTableOverride != null ) {
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-14 03:12:47 UTC (rev 18553)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-14 10:18:00 UTC (rev 18554)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -893,7 +893,7 @@
}
catch ( DocumentException e ) {
//oops asXML fails even if the core doc parses initially
- new AssertionFailure("Error in DOM4J leads to a bug in Hibernate", e);
+ throw new AssertionFailure("Error in DOM4J leads to a bug in Hibernate", e);
}
}
14 years, 4 months