Author: epbernard
Date: 2010-01-20 06:48:08 -0500 (Wed, 20 Jan 2010)
New Revision: 18586
Modified:
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
Log:
HHH-4529 FK constraint is now generated
Modified: core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-19
22:16:05 UTC (rev 18585)
+++
core/trunk/annotations/src/main/java/org/hibernate/cfg/AnnotationBinder.java 2010-01-20
11:48:08 UTC (rev 18586)
@@ -1414,10 +1414,12 @@
joinColumn.setSecondaryTableName( join.getTable().getName() );
}
}
+ //MapsId means the columns belong to the pk => not null
+ final boolean mandatory = !ann.optional() || property.isAnnotationPresent(
MapsId.class );
bindOneToOne(
getCascadeStrategy( ann.cascade(), hibernateCascade, ann.orphanRemoval()),
joinColumns,
- ann.optional(),
+ !mandatory,
getFetchMode( ann.fetch() ),
ignoreNotFound, onDeleteCascade,
mappings.getReflectionManager().toXClass( ann.targetEntity() ),
@@ -2088,6 +2090,7 @@
RootClass rootClass = (RootClass) persistentClass;
String persistentClassName = rootClass.getClassName();
SimpleValue id;
+ final String propertyName = inferredData.getPropertyName();
if ( isComposite ) {
id = fillComponent(
propertyHolder, inferredData, baseInferredData, propertyAccessor,
@@ -2126,7 +2129,7 @@
column.forceNotNull(); //this is an id
}
SimpleValueBinder value = new SimpleValueBinder();
- value.setPropertyName( inferredData.getPropertyName() );
+ value.setPropertyName( propertyName );
value.setReturnedClassName( inferredData.getTypeName() );
value.setColumns( columns );
value.setPersistentClassName( persistentClassName );
@@ -2141,7 +2144,7 @@
}
else {
PropertyBinder binder = new PropertyBinder();
- binder.setName( inferredData.getPropertyName() );
+ binder.setName( propertyName );
binder.setValue( id );
binder.setAccessType( inferredData.getDefaultAccess() );
binder.setProperty( inferredData.getProperty() );
@@ -2220,7 +2223,7 @@
String path = propertyHolder.getPath() + "." + propertyName;
FkSecondPass secondPass = new ToOneFkSecondPass(
value, columns,
- !optional && unique, //cannot have nullabe and unique on certain DBs like
Derby
+ !optional && unique, //cannot have nullable and unique on certain DBs like
Derby
propertyHolder.getEntityOwnerClassName(),
path, mappings
);
@@ -2328,15 +2331,20 @@
Iterator idColumns = identifier.getColumnIterator();
List<String> idColumnNames = new ArrayList<String>();
org.hibernate.mapping.Column currentColumn;
- while ( idColumns.hasNext() ) {
- currentColumn = (org.hibernate.mapping.Column) idColumns.next();
- idColumnNames.add( currentColumn.getName() );
+ if ( identifier.getColumnSpan() != joinColumns.length ) {
+ mapToPK = false;
}
- for (Ejb3JoinColumn col : joinColumns) {
- if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
- mapToPK = false;
- break;
+ else {
+ while ( idColumns.hasNext() ) {
+ currentColumn = (org.hibernate.mapping.Column) idColumns.next();
+ idColumnNames.add( currentColumn.getName() );
}
+ for (Ejb3JoinColumn col : joinColumns) {
+ if ( !idColumnNames.contains( col.getMappingColumn().getName() ) ) {
+ mapToPK = false;
+ break;
+ }
+ }
}
}
}
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-19
22:16:05 UTC (rev 18585)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/DerivedIdentitySimpleParentSimpleDepTest.java 2010-01-20
11:48:08 UTC (rev 18586)
@@ -1,5 +1,7 @@
package org.hibernate.test.annotations.derivedidentities.e4.a;
+import java.util.Date;
+
import org.hibernate.Session;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.util.SchemaUtil;
@@ -25,6 +27,11 @@
s.clear();
d = (MedicalHistory) s.get( MedicalHistory.class, d.id );
assertEquals( d.id, d.patient.ssn );
+ d.lastupdate = new Date();
+ s.flush();
+ s.clear();
+ d = (MedicalHistory) s.get( MedicalHistory.class, d.id );
+ assertNotNull( d.lastupdate );
s.getTransaction().rollback();
s.close();
}
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java
===================================================================
---
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-19
22:16:05 UTC (rev 18585)
+++
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/derivedidentities/e4/a/MedicalHistory.java 2010-01-20
11:48:08 UTC (rev 18586)
@@ -1,18 +1,24 @@
package org.hibernate.test.annotations.derivedidentities.e4.a;
+import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToOne;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
/**
* @author Emmanuel Bernard
*/
@Entity
public class MedicalHistory {
- @Id
- String id; // overriding not allowed ... // default join column name is overridden
@MapsId
+
+ @Id String id; // overriding not allowed ... // default join column name is overridden
@MapsId
+ @Temporal(TemporalType.DATE)
+ Date lastupdate;
+
@JoinColumn(name = "FK")
@MapsId
@OneToOne
Show replies by date