Author: epbernard
Date: 2006-11-29 10:17:28 -0500 (Wed, 29 Nov 2006)
New Revision: 10879
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Component.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Product.java
Modified:
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/DenormalizedTable.java
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/TablePerClassTest.java
Log:
ANN-473 unique constraint on TABLE_PER_CLASS
Modified: branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/DenormalizedTable.java
===================================================================
---
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/DenormalizedTable.java 2006-11-29
15:16:32 UTC (rev 10878)
+++
branches/Branch_3_2/Hibernate3/src/org/hibernate/mapping/DenormalizedTable.java 2006-11-29
15:17:28 UTC (rev 10879)
@@ -34,6 +34,16 @@
}
}
+ public Column getColumn(Column column) {
+ Column superColumn = super.getColumn( column );
+ if (superColumn != null) {
+ return superColumn;
+ }
+ else {
+ return includedTable.getColumn( column );
+ }
+ }
+
public Iterator getColumnIterator() {
return new JoinedIterator(
includedTable.getColumnIterator(),
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Component.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Component.java 2006-11-29
15:16:32 UTC (rev 10878)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Component.java 2006-11-29
15:17:28 UTC (rev 10879)
@@ -0,0 +1,56 @@
+//$Id: $
+package org.hibernate.test.annotations.tableperclass;
+
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.Entity;
+import javax.persistence.InheritanceType;
+
+import org.hibernate.validator.NotNull;
+import org.hibernate.validator.Length;
+import org.hibernate.annotations.Index;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity(name = "xpmComponent")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+public abstract class Component {
+ private String manufacturerPartNumber;
+ private Long manufacturerId;
+ private Long id;
+
+
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+
+ @Id
+ public Long getId() {
+ return id;
+ }
+
+
+ @NotNull
+ @Length(max = 40)
+ @Index(name = "manufacturerPartNumber")
+ public String getManufacturerPartNumber() {
+ return manufacturerPartNumber;
+ }
+
+ @NotNull
+ public Long getManufacturerId() {
+ return manufacturerId;
+ }
+
+ public void setManufacturerId(Long manufacturerId) {
+ this.manufacturerId = manufacturerId;
+ }
+
+
+ public void setManufacturerPartNumber(String manufacturerPartNumber) {
+ this.manufacturerPartNumber = manufacturerPartNumber;
+ }
+}
\ No newline at end of file
Added:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Product.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Product.java 2006-11-29
15:16:32 UTC (rev 10878)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/Product.java 2006-11-29
15:17:28 UTC (rev 10879)
@@ -0,0 +1,15 @@
+//$Id: $
+package org.hibernate.test.annotations.tableperclass;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import javax.persistence.UniqueConstraint;
+
+/**
+ * @author Emmanuel Bernard
+ */
+@Entity
+@Table( name = "xPM_Product", uniqueConstraints = {@UniqueConstraint(
columnNames = {
+ "manufacturerPartNumber", "manufacturerId"} )} )
+public class Product extends Component {
+}
Modified:
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/TablePerClassTest.java
===================================================================
---
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/TablePerClassTest.java 2006-11-29
15:16:32 UTC (rev 10878)
+++
branches/Branch_3_2/HibernateExt/metadata/src/test/org/hibernate/test/annotations/tableperclass/TablePerClassTest.java 2006-11-29
15:17:28 UTC (rev 10879)
@@ -2,10 +2,12 @@
package org.hibernate.test.annotations.tableperclass;
import java.util.List;
+import java.sql.SQLException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.JDBCException;
import org.hibernate.test.annotations.TestCase;
/**
@@ -45,6 +47,33 @@
s.close();
}
+ public void testConstraintsOnSuperclassProperties() throws Exception {
+ Session s = openSession();
+ Transaction tx = s.beginTransaction();
+ Product product1 = new Product();
+ product1.setId( 1l );
+ product1.setManufacturerId( 1l );
+ product1.setManufacturerPartNumber( "AAFR");
+ s.persist( product1 );
+ s.flush();
+ Product product2 = new Product();
+ product2.setId( 2l );
+ product2.setManufacturerId( 1l );
+ product2.setManufacturerPartNumber( "AAFR");
+ s.persist( product2 );
+ try {
+ s.flush();
+ fail("Database Exception not handled");
+ }
+ catch( JDBCException e ) {
+ //success
+ }
+ tx.rollback();
+ s.close();
+ }
+
+
+
public TablePerClassTest(String x) {
super( x ); //To change body of overridden methods use File | Settings | File
Templates.
}
@@ -53,7 +82,9 @@
return new Class[]{
Robot.class,
T800.class,
- Machine.class
+ Machine.class,
+ Component.class,
+ Product.class
};
}
}
Show replies by date