Author: epbernard
Date: 2007-07-03 12:26:31 -0400 (Tue, 03 Jul 2007)
New Revision: 12666
Added:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/Show.java
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/ShowDescription.java
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java
Log:
ANN-613 Fail properly when mappedBy is wrong
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2007-07-03
15:20:03 UTC (rev 12665)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/OneToOneSecondPass.java 2007-07-03
16:26:31 UTC (rev 12666)
@@ -132,6 +132,13 @@
+ StringHelper.qualify( value.getReferencedEntityName(), mappedBy )
);
}
+ if (otherSideProperty == null) {
+ throw new AnnotationException(
+ "Unknown mappedBy in: " + StringHelper.qualify( ownerEntity,
ownerProperty )
+ + ", referenced property unknown: "
+ + StringHelper.qualify( value.getReferencedEntityName(), mappedBy )
+ );
+ }
if ( otherSideProperty.getValue() instanceof OneToOne ) {
propertyHolder.addProperty( prop );
}
Added:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java
(rev 0)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/OneToOneErrorTest.java 2007-07-03
16:26:31 UTC (rev 12666)
@@ -0,0 +1,27 @@
+//$Id$
+package org.hibernate.test.annotations.onetoone;
+
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Environment;
+import org.hibernate.test.annotations.IncorrectEntity;
+import org.hibernate.SessionFactory;
+import org.hibernate.AnnotationException;
+
+/**
+ * @author Emmanuel Bernard
+ */
+public class OneToOneErrorTest extends junit.framework.TestCase {
+ public void testWrongOneToOne() throws Exception {
+ AnnotationConfiguration cfg = new AnnotationConfiguration();
+ cfg.addAnnotatedClass( Show.class )
+ .addAnnotatedClass( ShowDescription.class );
+ cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
+ try {
+ SessionFactory sf = cfg.buildSessionFactory();
+ fail( "Wrong mappedBy does not fail property" );
+ }
+ catch (AnnotationException e) {
+ //success
+ }
+ }
+}
\ No newline at end of file
Added:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/Show.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/Show.java
(rev 0)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/Show.java 2007-07-03
16:26:31 UTC (rev 12666)
@@ -0,0 +1,33 @@
+//$Id$
+package org.hibernate.test.annotations.onetoone;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Show {
+ @Id
+ private Integer id;
+ @OneToOne() private ShowDescription description;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public ShowDescription getDescription() {
+ return description;
+ }
+
+ public void setDescription(ShowDescription description) {
+ this.description = description;
+ }
+}
Added:
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/ShowDescription.java
===================================================================
---
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/ShowDescription.java
(rev 0)
+++
trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/onetoone/ShowDescription.java 2007-07-03
16:26:31 UTC (rev 12666)
@@ -0,0 +1,34 @@
+//$Id$
+package org.hibernate.test.annotations.onetoone;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class ShowDescription {
+ @Id
+ private Integer id;
+ @OneToOne(mappedBy = "wrongProperty")
+ private Show show;
+
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public Show getShow() {
+ return show;
+ }
+
+ public void setShow(Show show) {
+ this.show = show;
+ }
+}
Show replies by date