Hibernate SVN: r18594 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations: idclassgeneratedvalue and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-20 15:18:56 -0500 (Wed, 20 Jan 2010)
New Revision: 18594
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
Log:
HHH-4822 - Added @FailureExpected to annotations module
Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java (from rev 18589, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java)
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/FailureExpected.java 2010-01-20 20:18:56 UTC (rev 18594)
@@ -0,0 +1,42 @@
+// $Id$
+/*
+ * 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotations used to mark a expected test failure.
+ *
+ * @author Hardy Ferentschik
+ */
+@Target({ ElementType.METHOD, ElementType.TYPE })
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface FailureExpected {
+ String message() default "";
+ String issueNumber() default "";
+}
\ No newline at end of file
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java 2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/RequiresDialect.java 2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,4 +1,27 @@
-// $Id:$
+// $Id$
+/*
+ * 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.annotations;
import java.lang.annotation.ElementType;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java 2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/SkipForDialect.java 2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,4 +1,27 @@
// $Id$
+/*
+ * 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.annotations;
import java.lang.annotation.ElementType;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java 2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,8 +1,30 @@
//$Id$
+/*
+ * 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.annotations;
import java.io.InputStream;
-import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.sql.Connection;
@@ -24,6 +46,7 @@
import org.hibernate.dialect.Dialect;
import org.hibernate.jdbc.Work;
import org.hibernate.tool.hbm2ddl.SchemaExport;
+import org.hibernate.util.StringHelper;
/**
* A base class for all tests.
@@ -113,15 +136,10 @@
}
protected void runTest() throws Throwable {
- try {
- if ( runTest ) {
- runTestMethod( runMethod );
- handleUnclosedSession();
- }
+ if ( runTest ) {
+ runTestMethod( runMethod );
+ handleUnclosedSession();
}
- catch ( Throwable e ) {
- closeSession( e );
- }
}
private void setRunTestFlag(Method runMethod) {
@@ -197,16 +215,38 @@
}
private void runTestMethod(Method runMethod) throws Throwable {
+ boolean failureExpected = runMethod.getAnnotation( FailureExpected.class ) != null;
try {
runMethod.invoke( this, new Class[0] );
+ if ( failureExpected ) {
+ throw new FailureExpectedTestPassedException();
+ }
}
- catch ( InvocationTargetException e ) {
- e.fillInStackTrace();
- throw e.getTargetException();
+ catch ( FailureExpectedTestPassedException t ) {
+ closeSession();
+ throw t;
}
- catch ( IllegalAccessException e ) {
- e.fillInStackTrace();
- throw e;
+ catch ( Throwable t ) {
+ closeSession();
+ if ( failureExpected ) {
+ FailureExpected ann = runMethod.getAnnotation( FailureExpected.class );
+ StringBuilder builder = new StringBuilder();
+ if ( StringHelper.isNotEmpty( ann.message() ) ) {
+ builder.append( ann.message() );
+ }
+ else {
+ builder.append( "ignoring test methods annoated with @FailureExpected" );
+ }
+ if ( StringHelper.isNotEmpty( ann.issueNumber() ) ) {
+ builder.append( " (" );
+ builder.append( ann.issueNumber() );
+ builder.append( ")" );
+ }
+ reportSkip( builder.toString(), "Failed with: " + t.toString() );
+ }
+ else {
+ throw t;
+ }
}
}
@@ -215,7 +255,7 @@
assertNotNull( fName );
Method runMethod = null;
try {
- runMethod = getClass().getMethod( fName, null );
+ runMethod = getClass().getMethod( fName );
}
catch ( NoSuchMethodException e ) {
fail( "Method \"" + fName + "\" not found" );
@@ -240,7 +280,7 @@
}
}
- private void closeSession(Throwable e) throws Throwable {
+ private void closeSession() {
try {
if ( session != null && session.isOpen() ) {
if ( session.isConnected() ) {
@@ -259,7 +299,6 @@
}
catch ( Exception ignore ) {
}
- throw e;
}
public Session openSession() throws HibernateException {
@@ -314,10 +353,30 @@
export.create( true, true );
}
+ protected void reportSkip(String reason, String testDescription) {
+ StringBuilder builder = new StringBuilder( );
+ builder.append( "*** skipping test [" );
+ builder.append( runMethod.getDeclaringClass().getName() );
+ builder.append( "." );
+ builder.append(runMethod.getName() );
+ builder.append( "] - " );
+ builder.append( testDescription );
+ builder.append( " : " );
+ builder.append( reason );
+
+ log.warn( builder.toString() );
+ }
+
public class RollbackWork implements Work {
public void execute(Connection connection) throws SQLException {
connection.rollback();
}
}
+
+ private static class FailureExpectedTestPassedException extends Exception {
+ public FailureExpectedTestPassedException() {
+ super( "Test marked as @FailureExpected, but did not fail!" );
+ }
+ }
}
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/TestCase.java
___________________________________________________________________
Name: svn:keywords
- Date Revision Author Id
+ Id
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java 2010-01-20 19:16:38 UTC (rev 18593)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java 2010-01-20 20:18:56 UTC (rev 18594)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -23,11 +24,10 @@
*/
package org.hibernate.test.annotations.idclassgeneratedvalue;
-import java.math.BigDecimal;
import java.util.List;
import org.hibernate.Session;
-import org.hibernate.Transaction;
+import org.hibernate.test.annotations.FailureExpected;
import org.hibernate.test.annotations.TestCase;
/**
@@ -52,7 +52,7 @@
s.beginTransaction();
List<Simple> simpleList = s.createQuery( "select s from Simple s" ).list();
assertEquals( simpleList.size(), 2 );
- s1 = (Simple) s.load( Simple.class, new SimplePK( 1L, 2L ) );
+ s1 = ( Simple ) s.load( Simple.class, new SimplePK( 1L, 2L ) );
assertEquals( s1.getQuantity(), 10 );
s.clear();
s.createQuery( "delete Simple" ).executeUpdate();
@@ -60,6 +60,7 @@
s.close();
}
+ @FailureExpected(message = "Not yet implemented", issueNumber = "HHH-4552")
@SuppressWarnings({ "unchecked" })
public void testSingleGeneratedValue() {
Session s = openSession();
@@ -76,39 +77,40 @@
s.beginTransaction();
List<Simple> simpleList = s.createQuery( "select s from Simple2 s" ).list();
assertEquals( simpleList.size(), 2 );
- s1 = (Simple2) s.load( Simple2.class, new SimplePK( s1Id1, 2L ) );
+ s1 = ( Simple2 ) s.load( Simple2.class, new SimplePK( s1Id1, 2L ) );
assertEquals( s1.getQuantity(), 10 );
s.clear();
s.createQuery( "delete Simple2" ).executeUpdate();
s.getTransaction().commit();
s.close();
}
-
- @SuppressWarnings({ "unchecked" })
- public void testMultipleGeneratedValue() {
- Session s = openSession();
- s.beginTransaction();
- Multiple m1 = new Multiple( 1000L, 10 );
- s.persist( m1 );
- Long m1Id1 = m1.getId1();
- Long m1Id2 = m1.getId2();
- Multiple m2 = new Multiple( 2000L, 20 );
- s.persist( m2 );
- s.getTransaction().commit();
- s.close();
- s = openSession();
- s.beginTransaction();
- List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
- assertEquals( simpleList.size(), 2 );
- m1 = (Multiple) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
- assertEquals( m1.getQuantity(), 10 );
- s.clear();
- s.createQuery( "delete Multiple" ).executeUpdate();
- s.getTransaction().commit();
- s.close();
- }
+ @FailureExpected(message = "Not yet implemented", issueNumber = "HHH-4552")
+ @SuppressWarnings({ "unchecked" })
+ public void testMultipleGeneratedValue() {
+ Session s = openSession();
+ s.beginTransaction();
+ Multiple m1 = new Multiple( 1000L, 10 );
+ s.persist( m1 );
+ Long m1Id1 = m1.getId1();
+ Long m1Id2 = m1.getId2();
+ Multiple m2 = new Multiple( 2000L, 20 );
+ s.persist( m2 );
+ s.getTransaction().commit();
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+ List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
+ assertEquals( simpleList.size(), 2 );
+ m1 = ( Multiple ) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
+ assertEquals( m1.getQuantity(), 10 );
+ s.clear();
+ s.createQuery( "delete Multiple" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
// public void testComplexIdClass() {
// Session s = openSession();
// Transaction tx = s.beginTransaction();
@@ -155,7 +157,7 @@
Simple.class,
Simple2.class,
Multiple.class
-
+
};
}
}
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
___________________________________________________________________
Name: svn:keywords
+ Id
14 years, 12 months
Hibernate SVN: r18593 - in core/trunk: testsuite/src/test/java/org/hibernate/test/component/cascading/collection and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-01-20 14:16:38 -0500 (Wed, 20 Jan 2010)
New Revision: 18593
Modified:
core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java
core/trunk/testsuite/src/test/java/org/hibernate/test/component/cascading/collection/Value.java
Log:
HHH-4726 - Add support for delete-orphan cascading to <one-to-one/>
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-20 18:48:20 UTC (rev 18592)
+++ core/trunk/core/src/main/java/org/hibernate/type/ManyToOneType.java 2010-01-20 19:16:38 UTC (rev 18593)
@@ -65,7 +65,7 @@
* @param lazy Should the association be handled lazily
*/
public ManyToOneType(String referencedEntityName, boolean lazy) {
- this( referencedEntityName, null, !lazy, true, false, false );
+ this( referencedEntityName, null, lazy, true, false, false );
}
/**
@@ -79,7 +79,7 @@
boolean unwrapProxy,
boolean isEmbeddedInXML,
boolean ignoreNotFound) {
- this( referencedEntityName, uniqueKeyPropertyName, !lazy, isEmbeddedInXML, unwrapProxy, ignoreNotFound, false );
+ this( referencedEntityName, uniqueKeyPropertyName, lazy, unwrapProxy, isEmbeddedInXML, ignoreNotFound, false );
}
public ManyToOneType(
Modified: core/trunk/testsuite/src/test/java/org/hibernate/test/component/cascading/collection/Value.java
===================================================================
--- core/trunk/testsuite/src/test/java/org/hibernate/test/component/cascading/collection/Value.java 2010-01-20 18:48:20 UTC (rev 18592)
+++ core/trunk/testsuite/src/test/java/org/hibernate/test/component/cascading/collection/Value.java 2010-01-20 19:16:38 UTC (rev 18593)
@@ -10,7 +10,7 @@
private Definition definition;
private LocalizedStrings localizedStrings = new LocalizedStrings();
- private Value() {
+ protected Value() {
}
public Value(Definition definition) {
14 years, 12 months
Hibernate SVN: r18592 - in core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4: b and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-20 13:48:20 -0500 (Wed, 20 Jan 2010)
New Revision: 18592
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/
Removed:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/FinancialHistory.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/MedicalHistory.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/Person.java
Log:
HHH-4529 clean tests
Copied: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b (from rev 18589, core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a)
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20 18:48:20 UTC (rev 18592)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.e4.a;
+package org.hibernate.test.annotations.derivedidentities.e4.b;
import java.util.Date;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/FinancialHistory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/FinancialHistory.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/FinancialHistory.java 2010-01-20 18:48:20 UTC (rev 18592)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.e4.a;
+package org.hibernate.test.annotations.derivedidentities.e4.b;
import java.util.Date;
import javax.persistence.Entity;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/MedicalHistory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/MedicalHistory.java 2010-01-20 18:48:20 UTC (rev 18592)
@@ -1,10 +1,9 @@
-package org.hibernate.test.annotations.derivedidentities.e4.a;
+package org.hibernate.test.annotations.derivedidentities.e4.b;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
-import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/Person.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/Person.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/b/Person.java 2010-01-20 18:48:20 UTC (rev 18592)
@@ -1,4 +1,4 @@
-package org.hibernate.test.annotations.derivedidentities.e4.a;
+package org.hibernate.test.annotations.derivedidentities.e4.b;
import javax.persistence.Entity;
import javax.persistence.Id;
14 years, 12 months
Hibernate SVN: r18591 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-20 13:42:49 -0500 (Wed, 20 Jan 2010)
New Revision: 18591
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
Log:
HHH-4529 add test for one to one and embedded id
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java 2010-01-20 18:36:34 UTC (rev 18590)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java 2010-01-20 18:42:49 UTC (rev 18591)
@@ -9,7 +9,7 @@
*/
public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends TestCase {
- public void testIt() throws Exception {
+ public void testManyToOne() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK", getCfg() ) );
assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", getCfg() ) );
Employee e = new Employee();
@@ -32,11 +32,35 @@
s.close();
}
+ public void testOneToOne() throws Exception {
+ assertTrue( SchemaUtil.isColumnPresent( "ExclusiveDependent", "FK", getCfg() ) );
+ assertTrue( ! SchemaUtil.isColumnPresent( "ExclusiveDependent", "empPK", getCfg() ) );
+ Employee e = new Employee();
+ e.empId = 1;
+ e.empName = "Emmanuel";
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.persist( e );
+ ExclusiveDependent d = new ExclusiveDependent();
+ d.emp = e;
+ d.id = new DependentId();
+ d.id.name = "Doggy";
+ d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
+ s.persist( d );
+ s.flush();
+ s.clear();
+ d = (ExclusiveDependent) s.get( ExclusiveDependent.class, d.id );
+ assertEquals( d.id.empPK, d.emp.empId );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
@Override
protected Class<?>[] getMappings() {
return new Class<?>[] {
Dependent.class,
- Employee.class
+ Employee.class,
+ ExclusiveDependent.class
};
}
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/ExclusiveDependent.java 2010-01-20 18:42:49 UTC (rev 18591)
@@ -0,0 +1,23 @@
+package org.hibernate.test.annotations.derivedidentities.e1.b;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
+import javax.persistence.MapsId;
+import javax.persistence.OneToOne;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class ExclusiveDependent {
+ @EmbeddedId
+ DependentId id;
+
+ @JoinColumn(name = "FK")
+ // id attribute mapped by join column default
+ @MapsId("empPK")
+ // maps empPK attribute of embedded id
+ @OneToOne
+ Employee emp;
+}
14 years, 12 months
Hibernate SVN: r18590 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/derivedidentities/e1/b and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-20 13:36:34 -0500 (Wed, 20 Jan 2010)
New Revision: 18590
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/CollectionPropertyHolder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/ComponentPropertyHolder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyHolder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyInferredData.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
Log:
HHH-4529 Add support for @EmbeddedId
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -1256,6 +1256,8 @@
if ( !entityBinder.isIgnoreIdAnnotations() &&
( property.isAnnotationPresent( Id.class )
|| property.isAnnotationPresent( EmbeddedId.class ) ) ) {
+ //Override from @MapsId if needed
+ columns = overrideColumnFromMapsIdProperty( "", columns, propertyHolder, entityBinder, mappings );
if ( isIdentifierMapper ) {
throw new AnnotationException(
"@IdClass class should not have @Id nor @EmbeddedId properties"
@@ -1754,6 +1756,12 @@
}
}
+
+ //Override from @MapsId if needed
+ if ( propertyHolder.isOrWithinEmbeddedId() ) {
+ columns = overrideColumnFromMapsIdProperty( property.getName(), columns, propertyHolder, entityBinder, mappings );
+ }
+
PropertyBinder propBinder = new PropertyBinder();
propBinder.setName( inferredData.getPropertyName() );
propBinder.setReturnedClassName( inferredData.getTypeName() );
@@ -2110,25 +2118,6 @@
setupComponentTuplizer( property, componentId );
}
else {
- final XClass persistentXClass;
- try {
- persistentXClass = mappings.getReflectionManager()
- .classForName( persistentClassName, AnnotationBinder.class );
- }
- catch ( ClassNotFoundException e ) {
- throw new AssertionFailure( "Persistence class name cannot be converted into a Class", e);
- }
-
- final PropertyData annotatedWithMapsId = mappings.getPropertyAnnotatedWithMapsId( persistentXClass, "" );
- if ( annotatedWithMapsId != null ) {
- columns = buildExplicitJoinColumns( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
- if (columns == null) {
- columns = buildDefaultJoinColumnsForXToOne( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
- throw new UnsupportedOperationException( "Implicit @JoinColumn is not supported on @MapsId properties: "
- + annotatedWithMapsId.getDeclaringClass() + " " + annotatedWithMapsId.getPropertyName() );
- }
- }
-
for (Ejb3Column column : columns) {
column.forceNotNull(); //this is an id
}
@@ -2170,6 +2159,32 @@
}
}
+ private static Ejb3Column[] overrideColumnFromMapsIdProperty(String propertyPath,
+ Ejb3Column[] columns,
+ PropertyHolder propertyHolder,
+ EntityBinder entityBinder,
+ ExtendedMappings mappings) {
+ Ejb3Column[] result = columns;
+ final XClass persistentXClass;
+ try {
+ persistentXClass = mappings.getReflectionManager()
+ .classForName( propertyHolder.getPersistentClass().getClassName(), AnnotationBinder.class );
+ }
+ catch ( ClassNotFoundException e ) {
+ throw new AssertionFailure( "PersistentClass name cannot be converted into a Class", e);
+ }
+ final PropertyData annotatedWithMapsId = mappings.getPropertyAnnotatedWithMapsId( persistentXClass, propertyPath );
+ if ( annotatedWithMapsId != null ) {
+ result = buildExplicitJoinColumns( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
+ if (result == null) {
+ result = buildDefaultJoinColumnsForXToOne( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
+ throw new UnsupportedOperationException( "Implicit @JoinColumn is not supported on @MapsId properties: "
+ + annotatedWithMapsId.getDeclaringClass() + " " + annotatedWithMapsId.getPropertyName() );
+ }
+ }
+ return result;
+ }
+
private static void setupComponentTuplizer(XProperty property, Component component) {
if ( property == null ) return;
if ( property.isAnnotationPresent( Tuplizers.class ) ) {
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ClassPropertyHolder.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -195,4 +195,8 @@
public KeyValue getIdentifier() {
return persistentClass.getIdentifier();
}
+
+ public boolean isOrWithinEmbeddedId() {
+ return false;
+ }
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/CollectionPropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/CollectionPropertyHolder.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/CollectionPropertyHolder.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -70,6 +70,10 @@
throw new AssertionFailure( "Identifier collection not yet managed" );
}
+ public boolean isOrWithinEmbeddedId() {
+ return false;
+ }
+
public PersistentClass getPersistentClass() {
return collection.getOwner();
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/ComponentPropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ComponentPropertyHolder.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ComponentPropertyHolder.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -24,11 +24,14 @@
package org.hibernate.cfg;
import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import org.hibernate.AnnotationException;
import org.hibernate.annotations.common.reflection.XClass;
+import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.mapping.Component;
import org.hibernate.mapping.Join;
import org.hibernate.mapping.KeyValue;
@@ -45,6 +48,7 @@
//TODO introduce a overrideTable() method for columns held by sec table rather than the hack
// joinsPerRealTableName in ClassPropertyHolder
private Component component;
+ private boolean isOrWithinEmbeddedId;
public String getEntityName() {
return component.getComponentClassName();
@@ -82,8 +86,14 @@
ExtendedMappings mappings
) {
super( path, parent, inferredData.getPropertyClass(), mappings );
- setCurrentProperty( inferredData.getProperty() );
+ final XProperty property = inferredData.getProperty();
+ setCurrentProperty( property );
this.component = component;
+ this.isOrWithinEmbeddedId =
+ parent.isOrWithinEmbeddedId()
+ || ( property != null &&
+ ( property.isAnnotationPresent( Id.class )
+ || property.isAnnotationPresent( EmbeddedId.class ) ) );
}
public String getClassName() {
@@ -106,6 +116,10 @@
return component.getOwner().getIdentifier();
}
+ public boolean isOrWithinEmbeddedId() {
+ return isOrWithinEmbeddedId;
+ }
+
public PersistentClass getPersistentClass() {
return component.getOwner();
}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyHolder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyHolder.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyHolder.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -53,6 +53,11 @@
KeyValue getIdentifier();
+ /**
+ * Return true if this component is or is embedded in a @EmbeddedId
+ */
+ boolean isOrWithinEmbeddedId();
+
PersistentClass getPersistentClass();
boolean isComponent();
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyInferredData.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyInferredData.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/PropertyInferredData.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -44,6 +44,15 @@
private final ReflectionManager reflectionManager;
private final XClass declaringClass;
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append( "PropertyInferredData" );
+ sb.append( "{property=" ).append( property );
+ sb.append( ", declaringClass=" ).append( declaringClass );
+ sb.append( '}' );
+ return sb.toString();
+ }
/**
* Take the annoted element for lazy process
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -2,6 +2,7 @@
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
@@ -13,7 +14,7 @@
@EmbeddedId
DependentId id;
- // id attribute mapped by join column default
+ @JoinColumn(name="FK") // id attribute mapped by join column default
@MapsId("empPK") // maps empPK attribute of embedded id
@ManyToOne
Employee emp;
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java 2010-01-20 16:51:02 UTC (rev 18589)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java 2010-01-20 18:36:34 UTC (rev 18590)
@@ -9,28 +9,28 @@
*/
public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends TestCase {
-// public void testIt() throws Exception {
-// assertTrue( SchemaUtil.isColumnPresent( "Dependent", "empPK", getCfg() ) );
-// assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "emp_empId", getCfg() ) );
-// Employee e = new Employee();
-// e.empId = 1;
-// e.empName = "Emmanuel";
-// Session s = openSession( );
-// s.getTransaction().begin();
-// s.persist( e );
-// Dependent d = new Dependent();
-// d.emp = e;
-// d.id = new DependentId();
-// d.id.name = "Doggy";
-// d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
-// s.persist( d );
-// s.flush();
-// s.clear();
-// d = (Dependent) s.get( Dependent.class, d.id );
-// assertEquals( d.id.empPK, d.emp.empId );
-// s.getTransaction().rollback();
-// s.close();
-// }
+ public void testIt() throws Exception {
+ assertTrue( SchemaUtil.isColumnPresent( "Dependent", "FK", getCfg() ) );
+ assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "empPK", getCfg() ) );
+ Employee e = new Employee();
+ e.empId = 1;
+ e.empName = "Emmanuel";
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.persist( e );
+ Dependent d = new Dependent();
+ d.emp = e;
+ d.id = new DependentId();
+ d.id.name = "Doggy";
+ d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
+ s.persist( d );
+ s.flush();
+ s.clear();
+ d = (Dependent) s.get( Dependent.class, d.id );
+ assertEquals( d.id.empPK, d.emp.empId );
+ s.getTransaction().rollback();
+ s.close();
+ }
@Override
protected Class<?>[] getMappings() {
14 years, 12 months
Hibernate SVN: r18589 - in core/trunk/annotations/src: main/java/org/hibernate/cfg/annotations and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-20 11:51:02 -0500 (Wed, 20 Jan 2010)
New Revision: 18589
Added:
core/trunk/annotations/src/main/java/org/hibernate/cfg/ToOneBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DependentId.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Employee.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/FinancialHistory.java
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/SetSimpleValueTypeSecondPass.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
Log:
HHH-4529 support @ManyToOne and fix FK error
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -1379,12 +1379,13 @@
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
+ final boolean mandatory = !ann.optional() || property.isAnnotationPresent( MapsId.class );
bindManyToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, false),
joinColumns,
- ann.optional(),
+ !mandatory,
ignoreNotFound, onDeleteCascade,
- mappings.getReflectionManager().toXClass( ann.targetEntity() ),
+ ToOneBinder.getTargetEntity( inferredData, mappings ),
propertyHolder,
inferredData, false, isIdentifierMapper, inSecondPass, mappings
);
@@ -1422,7 +1423,7 @@
!mandatory,
getFetchMode( ann.fetch() ),
ignoreNotFound, onDeleteCascade,
- mappings.getReflectionManager().toXClass( ann.targetEntity() ),
+ ToOneBinder.getTargetEntity( inferredData, mappings ),
propertyHolder,
inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper, inSecondPass, mappings
);
@@ -2117,11 +2118,14 @@
catch ( ClassNotFoundException e ) {
throw new AssertionFailure( "Persistence class name cannot be converted into a Class", e);
}
+
final PropertyData annotatedWithMapsId = mappings.getPropertyAnnotatedWithMapsId( persistentXClass, "" );
if ( annotatedWithMapsId != null ) {
columns = buildExplicitJoinColumns( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
if (columns == null) {
columns = buildDefaultJoinColumnsForXToOne( propertyHolder, annotatedWithMapsId.getProperty(), annotatedWithMapsId, entityBinder, mappings );
+ throw new UnsupportedOperationException( "Implicit @JoinColumn is not supported on @MapsId properties: "
+ + annotatedWithMapsId.getDeclaringClass() + " " + annotatedWithMapsId.getPropertyName() );
}
}
@@ -2194,13 +2198,9 @@
if ( unique ) {
value.markAsLogicalOneToOne();
}
- if ( isDefault( targetEntity, mappings ) ) {
- value.setReferencedEntityName( inferredData.getClassOrElementName() );
- }
- else {
- value.setReferencedEntityName( targetEntity.getName() );
- }
- defineFetchingStrategy( value, inferredData.getProperty() );
+ value.setReferencedEntityName( ToOneBinder.getReferenceEntityName(inferredData, targetEntity, mappings) );
+ final XProperty property = inferredData.getProperty();
+ defineFetchingStrategy( value, property );
//value.setFetchMode( fetchMode );
value.setIgnoreNotFound( ignoreNotFound );
value.setCascadeDeleteEnabled( cascadeOnDelete );
@@ -2210,11 +2210,18 @@
column.setNullable( false );
}
}
+ if ( property.isAnnotationPresent( MapsId.class ) ) {
+ //read only
+ for (Ejb3JoinColumn column : columns) {
+ column.setInsertable( false );
+ column.setUpdatable( false );
+ }
+ }
value.setTypeName( inferredData.getClassOrElementName() );
final String propertyName = inferredData.getPropertyName();
value.setTypeUsingReflection( propertyHolder.getClassName(), propertyName );
- ForeignKey fk = inferredData.getProperty().getAnnotation( ForeignKey.class );
+ ForeignKey fk = property.getAnnotation( ForeignKey.class );
String fkName = fk != null ?
fk.name() :
"";
@@ -2250,7 +2257,7 @@
}
binder.setAccessType( inferredData.getDefaultAccess() );
binder.setCascade( cascadeStrategy );
- binder.setProperty(inferredData.getProperty());
+ binder.setProperty( property );
Property prop = binder.make();
//composite FK columns are in the same table so its OK
propertyHolder.addProperty( prop, columns, inferredData.getDeclaringClass() );
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-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationConfiguration.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -374,7 +374,7 @@
iter = secondPasses.iterator();
while ( iter.hasNext() ) {
SecondPass sp = ( SecondPass ) iter.next();
- //do the SecondaryTable second pass before any association becasue associations can be built on joins
+ //do the SecondaryTable second pass before any association because associations can be built on joins
if ( sp instanceof SecondaryTableSecondPass ) {
sp.doSecondPass( classes );
iter.remove();
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -393,6 +393,31 @@
String logicalReferencedColumn = getMappings().getLogicalColumnName(
referencedColumn.getQuotedName(), referencedEntity.getTable()
);
+ columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn );
+ //yuk side effect on an implicit column
+ setLogicalColumnName( columnName );
+ setReferencedColumn( logicalReferencedColumn );
+ initMappingColumn(
+ columnName,
+ null, referencedColumn.getLength(),
+ referencedColumn.getPrecision(),
+ referencedColumn.getScale(),
+ getMappingColumn() != null ? getMappingColumn().isNullable() : false,
+ referencedColumn.getSqlType(),
+ getMappingColumn() != null ? getMappingColumn().isUnique() : false,
+ false
+ );
+ linkWithValue( value );
+ }
+
+ public void addDefaultJoinColumnName(PersistentClass referencedEntity, String logicalReferencedColumn) {
+ final String columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn );
+ getMappingColumn().setName( columnName );
+ setLogicalColumnName( columnName );
+ }
+
+ private String buildDefaultColumnName(PersistentClass referencedEntity, String logicalReferencedColumn) {
+ String columnName;
boolean mappedBySide = mappedByTableName != null || mappedByPropertyName != null;
boolean ownerSide = getPropertyName() != null;
@@ -443,20 +468,7 @@
columnName = StringHelper.quote( columnName );
}
}
- //yuk side effect on an implicit column
- setLogicalColumnName( columnName );
- setReferencedColumn( logicalReferencedColumn );
- initMappingColumn(
- columnName,
- null, referencedColumn.getLength(),
- referencedColumn.getPrecision(),
- referencedColumn.getScale(),
- getMappingColumn() != null ? getMappingColumn().isNullable() : false,
- referencedColumn.getSqlType(),
- getMappingColumn() != null ? getMappingColumn().isUnique() : false,
- false
- );
- linkWithValue( value );
+ return columnName;
}
/**
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/OneToOneSecondPass.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -88,13 +88,7 @@
);
final String propertyName = inferredData.getPropertyName();
value.setPropertyName( propertyName );
- String referencedEntityName;
- if ( AnnotationBinder.isDefault( targetEntity, mappings ) ) {
- referencedEntityName = inferredData.getClassOrElementName();
- }
- else {
- referencedEntityName = targetEntity.getName();
- }
+ String referencedEntityName = ToOneBinder.getReferenceEntityName(inferredData, targetEntity, mappings);
value.setReferencedEntityName( referencedEntityName );
AnnotationBinder.defineFetchingStrategy( value, inferredData.getProperty() );
//value.setFetchMode( fetchMode );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/SetSimpleValueTypeSecondPass.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/SetSimpleValueTypeSecondPass.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/SetSimpleValueTypeSecondPass.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -34,7 +34,7 @@
public class SetSimpleValueTypeSecondPass implements SecondPass {
SimpleValueBinder binder;
-
+
public SetSimpleValueTypeSecondPass(SimpleValueBinder val) {
binder = val;
}
Added: core/trunk/annotations/src/main/java/org/hibernate/cfg/ToOneBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/ToOneBinder.java (rev 0)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/ToOneBinder.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,53 @@
+package org.hibernate.cfg;
+
+import javax.persistence.ManyToOne;
+import javax.persistence.OneToOne;
+
+import org.hibernate.AssertionFailure;
+import org.hibernate.annotations.common.reflection.XClass;
+import org.hibernate.annotations.common.reflection.XProperty;
+
+/**
+ * Work in progress
+ * The goal of this class is to aggregate all operations
+ * related to ToOne binding operations
+ *
+ * @author Emmanuel Bernard
+ */
+public class ToOneBinder {
+ public static String getReferenceEntityName(PropertyData propertyData, XClass targetEntity, ExtendedMappings mappings) {
+ if ( AnnotationBinder.isDefault( targetEntity, mappings ) ) {
+ return propertyData.getClassOrElementName();
+ }
+ else {
+ return targetEntity.getName();
+ }
+ }
+
+ public static String getReferenceEntityName(PropertyData propertyData, ExtendedMappings mappings) {
+ XClass targetEntity = getTargetEntity( propertyData, mappings );
+ if ( AnnotationBinder.isDefault( targetEntity, mappings ) ) {
+ return propertyData.getClassOrElementName();
+ }
+ else {
+ return targetEntity.getName();
+ }
+ }
+
+ public static XClass getTargetEntity(PropertyData propertyData, ExtendedMappings mappings) {
+ XProperty property = propertyData.getProperty();
+ return mappings.getReflectionManager().toXClass( getTargetEntityClass( property ) );
+ }
+
+ private static Class<?> getTargetEntityClass(XProperty property) {
+ final ManyToOne mTo = property.getAnnotation( ManyToOne.class );
+ if (mTo != null) {
+ return mTo.targetEntity();
+ }
+ final OneToOne oTo = property.getAnnotation( OneToOne.class );
+ if (oTo != null) {
+ return oTo.targetEntity();
+ }
+ throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() );
+ }
+}
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/SimpleValueBinder.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -27,6 +27,7 @@
import java.sql.Types;
import java.util.Calendar;
import java.util.Date;
+import java.util.Map;
import java.util.Properties;
import javax.persistence.Enumerated;
import javax.persistence.Lob;
@@ -46,6 +47,7 @@
import org.hibernate.cfg.Ejb3Column;
import org.hibernate.cfg.ExtendedMappings;
import org.hibernate.cfg.NotYetImplementedException;
+import org.hibernate.cfg.SecondPass;
import org.hibernate.cfg.SetSimpleValueTypeSecondPass;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Table;
@@ -288,15 +290,13 @@
table = columns[0].getTable();
}
simpleValue = new SimpleValue( table );
-
- for (Ejb3Column column : columns) {
- column.linkWithValue( simpleValue );
- }
-
+
+ linkWithValue();
+
boolean isInSecondPass = mappings.isInSecondPass();
+ SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass(this);
if (!isInSecondPass) {
//Defer this to the second pass
- SetSimpleValueTypeSecondPass secondPass = new SetSimpleValueTypeSecondPass(this);
mappings.addSecondPass(secondPass);
}
else {
@@ -306,6 +306,12 @@
return simpleValue;
}
+ public void linkWithValue() {
+ for ( Ejb3Column column : columns) {
+ column.linkWithValue( simpleValue );
+ }
+ }
+
public void fillSimpleValue() {
log.debug( "setting SimpleValue typeName for {}", propertyName );
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/annotations/TableBinder.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -314,7 +314,7 @@
) {
PersistentClass associatedClass;
if ( destinationEntity != null ) {
- //overidden destination
+ //overridden destination
associatedClass = destinationEntity;
}
else {
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Dependent.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,21 @@
+package org.hibernate.test.annotations.derivedidentities.e1.b;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+import javax.persistence.MapsId;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Dependent {
+ @EmbeddedId
+ DependentId id;
+
+ // id attribute mapped by join column default
+ @MapsId("empPK") // maps empPK attribute of embedded id
+ @ManyToOne
+ Employee emp;
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DependentId.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DependentId.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DependentId.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,13 @@
+package org.hibernate.test.annotations.derivedidentities.e1.b;
+
+import java.io.Serializable;
+import javax.persistence.Embeddable;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Embeddable
+public class DependentId implements Serializable {
+ String name;
+ long empPK; // corresponds to PK type of Employee
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/DerivedIdentitySimpleParentEmbeddedIdDepTest.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,42 @@
+package org.hibernate.test.annotations.derivedidentities.e1.b;
+
+import org.hibernate.Session;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.util.SchemaUtil;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class DerivedIdentitySimpleParentEmbeddedIdDepTest extends TestCase {
+
+// public void testIt() throws Exception {
+// assertTrue( SchemaUtil.isColumnPresent( "Dependent", "empPK", getCfg() ) );
+// assertTrue( ! SchemaUtil.isColumnPresent( "Dependent", "emp_empId", getCfg() ) );
+// Employee e = new Employee();
+// e.empId = 1;
+// e.empName = "Emmanuel";
+// Session s = openSession( );
+// s.getTransaction().begin();
+// s.persist( e );
+// Dependent d = new Dependent();
+// d.emp = e;
+// d.id = new DependentId();
+// d.id.name = "Doggy";
+// d.id.empPK = e.empId; //FIXME not needed when foreign is enabled
+// s.persist( d );
+// s.flush();
+// s.clear();
+// d = (Dependent) s.get( Dependent.class, d.id );
+// assertEquals( d.id.empPK, d.emp.empId );
+// s.getTransaction().rollback();
+// s.close();
+// }
+
+ @Override
+ protected Class<?>[] getMappings() {
+ return new Class<?>[] {
+ Dependent.class,
+ Employee.class
+ };
+ }
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Employee.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Employee.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e1/b/Employee.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,14 @@
+package org.hibernate.test.annotations.derivedidentities.e1.b;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Employee {
+ @Id
+ long empId;
+ String empName;
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -11,7 +11,7 @@
*/
public class DerivedIdentitySimpleParentSimpleDepTest extends TestCase {
- public void testIt() throws Exception {
+ public void testOneToOneExplicitJoinColumn() throws Exception {
assertTrue( SchemaUtil.isColumnPresent( "MedicalHistory", "FK", getCfg() ) );
assertTrue( ! SchemaUtil.isColumnPresent( "MedicalHistory", "id", getCfg() ) );
Person e = new Person();
@@ -36,11 +36,37 @@
s.close();
}
+ public void testManyToOneExplicitJoinColumn() throws Exception {
+ assertTrue( SchemaUtil.isColumnPresent( "FinancialHistory", "FK", getCfg() ) );
+ assertTrue( ! SchemaUtil.isColumnPresent( "FinancialHistory", "id", getCfg() ) );
+ Person e = new Person();
+ e.ssn = "aaa";
+ Session s = openSession( );
+ s.getTransaction().begin();
+ s.persist( e );
+ FinancialHistory d = new FinancialHistory();
+ d.patient = e;
+ d.id = "aaa"; //FIXME not needed when foreign is enabled
+ s.persist( d );
+ s.flush();
+ s.clear();
+ d = (FinancialHistory) s.get( FinancialHistory.class, d.id );
+ assertEquals( d.id, d.patient.ssn );
+ d.lastupdate = new Date();
+ s.flush();
+ s.clear();
+ d = (FinancialHistory) s.get( FinancialHistory.class, d.id );
+ assertNotNull( d.lastupdate );
+ s.getTransaction().rollback();
+ s.close();
+ }
+
@Override
protected Class<?>[] getMappings() {
return new Class<?>[] {
MedicalHistory.class,
- Person.class
+ Person.class,
+ FinancialHistory.class
};
}
}
\ No newline at end of file
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/FinancialHistory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/FinancialHistory.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/FinancialHistory.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -0,0 +1,27 @@
+package org.hibernate.test.annotations.derivedidentities.e4.a;
+
+import java.util.Date;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
+import javax.persistence.MapsId;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class FinancialHistory {
+ @Id
+ String id; // overriding not allowed ... // default join column name is overridden @MapsId
+ @Temporal(TemporalType.DATE)
+ Date lastupdate;
+
+ @JoinColumn(name = "FK")
+ @MapsId
+ @ManyToOne
+ Person patient;
+
+}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-20 15:35:26 UTC (rev 18588)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-20 16:51:02 UTC (rev 18589)
@@ -4,6 +4,7 @@
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.ManyToOne;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
import javax.persistence.Temporal;
14 years, 12 months
Hibernate SVN: r18588 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue.
by hibernate-commits@lists.jboss.org
Author: stalep
Date: 2010-01-20 10:35:26 -0500 (Wed, 20 Jan 2010)
New Revision: 18588
Added:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/Multiple.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/MultiplePK.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
Log:
[HHH-4552]
added multiple generated values to the test
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java 2010-01-20 15:23:45 UTC (rev 18587)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/IdClassGeneratedValueTest.java 2010-01-20 15:35:26 UTC (rev 18588)
@@ -83,7 +83,32 @@
s.getTransaction().commit();
s.close();
}
+
+ @SuppressWarnings({ "unchecked" })
+ public void testMultipleGeneratedValue() {
+ Session s = openSession();
+ s.beginTransaction();
+ Multiple m1 = new Multiple( 1000L, 10 );
+ s.persist( m1 );
+ Long m1Id1 = m1.getId1();
+ Long m1Id2 = m1.getId2();
+ Multiple m2 = new Multiple( 2000L, 20 );
+ s.persist( m2 );
+ s.getTransaction().commit();
+ s.close();
+ s = openSession();
+ s.beginTransaction();
+ List<Simple> simpleList = s.createQuery( "select m from Multiple m" ).list();
+ assertEquals( simpleList.size(), 2 );
+ m1 = (Multiple) s.load( Multiple.class, new MultiplePK( m1Id1, m1Id2, 2L ) );
+ assertEquals( m1.getQuantity(), 10 );
+ s.clear();
+ s.createQuery( "delete Multiple" ).executeUpdate();
+ s.getTransaction().commit();
+ s.close();
+ }
+
// public void testComplexIdClass() {
// Session s = openSession();
// Transaction tx = s.beginTransaction();
@@ -128,7 +153,9 @@
// CustomerInventory.class,
// Item.class,
Simple.class,
- Simple2.class
+ Simple2.class,
+ Multiple.class
+
};
}
}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/Multiple.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/Multiple.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/Multiple.java 2010-01-20 15:35:26 UTC (rev 18588)
@@ -0,0 +1,96 @@
+/*
+ * 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.annotations.idclassgeneratedvalue;
+
+import java.io.Serializable;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+
+import org.hibernate.annotations.GenericGenerator;
+
+/**
+ * An Entity containing a composite key with two generated values.
+ *
+ * @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
+ */
+@Entity
+(a)IdClass(MultiplePK.class)
+@SuppressWarnings("serial")
+public class Multiple implements Serializable
+{
+ @Id
+ @GenericGenerator(name = "increment", strategy = "increment")
+ @GeneratedValue(generator = "increment")
+ private Long id1;
+
+ @Id
+ @GenericGenerator(name = "increment2", strategy = "increment")
+ @GeneratedValue(generator = "increment2")
+ private Long id2;
+
+ @Id
+ private Long id3;
+ private int quantity;
+
+ public Multiple()
+ {
+
+ }
+
+ public Multiple(Long id3, int quantity)
+ {
+ this.id3 = id3;
+ this.quantity = quantity;
+ }
+
+ public Long getId1()
+ {
+ return id1;
+ }
+
+ public Long getId2()
+ {
+ return id2;
+ }
+
+ public Long getId3()
+ {
+ return id3;
+ }
+
+ public int getQuantity()
+ {
+ return quantity;
+ }
+
+ public void setQuantity(int quantity)
+ {
+ this.quantity = quantity;
+ }
+
+
+}
Added: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/MultiplePK.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/MultiplePK.java (rev 0)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/idclassgeneratedvalue/MultiplePK.java 2010-01-20 15:35:26 UTC (rev 18588)
@@ -0,0 +1,98 @@
+/*
+ * 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.annotations.idclassgeneratedvalue;
+
+import java.io.Serializable;
+
+/**
+ * MultiplePK
+ *
+ * @author <a href="mailto:stale.pedersen@jboss.org">Stale W. Pedersen</a>
+ */
+public class MultiplePK implements Serializable
+{
+ private final Long id1;
+ private final Long id2;
+ private final Long id3;
+// AnnotationBinder (incorrectly) requires this to be transient; see HHH-4819 and HHH-4820
+ private final transient int cachedHashCode;
+
+ private MultiplePK()
+ {
+ id1 = null;
+ id2 = null;
+ id3 = null;
+ cachedHashCode = super.hashCode();
+ }
+
+ public MultiplePK(Long id1, Long id2, Long id3)
+ {
+ this.id1 = id1;
+ this.id2 = id2;
+ this.id3 = id3;
+ this.cachedHashCode = calculateHashCode();
+ }
+
+
+ private int calculateHashCode() {
+ int result = id1.hashCode();
+ result = 31 * result + id2.hashCode();
+ return result;
+ }
+
+ public Long getId1() {
+ return id1;
+ }
+
+ public Long getId2() {
+ return id2;
+ }
+
+ public Long getId3() {
+ return id3;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if ( this == o ) {
+ return true;
+ }
+ if ( o == null || getClass() != o.getClass() )
+ {
+ return false;
+ }
+
+ MultiplePK multiplePK = (MultiplePK) o;
+
+ return id1.equals( multiplePK.id1 )
+ && id2.equals( multiplePK.id2 )
+ && id3.equals( multiplePK.id3);
+ }
+
+ @Override
+ public int hashCode() {
+ return cachedHashCode;
+ }
+}
14 years, 12 months
Hibernate SVN: r18586 - in core/trunk/annotations/src: test/java/org/hibernate/test/annotations/derivedidentities/e4/a and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-01-20 06:48:08 -0500 (Wed, 20 Jan 2010)
New Revision: 18586
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
Log:
HHH-4529 FK constraint is now generated
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-19 22:16:05 UTC (rev 18585)
+++ core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20 11:48:08 UTC (rev 18586)
@@ -1414,10 +1414,12 @@
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
+ //MapsId means the columns belong to the pk => not null
+ final boolean mandatory = !ann.optional() || property.isAnnotationPresent( MapsId.class );
bindOneToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval()),
joinColumns,
- ann.optional(),
+ !mandatory,
getFetchMode( ann.fetch() ),
ignoreNotFound, onDeleteCascade,
mappings.getReflectionManager().toXClass( ann.targetEntity() ),
@@ -2088,6 +2090,7 @@
RootClass rootClass = (RootClass) persistentClass;
String persistentClassName = rootClass.getClassName();
SimpleValue id;
+ final String propertyName = inferredData.getPropertyName();
if ( isComposite ) {
id = fillComponent(
propertyHolder, inferredData, baseInferredData, propertyAccessor,
@@ -2126,7 +2129,7 @@
column.forceNotNull(); //this is an id
}
SimpleValueBinder value = new SimpleValueBinder();
- value.setPropertyName( inferredData.getPropertyName() );
+ value.setPropertyName( propertyName );
value.setReturnedClassName( inferredData.getTypeName() );
value.setColumns( columns );
value.setPersistentClassName( persistentClassName );
@@ -2141,7 +2144,7 @@
}
else {
PropertyBinder binder = new PropertyBinder();
- binder.setName( inferredData.getPropertyName() );
+ binder.setName( propertyName );
binder.setValue( id );
binder.setAccessType( inferredData.getDefaultAccess() );
binder.setProperty( inferredData.getProperty() );
@@ -2220,7 +2223,7 @@
String path = propertyHolder.getPath() + "." + propertyName;
FkSecondPass secondPass = new ToOneFkSecondPass(
value, columns,
- !optional && unique, //cannot have nullabe and unique on certain DBs like Derby
+ !optional && unique, //cannot have nullable and unique on certain DBs like Derby
propertyHolder.getEntityOwnerClassName(),
path, mappings
);
@@ -2328,15 +2331,20 @@
Iterator idColumns = identifier.getColumnIterator();
List<String> idColumnNames = new ArrayList<String>();
org.hibernate.mapping.Column currentColumn;
- while ( idColumns.hasNext() ) {
- currentColumn = (org.hibernate.mapping.Column) idColumns.next();
- idColumnNames.add( currentColumn.getName() );
+ if ( identifier.getColumnSpan() != joinColumns.length ) {
+ mapToPK = false;
}
- for (Ejb3JoinColumn col : joinColumns) {
- if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
- mapToPK = false;
- break;
+ else {
+ while ( idColumns.hasNext() ) {
+ currentColumn = (org.hibernate.mapping.Column) idColumns.next();
+ idColumnNames.add( currentColumn.getName() );
}
+ for (Ejb3JoinColumn col : joinColumns) {
+ if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
+ mapToPK = false;
+ break;
+ }
+ }
}
}
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-19 22:16:05 UTC (rev 18585)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20 11:48:08 UTC (rev 18586)
@@ -1,5 +1,7 @@
package org.hibernate.test.annotations.derivedidentities.e4.a;
+import java.util.Date;
+
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.util.SchemaUtil;
@@ -25,6 +27,11 @@
s.clear();
d = (MedicalHistory) s.get( MedicalHistory.class, d.id );
assertEquals( d.id, d.patient.ssn );
+ d.lastupdate = new Date();
+ s.flush();
+ s.clear();
+ d = (MedicalHistory) s.get( MedicalHistory.class, d.id );
+ assertNotNull( d.lastupdate );
s.getTransaction().rollback();
s.close();
}
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-19 22:16:05 UTC (rev 18585)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-20 11:48:08 UTC (rev 18586)
@@ -1,18 +1,24 @@
package org.hibernate.test.annotations.derivedidentities.e4.a;
+import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
/**
* @author Emmanuel Bernard
*/
@Entity
public class MedicalHistory {
- @Id
- String id; // overriding not allowed ... // default join column name is overridden @MapsId
+
+ @Id String id; // overriding not allowed ... // default join column name is overridden @MapsId
+ @Temporal(TemporalType.DATE)
+ Date lastupdate;
+
@JoinColumn(name = "FK")
@MapsId
@OneToOne
14 years, 12 months
Hibernate SVN: r18585 - in core/trunk: entitymanager/src/main/java/org/hibernate/ejb and 3 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-19 17:16:05 -0500 (Tue, 19 Jan 2010)
New Revision: 18585
Modified:
core/trunk/core/src/main/java/org/hibernate/LockOptions.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java
Log:
HHH-4651 - Add support for EntityManager properties
Modified: core/trunk/core/src/main/java/org/hibernate/LockOptions.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/core/src/main/java/org/hibernate/LockOptions.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -1,3 +1,4 @@
+// $Id:$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -23,6 +24,7 @@
*/
package org.hibernate;
+import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
@@ -33,7 +35,7 @@
*
* @author Scott Marlow
*/
-public class LockOptions
+public class LockOptions implements Serializable
{
/**
* NO_WAIT timeout value will not block for pessimistic locking
@@ -67,10 +69,8 @@
private Map /* <String, LockMode> */ lockModesByName = new HashMap();
public LockOptions() {
-
}
-
public LockOptions( LockMode lockMode) {
this.lockMode = lockMode;
}
@@ -193,5 +193,4 @@
dest.lockModesByName = new HashMap(from.lockModesByName);
return dest;
}
-
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AbstractEntityManagerImpl.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -1,10 +1,11 @@
+// $Id:$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
- * Copyright (c) 2009 by Red Hat Inc and/or its affiliates or by
- * third-party contributors as indicated by either @author tags or express
- * copyright attribution statements applied by the authors. All
- * third-party contributions are distributed under license by Red Hat Inc.
+ * 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
@@ -27,28 +28,31 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.EntityNotFoundException;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.LockModeType;
+import javax.persistence.LockTimeoutException;
import javax.persistence.NoResultException;
import javax.persistence.NonUniqueResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceException;
import javax.persistence.PessimisticLockException;
+import javax.persistence.PessimisticLockScope;
import javax.persistence.Query;
+import javax.persistence.QueryTimeoutException;
import javax.persistence.TransactionRequiredException;
import javax.persistence.Tuple;
import javax.persistence.TupleElement;
import javax.persistence.TypedQuery;
-import javax.persistence.PessimisticLockScope;
-import javax.persistence.LockTimeoutException;
-import javax.persistence.QueryTimeoutException;
+import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
-import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Selection;
import javax.persistence.metamodel.Metamodel;
import javax.persistence.spi.PersistenceUnitTransactionType;
@@ -61,36 +65,59 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.hibernate.*;
+import org.hibernate.AssertionFailure;
+import org.hibernate.FlushMode;
+import org.hibernate.HibernateException;
+import org.hibernate.LockMode;
+import org.hibernate.LockOptions;
+import org.hibernate.MappingException;
+import org.hibernate.ObjectDeletedException;
+import org.hibernate.ObjectNotFoundException;
+import org.hibernate.QueryException;
+import org.hibernate.SQLQuery;
+import org.hibernate.Session;
+import org.hibernate.StaleObjectStateException;
+import org.hibernate.StaleStateException;
+import org.hibernate.Transaction;
+import org.hibernate.TransientObjectException;
+import org.hibernate.TypeMismatchException;
+import org.hibernate.UnresolvableObjectException;
import org.hibernate.cfg.Environment;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.ValueHandlerFactory;
import org.hibernate.ejb.criteria.expression.CompoundSelectionImpl;
import org.hibernate.ejb.transaction.JoinableCMTTransaction;
import org.hibernate.ejb.util.ConfigurationHelper;
-import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.transaction.TransactionFactory;
import org.hibernate.transform.BasicTransformerAdapter;
-import org.hibernate.util.CollectionHelper;
import org.hibernate.util.JTAHelper;
/**
* @author <a href="mailto:gavin@hibernate.org">Gavin King</a>
* @author Emmanuel Bernard
* @author Steve Ebersole
+ * @author Hardy Ferentschik
*/
@SuppressWarnings("unchecked")
public abstract class AbstractEntityManagerImpl implements HibernateEntityManagerImplementor, Serializable {
private static final Logger log = LoggerFactory.getLogger( AbstractEntityManagerImpl.class );
+ private static final List<String> entityManagerSpecificProperties = new ArrayList<String>();
+ static {
+ entityManagerSpecificProperties.add( AvailableSettings.LOCK_SCOPE );
+ entityManagerSpecificProperties.add( AvailableSettings.LOCK_TIMEOUT );
+ entityManagerSpecificProperties.add( AvailableSettings.FLUSH_MODE );
+ }
+
private EntityManagerFactoryImpl entityManagerFactory;
protected transient TransactionImpl tx = new TransactionImpl( this );
protected PersistenceContextType persistenceContextType;
- private FlushModeType flushModeType = FlushModeType.AUTO;
private PersistenceUnitTransactionType transactionType;
- private Map properties;
+ private Map<String, Object> properties;
+ private LockOptions lockOptions;
protected AbstractEntityManagerImpl(
EntityManagerFactoryImpl entityManagerFactory,
@@ -100,7 +127,16 @@
this.entityManagerFactory = entityManagerFactory;
this.persistenceContextType = type;
this.transactionType = transactionType;
- this.properties = properties != null ? properties : CollectionHelper.EMPTY_MAP;
+
+ this.lockOptions = new LockOptions( );
+ this.properties = new HashMap<String, Object>();
+ if(properties != null) {
+ for ( String key : entityManagerSpecificProperties ) {
+ if ( properties.containsKey( key ) ) {
+ this.properties.put( key, properties.get( key ) );
+ }
+ }
+ }
}
protected void postInit() {
@@ -108,13 +144,67 @@
if ( PersistenceUnitTransactionType.JTA.equals( transactionType ) ) {
joinTransaction( true );
}
- Object flushMode = properties.get( "org.hibernate.flushMode" );
- if ( flushMode != null ) {
- getSession().setFlushMode( ConfigurationHelper.getFlushMode( flushMode ) );
+
+ setDefaultProperties();
+ applyProperties();
+ }
+
+ private void applyProperties() {
+ getSession().setFlushMode( ConfigurationHelper.getFlushMode( properties.get( AvailableSettings.FLUSH_MODE ) ) );
+ setLockOptions(this.properties, this.lockOptions);
+ }
+
+ private void setLockOptions(Map<String, Object> props, LockOptions options) {
+ Object lockScope = props.get( AvailableSettings.LOCK_SCOPE );
+ if ( lockScope instanceof String && PessimisticLockScope.valueOf( ( String ) lockScope ) == PessimisticLockScope.EXTENDED ) {
+ options.setScope( true );
}
- this.properties = null;
+ else if ( lockScope instanceof PessimisticLockScope ) {
+ boolean extended = PessimisticLockScope.EXTENDED.equals( ( PessimisticLockScope ) lockScope );
+ options.setScope( extended );
+ }
+ else {
+ throw new PersistenceException( "Unable to parse " + AvailableSettings.LOCK_SCOPE + ": " + lockScope );
+ }
+
+ Object lockTimeout = props.get( AvailableSettings.LOCK_TIMEOUT );
+ int timeout;
+ if ( lockTimeout instanceof String ) {
+ timeout = Integer.parseInt( ( String ) lockTimeout );
+ }
+ else if ( lockTimeout instanceof Integer ) {
+ timeout = ( Integer ) lockTimeout;
+ }
+ else {
+ throw new PersistenceException( "Unable to parse " + AvailableSettings.LOCK_TIMEOUT + ": " + lockTimeout );
+ }
+ if ( timeout < 0 ) {
+ options.setTimeOut( LockOptions.WAIT_FOREVER );
+ }
+ else if ( timeout == 0 ) {
+ options.setTimeOut( LockOptions.NO_WAIT );
+ }
+ else {
+ options.setTimeOut( timeout );
+ }
}
+ /**
+ * Sets the default property values for the properties the entity manager supports and which are not already explicitly
+ * set.
+ */
+ private void setDefaultProperties() {
+ if (properties.get( AvailableSettings.FLUSH_MODE ) == null) {
+ properties.put( AvailableSettings.FLUSH_MODE, getSession().getFlushMode().toString() );
+ }
+ if (properties.get( AvailableSettings.LOCK_SCOPE ) == null) {
+ this.properties.put( AvailableSettings.LOCK_SCOPE, PessimisticLockScope.EXTENDED.name() );
+ }
+ if (properties.get( AvailableSettings.LOCK_TIMEOUT ) == null) {
+ properties.put( AvailableSettings.LOCK_TIMEOUT, LockOptions.WAIT_FOREVER );
+ }
+ }
+
public Query createQuery(String jpaqlString) {
try {
return new QueryImpl<Object>( getSession().createQuery( jpaqlString ), this );
@@ -328,7 +418,6 @@
}
}
-
public Query createNativeQuery(String sqlString) {
try {
SQLQuery q = getSession().createSQLQuery( sqlString );
@@ -397,9 +486,12 @@
public <A> A find(Class<A> entityClass, Object primaryKey, LockModeType lockModeType, Map<String, Object> properties) {
LockOptions lockOptions = null;
try {
- if ( lockModeType != null )
- return ( A ) getSession().get( entityClass, ( Serializable ) primaryKey,
- ( lockOptions = getLockRequest(lockModeType, properties) ) );
+ if ( lockModeType != null ) {
+ return ( A ) getSession().get(
+ entityClass, ( Serializable ) primaryKey,
+ getLockRequest( lockModeType, properties )
+ );
+ }
else
return ( A ) getSession().get( entityClass, ( Serializable ) primaryKey );
}
@@ -530,17 +622,21 @@
if ( !contains( entity ) ) {
throw new IllegalArgumentException( "entity not in the persistence context" );
}
- return this.getLockModeType(getSession().getCurrentLockMode(entity));
+ return getLockModeType(getSession().getCurrentLockMode(entity));
}
public void setProperty(String s, Object o) {
- //FIXME
- //To change body of implemented methods use File | Settings | File Templates.
+ if ( entityManagerSpecificProperties.contains( s ) ) {
+ properties.put( s, o );
+ applyProperties();
+ }
+ else {
+ log.debug( "Trying to set a property which is not supported on entity manager level" );
+ }
}
public Map<String, Object> getProperties() {
- //FIXME
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return Collections.unmodifiableMap( properties );
}
public void flush() {
@@ -548,7 +644,6 @@
if ( !isTransactionInProgress() ) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
- //adjustFlushMode();
getSession().flush();
}
catch ( RuntimeException e ) {
@@ -606,7 +701,6 @@
}
public void setFlushMode(FlushModeType flushModeType) {
- this.flushModeType = flushModeType;
if ( flushModeType == FlushModeType.AUTO ) {
getSession().setFlushMode( FlushMode.AUTO );
}
@@ -619,7 +713,6 @@
}
public void clear() {
- //adjustFlushMode();
try {
getSession().clear();
}
@@ -646,16 +739,15 @@
public FlushModeType getFlushMode() {
FlushMode mode = getSession().getFlushMode();
if ( mode == FlushMode.AUTO ) {
- this.flushModeType = FlushModeType.AUTO;
+ return FlushModeType.AUTO;
}
else if ( mode == FlushMode.COMMIT ) {
- this.flushModeType = FlushModeType.COMMIT;
+ return FlushModeType.COMMIT;
}
else {
+ // otherwise this is an unknown mode for EJB3
return null;
}
- //otherwise this is an unknown mode for EJB3
- return flushModeType;
}
public void lock(Object entity, LockModeType lockMode) {
@@ -668,7 +760,6 @@
if ( !isTransactionInProgress() ) {
throw new TransactionRequiredException( "no transaction is in progress" );
}
- //adjustFlushMode();
if ( !contains( entity ) ) {
throw new IllegalArgumentException( "entity not in the persistence context" );
}
@@ -677,36 +768,19 @@
catch ( HibernateException he ) {
throw convert( he , lockOptions);
}
-
}
public LockOptions getLockRequest(LockModeType lockModeType, Map<String, Object> properties) {
LockOptions lockOptions = new LockOptions();
- lockOptions.setLockMode(getLockMode(lockModeType));
+ LockOptions.copy( this.lockOptions, lockOptions );
+ lockOptions.setLockMode( getLockMode( lockModeType ) );
if ( properties != null ) {
- // lockOptions scope will default to false (PessimisticLockScope.NORMAL)
- Object value = properties.get( AvailableSettings.LOCK_SCOPE );
- if ( value instanceof String && PessimisticLockScope.valueOf((String) value) == PessimisticLockScope.EXTENDED) {
- lockOptions.setScope(true);
- }
- // lockOptions timeout will default to LockOptions.FOREVER_WAIT
- value = properties.get( AvailableSettings.LOCK_TIMEOUT );
- if ( value instanceof String ) {
- int timeout = Integer.parseInt((String) value);
- if ( timeout < 0 ) {
- lockOptions.setTimeOut(LockOptions.WAIT_FOREVER);
- }
- else if( timeout == 0 ) {
- lockOptions.setTimeOut(LockOptions.NO_WAIT);
- }
- else {
- lockOptions.setTimeOut(timeout);
- }
- }
+ setLockOptions( properties, lockOptions );
}
return lockOptions;
}
+ @SuppressWarnings("deprecation")
private static LockModeType getLockModeType(LockMode lockMode) {
if ( lockMode == LockMode.NONE )
return LockModeType.NONE;
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/AvailableSettings.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -168,65 +168,83 @@
* JAR autodetection artifacts class, hbm
*/
public static final String AUTODETECTION = "hibernate.archive.autodetection";
+
/**
* cfg.xml configuration file used
*/
public static final String CFG_FILE = "hibernate.ejb.cfgfile";
+
/**
* Caching configuration should follow the following pattern
* hibernate.ejb.classcache.<fully.qualified.Classname> usage[, region]
* where usage is the cache strategy used and region the cache region name
*/
public static final String CLASS_CACHE_PREFIX = "hibernate.ejb.classcache";
+
/**
* Caching configuration should follow the following pattern
* hibernate.ejb.collectioncache.<fully.qualified.Classname>.<role> usage[, region]
* where usage is the cache strategy used and region the cache region name
*/
public static final String COLLECTION_CACHE_PREFIX = "hibernate.ejb.collectioncache";
+
/**
* Interceptor class name, the class has to have a no-arg constructor
* the interceptor instance is shared amongst all EntityManager of a given EntityManagerFactory
*/
public static final String INTERCEPTOR = "hibernate.ejb.interceptor";
+
/**
* Interceptor class name, the class has to have a no-arg constructor
*/
public static final String SESSION_INTERCEPTOR = "hibernate.ejb.interceptor.session_scoped";
+
/**
* Naming strategy class name, the class has to have a no-arg constructor
*/
public static final String NAMING_STRATEGY = "hibernate.ejb.naming_strategy";
+
/**
* Event configuration should follow the following pattern
* hibernate.ejb.event.[eventType] f.q.c.n.EventListener1, f.q.c.n.EventListener12 ...
*/
public static final String EVENT_LISTENER_PREFIX = "hibernate.ejb.event";
+
/**
* Enable the class file enhancement
*/
public static final String USE_CLASS_ENHANCER = "hibernate.ejb.use_class_enhancer";
+
/**
* Whether or not discard persistent context on entityManager.close()
* The EJB3 compliant and default choice is false
*/
public static final String DISCARD_PC_ON_CLOSE = "hibernate.ejb.discard_pc_on_close";
+
/**
* Consider this as experimental
* It is not recommended to set up this property, the configuration is stored
* in the JNDI in a serialized form
*/
public static final String CONFIGURATION_JNDI_NAME = "hibernate.ejb.configuration_jndi_name";
+
/**
+ * Used to detrmine flush mode.
+ */
+ public static final String FLUSH_MODE = "org.hibernate.flushMode";
+
+ /**
* List of classes names
* Internal use only
*/
public static final String CLASS_NAMES = "hibernate.ejb.classes";
+
/**
* List of annotated packages
* Internal use only
*/
public static final String PACKAGE_NAMES = "hibernate.ejb.packages";
+
/**
* List of classes names
* Internal use only
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/util/ConfigurationHelper.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -78,7 +78,6 @@
default:
throw new AssertionFailure("Unknown FlushModeType: " + flushMode);
}
-
}
public static Integer getInteger(Object value) {
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/EntityManagerTest.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -1,4 +1,27 @@
//$Id$
+/*
+ * 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.ejb.test;
import java.io.ByteArrayInputStream;
@@ -10,11 +33,13 @@
import java.util.HashSet;
import java.util.Map;
import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
import javax.persistence.FlushModeType;
import javax.persistence.Query;
import org.hibernate.FlushMode;
import org.hibernate.HibernateException;
+import org.hibernate.ejb.AvailableSettings;
import org.hibernate.ejb.HibernateEntityManager;
import org.hibernate.ejb.HibernateEntityManagerFactory;
import org.hibernate.stat.Statistics;
@@ -25,7 +50,7 @@
public class EntityManagerTest extends TestCase {
public Class[] getAnnotatedClasses() {
- return new Class[]{
+ return new Class[] {
Item.class,
Distributor.class,
Wallet.class
@@ -44,55 +69,8 @@
return result;
}
- // EM TRANSACTION
-// public void testEntityManager() {
-//
-// Item item = new Item( "Mouse", "Micro$oft mouse" );
-//
-// EntityManager em = getEntityManager();
-// em.getTransaction().begin();
-// em.persist( item );
-// assertTrue( em.contains( item ) );
-// em.getTransaction().commit();
-//
-// assertFalse( em.contains( item ) );
-//
-// em.getTransaction().begin();
-// item = (Item) em.createQuery( "from Item where descr like 'M%'" ).getSingleResult();
-// assertNotNull( item );
-// assertEquals( "Micro$oft mouse", item.getDescr() );
-// item.setDescr( "Micro$oft wireless mouse" );
-// assertTrue( em.contains( item ) );
-// em.getTransaction().commit();
-//
-// assertFalse( em.contains( item ) );
-//
-// em.getTransaction().begin();
-// item = (Item) em.find( Item.class, "Mouse" );
-// assertNotNull( item );
-// em.getTransaction().commit();
-//
-// item = em.find( Item.class, "Mouse" );
-// assertFalse( em.contains( item ) );
-//
-// item = (Item) em.createQuery( "from Item where descr like 'M%'" ).getSingleResult();
-// assertNotNull( item );
-// assertFalse( em.contains( item ) );
-//
-// em.getTransaction().begin();
-// item = em.find( Item.class, "Mouse" );
-// assertNotNull( item );
-// assertTrue( em.contains( item ) );
-// assertEquals( "Micro$oft wireless mouse", item.getDescr() );
-// em.remove( item );
-// em.remove( item );//second should be a no-op
-// em.getTransaction().commit();
-//
-// em.close();
-// }
+ public void testEntityManager() {
- public void testExtendedEntityManager() {
-
Item item = new Item( "Mouse", "Micro$oft mouse" );
EntityManager em = getOrCreateEntityManager();
@@ -104,7 +82,7 @@
assertTrue( em.contains( item ) );
em.getTransaction().begin();
- Item item1 = (Item) em.createQuery( "select i from Item i where descr like 'M%'" ).getSingleResult();
+ Item item1 = ( Item ) em.createQuery( "select i from Item i where descr like 'M%'" ).getSingleResult();
assertNotNull( item1 );
assertSame( item, item1 );
item.setDescr( "Micro$oft wireless mouse" );
@@ -123,7 +101,7 @@
assertSame( item, item1 );
assertTrue( em.contains( item ) );
- item1 = (Item) em.createQuery( "select i from Item i where descr like 'M%'" ).getSingleResult();
+ item1 = ( Item ) em.createQuery( "select i from Item i where descr like 'M%'" ).getSingleResult();
assertNotNull( item1 );
assertSame( item, item1 );
assertTrue( em.contains( item ) );
@@ -144,7 +122,7 @@
res.setName( "Bruce" );
item.setDistributors( new HashSet<Distributor>() );
item.getDistributors().add( res );
- Statistics stats = ( (HibernateEntityManagerFactory) factory ).getSessionFactory().getStatistics();
+ Statistics stats = ( ( HibernateEntityManagerFactory ) factory ).getSessionFactory().getStatistics();
stats.clear();
stats.setStatisticsEnabled( true );
@@ -191,9 +169,11 @@
em.contains( nonManagedObject );
fail( "Should have raised an exception" );
}
- catch (IllegalArgumentException iae) {
+ catch ( IllegalArgumentException iae ) {
//success
- if ( em.getTransaction() != null ) em.getTransaction().rollback();
+ if ( em.getTransaction() != null ) {
+ em.getTransaction().rollback();
+ }
}
finally {
em.close();
@@ -232,7 +212,7 @@
EntityManager em = getOrCreateEntityManager();
em.setFlushMode( FlushModeType.COMMIT );
assertEquals( FlushModeType.COMMIT, em.getFlushMode() );
- ( (HibernateEntityManager) em ).getSession().setFlushMode( FlushMode.ALWAYS );
+ ( ( HibernateEntityManager ) em ).getSession().setFlushMode( FlushMode.ALWAYS );
assertNull( em.getFlushMode() );
em.close();
}
@@ -261,7 +241,7 @@
Query query = em.createQuery( "SELECT p FETCH JOIN p.distributors FROM Item p" );
query.getSingleResult();
}
- catch (IllegalArgumentException e) {
+ catch ( IllegalArgumentException e ) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream( stream );
out.writeObject( e );
@@ -270,7 +250,7 @@
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
ObjectInputStream in = new ObjectInputStream( byteIn );
- IllegalArgumentException deserializedException = (IllegalArgumentException) in.readObject();
+ IllegalArgumentException deserializedException = ( IllegalArgumentException ) in.readObject();
in.close();
byteIn.close();
assertNull( deserializedException.getCause().getCause() );
@@ -289,7 +269,7 @@
stream.close();
ByteArrayInputStream byteIn = new ByteArrayInputStream( serialized );
ObjectInputStream in = new ObjectInputStream( byteIn );
- HibernateException deserializedException = (HibernateException) in.readObject();
+ HibernateException deserializedException = ( HibernateException ) in.readObject();
in.close();
byteIn.close();
assertNotNull( "Arbitrary exceptions nullified", deserializedException.getCause() );
@@ -307,30 +287,78 @@
}
//EJB-9
-// public void testGet() throws Exception {
-// EntityManager em = getEntityManager();
-// em.getTransaction().begin();
-// Item item = (Item) em.get(Item.class, "nonexistentone");
-// try {
-// item.getDescr();
-// em.getTransaction().commit();
-// fail("Object with wrong id should have failed");
-// }
-// catch (EntityNotFoundException e) {
-// //success
-// if (em.getTransaction() != null) em.getTransaction().rollback();
-// }
-// finally {
-// em.close();
-// }
-// }
+ public void testGet() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Item item = ( Item ) em.getReference( Item.class, "nonexistentone" );
+ try {
+ item.getDescr();
+ em.getTransaction().commit();
+ fail( "Object with wrong id should have failed" );
+ }
+ catch ( EntityNotFoundException e ) {
+ //success
+ if ( em.getTransaction() != null ) {
+ em.getTransaction().rollback();
+ }
+ }
+ finally {
+ em.close();
+ }
+ }
- public EntityManagerTest() {
- super();
+ public void testGetProperties() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ Map<String, Object> properties = em.getProperties();
+ assertNotNull( properties );
+ try {
+ properties.put( "foo", "bar" );
+ fail();
+ }
+ catch ( UnsupportedOperationException e ) {
+ // success
+ }
+
+ assertTrue( properties.containsKey( AvailableSettings.FLUSH_MODE ) );
}
- public EntityManagerTest(String arg0) {
- super( arg0 );
+ public void testSetProperty() throws Exception {
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+ Wallet wallet = new Wallet();
+ wallet.setSerial( "000" );
+ em.persist( wallet );
+ em.getTransaction().commit();
+
+ em.clear();
+ assertEquals( em.getProperties().get( AvailableSettings.FLUSH_MODE ), "AUTO" );
+ assertNotNull(
+ "With default settings the entity should be persisted on commit.",
+ em.find( Wallet.class, wallet.getSerial() )
+ );
+
+ em.getTransaction().begin();
+ wallet = em.merge( wallet );
+ em.remove( wallet );
+ em.getTransaction().commit();
+
+ em.clear();
+ assertNull( "The entity should have been removed.", em.find( Wallet.class, wallet.getSerial() ) );
+
+ em.setProperty( "org.hibernate.flushMode", "MANUAL" +
+ "" );
+ em.getTransaction().begin();
+ wallet = new Wallet();
+ wallet.setSerial( "000" );
+ em.persist( wallet );
+ em.getTransaction().commit();
+
+ em.clear();
+ assertNull(
+ "With a flush mode of manual the entity should not have been persisted.",
+ em.find( Wallet.class, wallet.getSerial() )
+ );
+ assertEquals( "MANUAL", em.getProperties().get( AvailableSettings.FLUSH_MODE ) );
+ em.close();
}
-
}
Modified: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java 2010-01-19 21:52:23 UTC (rev 18584)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/test/emops/FlushModeTest.java 2010-01-19 22:16:05 UTC (rev 18585)
@@ -1,8 +1,31 @@
//$Id$
+/*
+ * 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.ejb.test.emops;
+import java.util.HashMap;
import java.util.Map;
-import java.util.HashMap;
import javax.persistence.EntityManager;
import org.hibernate.ejb.test.TestCase;
@@ -13,12 +36,12 @@
public class FlushModeTest extends TestCase {
public void testCreateEMFlushMode() throws Exception {
- Map properties = new HashMap();
+ Map<String, String> properties = new HashMap<String, String>();
properties.put( "org.hibernate.flushMode", "manual" );
EntityManager em = createEntityManager( properties );
em.getTransaction().begin();
Dress dress = new Dress();
- dress.name = "long dress";
+ dress.name = "long dress";
em.persist( dress );
em.getTransaction().commit();
14 years, 12 months
Hibernate SVN: r18584 - core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-01-19 16:52:23 -0500 (Tue, 19 Jan 2010)
New Revision: 18584
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
Log:
Removed unused import statements
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-19 18:57:19 UTC (rev 18583)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-19 21:52:23 UTC (rev 18584)
@@ -2,9 +2,6 @@
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
-import org.hibernate.test.annotations.derivedidentities.e1.b.Dependent;
-import org.hibernate.test.annotations.derivedidentities.e1.b.DependentId;
-import org.hibernate.test.annotations.derivedidentities.e1.b.Employee;
import org.hibernate.test.util.SchemaUtil;
/**
14 years, 12 months