Author: epbernard
Date: 2006-11-29 09:19:45 -0500 (Wed, 29 Nov 2006)
New Revision: 10876
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Frame.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java
Log:
ANN-477 formula interfere with many to one property-ref
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2006-11-29
14:11:32 UTC (rev 10875)
+++
branches/Branch_3_2/HibernateExt/metadata/src/java/org/hibernate/cfg/BinderHelper.java 2006-11-29
14:19:45 UTC (rev 10876)
@@ -213,9 +213,9 @@
);
}
//build the list of column names
- for ( int index = 0; index < columns.length ; index++ ) {
+ for ( Ejb3JoinColumn column1 : columns ) {
Column column = new Column(
- mappings.getPhysicalColumnName( columns[index].getReferencedColumn(),
referencedTable )
+ mappings.getPhysicalColumnName( column1.getReferencedColumn(), referencedTable )
);
orderedColumns.add( column );
columnsToProperty.put( column, new HashSet<Property>() );
@@ -231,7 +231,8 @@
}
Iterator columnIt = property.getColumnIterator();
while ( columnIt.hasNext() ) {
- Column column = (Column) columnIt.next();
+ Object column = columnIt.next(); //can be a Formula so we don't cast
+ //noinspection SuspiciousMethodCalls
if ( columnsToProperty.containsKey( column ) ) {
columnsToProperty.get( column ).add( property );
}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Frame.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Frame.java 2006-11-29
14:11:32 UTC (rev 10875)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Frame.java 2006-11-29
14:19:45 UTC (rev 10876)
@@ -0,0 +1,52 @@
+//$Id: $
+package org.hibernate.test.annotations.manytoone;
+
+import java.util.Set;
+import java.io.Serializable;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.hibernate.annotations.Formula;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Frame implements Serializable {
+ @Id
+ @GeneratedValue
+ private Long id;
+ @OneToMany( mappedBy = "frame" )
+ private Set<Lens> lenses;
+ @Column( unique = true )
+ private String name;
+ @Formula("lower(name)")
+ private String lowerName;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public Set<Lens> getLenses() {
+ return lenses;
+ }
+
+ public void setLenses(Set<Lens> lenses) {
+ this.lenses = lenses;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java 2006-11-29
14:11:32 UTC (rev 10875)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/Lens.java 2006-11-29
14:19:45 UTC (rev 10876)
@@ -0,0 +1,58 @@
+//$Id: $
+package org.hibernate.test.annotations.manytoone;
+
+import javax.persistence.Entity;
+import javax.persistence.ManyToOne;
+import javax.persistence.JoinColumn;
+import javax.persistence.Id;
+import javax.persistence.GeneratedValue;
+
+import org.hibernate.annotations.Formula;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+public class Lens {
+ @Id
+ @GeneratedValue
+ private Long id;
+ private float focal;
+ @Formula("(1/focal)")
+ private float length;
+ @ManyToOne()
+ @JoinColumn(name="frame_fk", referencedColumnName = "name")
+ private Frame frame;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public float getFocal() {
+ return focal;
+ }
+
+ public void setFocal(float focal) {
+ this.focal = focal;
+ }
+
+ public float getLength() {
+ return length;
+ }
+
+ public void setLength(float length) {
+ this.length = length;
+ }
+
+ public Frame getFrame() {
+ return frame;
+ }
+
+ public void setFrame(Frame frame) {
+ this.frame = frame;
+ }
+}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java 2006-11-29
14:11:32 UTC (rev 10875)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/manytoone/ManyToOneTest.java 2006-11-29
14:19:45 UTC (rev 10876)
@@ -296,6 +296,30 @@
s.close();
}
+ public void testFormulaOnOtherSide() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Frame frame = new Frame();
+ frame.setName( "Prada" );
+ s.persist( frame );
+ Lens l = new Lens();
+ l.setFocal( 2.5f );
+ l.setFrame( frame );
+ s.persist( l );
+ Lens r = new Lens();
+ r.setFocal( 1.2f);
+ r.setFrame( frame );
+ s.persist( r );
+ s.flush();
+ s.clear();
+ frame = (Frame) s.get( Frame.class, frame.getId() );
+ assertEquals( 2, frame.getLenses().size() );
+ assertTrue( frame.getLenses().iterator().next().getLength() <= 1/1.2f );
+ assertTrue( frame.getLenses().iterator().next().getLength() >= 1/2.5f );
+ tx.rollback();
+ s.close();
+ }
+
/**
* @see org.hibernate.test.annotations.TestCase#getMappings()
*/
@@ -317,7 +341,9 @@
User.class,
DistrictUser.class,
Order.class,
- OrderLine.class
+ OrderLine.class,
+ Frame.class,
+ Lens.class
};
}
Show replies by date