[hibernate-commits] Hibernate SVN: r12761 - trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jul 12 18:53:23 EDT 2007


Author: epbernard
Date: 2007-07-12 18:53:23 -0400 (Thu, 12 Jul 2007)
New Revision: 12761

Added:
   trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/Gardenshed.java
Modified:
   trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/AccessTest.java
Log:
ANN-618 more access test

Modified: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/AccessTest.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/AccessTest.java	2007-07-12 20:21:25 UTC (rev 12760)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/AccessTest.java	2007-07-12 22:53:23 UTC (rev 12761)
@@ -98,12 +98,31 @@
 
 	}
 
+	public void testFieldsOverriding() throws Exception {
+		Gardenshed gs = new Gardenshed();
+		gs.floors = 4;
+		Session s = openSession();
+		s.persist( gs );
+		Transaction tx = s.beginTransaction();
+		tx.commit();
+		s.clear();
+		tx = s.beginTransaction();
+		gs = (Gardenshed) s.get( Gardenshed.class, gs.getId() );
+		assertEquals( 4, gs.floors );
+		assertEquals( 6, gs.getFloors() );
+		s.delete( gs );
+		tx.commit();
+		s.close();
+
+	}
+
 	protected Class[] getMappings() {
 		return new Class[]{
 				Bed.class,
 				Chair.class,
 				Furniture.class,
-				BigBed.class
+				BigBed.class,
+				Gardenshed.class
 		};
 	}
 }

Added: trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/Gardenshed.java
===================================================================
--- trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/Gardenshed.java	                        (rev 0)
+++ trunk/HibernateExt/annotations/src/test/org/hibernate/test/annotations/access/Gardenshed.java	2007-07-12 22:53:23 UTC (rev 12761)
@@ -0,0 +1,55 @@
+//$Id: Furniture.java 9795 2006-04-26 06:41:18Z epbernard $
+package org.hibernate.test.annotations.access;
+
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Transient;
+
+import org.hibernate.annotations.AccessType;
+
+/**
+ * This is the opposite of the Furniture test, as this tries to override the class AccessType("property") with
+ * the property AccessType("field").
+ *
+ * @author Dennis Fleurbaaij
+ * @since 2007-05-31
+ */
+ at Entity
+ at AccessType( "property" )
+public class Gardenshed
+		extends
+		Woody {
+	private Integer id;
+	private String brand;
+	public long floors;
+
+	@Transient
+	public String getBrand() {
+		return brand;
+	}
+
+	public void setBrand(String brand) {
+		this.brand = brand;
+	}
+
+	@Id
+	@GeneratedValue
+	public Integer getId() {
+		return id;
+	}
+
+	public void setId(Integer id) {
+		this.id = id;
+	}
+
+	// These 2 functions should not return in Hibernate, but the value should come from the field "floors"
+	@AccessType( "field" )
+	public long getFloors() {
+		return this.floors + 2;
+	}
+
+	public void setFloors(long floors) {
+		this.floors = floors + 2;
+	}
+}
\ No newline at end of file




More information about the hibernate-commits mailing list