[hibernate-commits] Hibernate SVN: r14785 - in annotations/trunk/src: test/org/hibernate/test/annotations/id and 1 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Jun 19 06:44:33 EDT 2008


Author: hardy.ferentschik
Date: 2008-06-19 06:44:33 -0400 (Thu, 19 Jun 2008)
New Revision: 14785

Added:
   annotations/trunk/src/test/org/hibernate/test/annotations/id/EnumIdTest.java
   annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/Planet.java
   annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java
Modified:
   annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
Log:
ANN-733
- Added test case
- Made sure that bindId() in AnnotationBinder calls SimpleValueBinder.setType() in order to set the column type to string resp. int. Before that was not done and hence the column type was some form of blob

Modified: annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
--- annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java	2008-06-19 10:42:20 UTC (rev 14784)
+++ annotations/trunk/src/java/org/hibernate/cfg/AnnotationBinder.java	2008-06-19 10:44:33 UTC (rev 14785)
@@ -715,7 +715,6 @@
 					isComponent,
 					propertyAnnotated,
 					propertyAccessor, entityBinder,
-					null,
 					true,
 					false, mappings
 			);
@@ -1276,7 +1275,7 @@
 					generatedValue.generator() :
 					BinderHelper.ANNOTATION_STRING_DEFAULT;
 			if ( isComponent ) generatorType = "assigned"; //a component must not have any generator
-			Type typeAnn = property.getAnnotation( Type.class );
+						
 			bindId(
 					generatorType,
 					generator,
@@ -1287,10 +1286,10 @@
 					isComponent,
 					propertyAnnotated,
 					propertyAccessor, entityBinder,
-					typeAnn,
 					false,
 					isIdentifierMapper, mappings
 			);
+						
 			log.debug(
 					"Bind {} on {}", ( isComponent ? "@EmbeddedId" : "@Id" ), inferredData.getPropertyName()
 			);
@@ -1850,7 +1849,7 @@
 			Map<String, IdGenerator> localGenerators,
 			boolean isComposite,
 			boolean isPropertyAnnotated,
-			String propertyAccessor, EntityBinder entityBinder, Type typeAnn, boolean isEmbedded,
+			String propertyAccessor, EntityBinder entityBinder, boolean isEmbedded,
 			boolean isIdentifierMapper, ExtendedMappings mappings
 	) {
 		/*
@@ -1895,7 +1894,7 @@
 			value.setColumns( columns );
 			value.setPersistentClassName( persistentClassName );
 			value.setMappings( mappings );
-			value.setExplicitType( typeAnn );
+			value.setType( inferredData.getProperty(), inferredData.getClassOrElement() );
 			id = value.make();
 		}
 		rootClass.setIdentifier( id );

Added: annotations/trunk/src/test/org/hibernate/test/annotations/id/EnumIdTest.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/id/EnumIdTest.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/id/EnumIdTest.java	2008-06-19 10:44:33 UTC (rev 14785)
@@ -0,0 +1,62 @@
+//$Id$
+package org.hibernate.test.annotations.id;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+import org.hibernate.test.annotations.TestCase;
+import org.hibernate.test.annotations.id.entities.Planet;
+import org.hibernate.test.annotations.id.entities.PlanetCheatSheet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Tests for enum type as id.
+ * 
+ * @author Hardy Ferentschik
+ * @see ANN-744
+ */
+ at SuppressWarnings("unchecked")
+public class EnumIdTest extends TestCase {
+
+	private Logger log = LoggerFactory.getLogger(EnumIdTest.class);	
+	
+	public EnumIdTest(String x) {
+		super(x);
+	}
+
+	public void testEnumAsId() throws Exception {
+		Session s = openSession();
+		Transaction tx = s.beginTransaction();
+		PlanetCheatSheet mercury = new PlanetCheatSheet();
+		mercury.setPlanet(Planet.MERCURY);
+		mercury.setMass(3.303e+23);
+		mercury.setRadius(2.4397e6);
+		mercury.setNumberOfInhabitants(0);
+		s.persist(mercury);
+		tx.commit();
+		s.close();
+
+		s = openSession();
+		tx = s.beginTransaction();
+		PlanetCheatSheet mercuryFromDb = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, mercury.getPlanet());
+		assertNotNull(mercuryFromDb);
+		log.debug(mercuryFromDb.toString());
+		s.delete(mercuryFromDb);
+		tx.commit();
+		s.close();
+		
+		s = openSession();
+		tx = s.beginTransaction();
+		mercury = (PlanetCheatSheet) s.get(PlanetCheatSheet.class, Planet.MERCURY);
+		assertNull(mercury);
+		tx.commit();
+		s.close();
+	}
+
+	/**
+	 * @see org.hibernate.test.annotations.TestCase#getMappings()
+	 */
+	protected Class[] getMappings() {
+		return new Class[] { PlanetCheatSheet.class };
+	}
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/id/EnumIdTest.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/Planet.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/Planet.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/Planet.java	2008-06-19 10:44:33 UTC (rev 14785)
@@ -0,0 +1,6 @@
+// $Id:$
+package org.hibernate.test.annotations.id.entities;
+
+public enum Planet {
+	MERCURY, VENUS, EARTH, MARS, JUPITER, SATURN, URANUS, NEPTUNE, PLUTO;
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/Planet.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java
===================================================================
--- annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java	                        (rev 0)
+++ annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java	2008-06-19 10:44:33 UTC (rev 14785)
@@ -0,0 +1,85 @@
+package org.hibernate.test.annotations.id.entities;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.Id;
+
+
+/**
+ * Test entity for enum type as id.
+ * 
+ * @author Hardy Ferentschik
+ * @see ANN-744
+ */
+ at Entity
+public class PlanetCheatSheet {
+
+	@Id
+	@Enumerated(EnumType.STRING)
+	@Column(name = "planet")
+	private Planet planet;
+
+	private double mass;
+
+	private double radius;
+
+	private long numberOfInhabitants;
+
+	public Planet getPlanet() {
+		return planet;
+	}
+
+	public void setPlanet(Planet planet) {
+		this.planet = planet;
+	}
+
+	public double getMass() {
+		return mass;
+	}
+
+	public void setMass(double mass) {
+		this.mass = mass;
+	}
+
+	public double getRadius() {
+		return radius;
+	}
+
+	public void setRadius(double radius) {
+		this.radius = radius;
+	}
+
+	public long getNumberOfInhabitants() {
+		return numberOfInhabitants;
+	}
+
+	public void setNumberOfInhabitants(long numberOfInhabitants) {
+		this.numberOfInhabitants = numberOfInhabitants;
+	}
+
+	/**
+	 * Constructs a <code>String</code> with all attributes
+	 * in name = value format.
+	 *
+	 * @return a <code>String</code> representation 
+	 * of this object.
+	 */
+	public String toString()
+	{
+	    final String TAB = "    ";
+	    
+	    String retValue = "";
+	    
+	    retValue = "PlanetCheatSheet ( "
+	        + super.toString() + TAB
+	        + "planet = " + this.planet + TAB
+	        + "mass = " + this.mass + TAB
+	        + "radius = " + this.radius + TAB
+	        + "numberOfInhabitants = " + this.numberOfInhabitants + TAB
+	        + " )";
+	
+	    return retValue;
+	}	
+}


Property changes on: annotations/trunk/src/test/org/hibernate/test/annotations/id/entities/PlanetCheatSheet.java
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native




More information about the hibernate-commits mailing list