mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-13 14:44:48 +00:00
Revert "HHH-8783 use JPA @JoinColumn(@ForeignKey(name=...)) for constraint name"
This reverts commit cd83193875273345ad79b507616a8b3e15c69974.
This commit is contained in:
parent
cd83193875
commit
7bb9fc1e82
@ -2634,8 +2634,6 @@ private static void bindManyToOne(
|
||||
column.setUpdatable( false );
|
||||
}
|
||||
}
|
||||
|
||||
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
|
||||
|
||||
//Make sure that JPA1 key-many-to-one columns are read only tooj
|
||||
boolean hasSpecjManyToOne=false;
|
||||
@ -2647,6 +2645,7 @@ private static void bindManyToOne(
|
||||
columnName = prop.getAnnotation( Column.class ).name();
|
||||
}
|
||||
|
||||
final JoinColumn joinColumn = property.getAnnotation( JoinColumn.class );
|
||||
if ( property.isAnnotationPresent( ManyToOne.class ) && joinColumn != null
|
||||
&& ! BinderHelper.isEmptyAnnotationValue( joinColumn.name() )
|
||||
&& joinColumn.name().equals( columnName )
|
||||
@ -2663,15 +2662,11 @@ private static void bindManyToOne(
|
||||
value.setTypeName( inferredData.getClassOrElementName() );
|
||||
final String propertyName = inferredData.getPropertyName();
|
||||
value.setTypeUsingReflection( propertyHolder.getClassName(), propertyName );
|
||||
|
||||
String fkName = null;
|
||||
if ( joinColumn != null && joinColumn.foreignKey() != null ) {
|
||||
fkName = joinColumn.foreignKey().name();
|
||||
}
|
||||
if ( BinderHelper.isEmptyAnnotationValue( fkName ) ) {
|
||||
ForeignKey fk = property.getAnnotation( ForeignKey.class );
|
||||
fkName = fk != null ? fk.name() : "";
|
||||
}
|
||||
|
||||
ForeignKey fk = property.getAnnotation( ForeignKey.class );
|
||||
String fkName = fk != null ?
|
||||
fk.name() :
|
||||
"";
|
||||
if ( !BinderHelper.isEmptyAnnotationValue( fkName ) ) {
|
||||
value.setForeignKeyName( fkName );
|
||||
}
|
||||
|
@ -29,7 +29,6 @@
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
@ -41,16 +40,11 @@
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Brett Meyer
|
||||
*/
|
||||
public class ConstraintTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
private static final int MAX_NAME_LENGTH = 30;
|
||||
|
||||
private static final String EXPLICIT_FK_NAME_NATIVE = "fk_explicit_native";
|
||||
|
||||
private static final String EXPLICIT_FK_NAME_JPA = "fk_explicit_jpa";
|
||||
private static final String EXPLICIT_FK_NAME = "fk_explicit";
|
||||
|
||||
private static final String EXPLICIT_UK_NAME = "uk_explicit";
|
||||
|
||||
@ -84,7 +78,6 @@ public void testUniqueConstraints() {
|
||||
@TestForIssue( jiraKey = "HHH-1904" )
|
||||
public void testConstraintNameLength() {
|
||||
Iterator<org.hibernate.mapping.Table> tableItr = configuration().getTableMappings();
|
||||
int foundCount = 0;
|
||||
while (tableItr.hasNext()) {
|
||||
org.hibernate.mapping.Table table = tableItr.next();
|
||||
|
||||
@ -96,13 +89,8 @@ public void testConstraintNameLength() {
|
||||
// ensure the randomly generated constraint name doesn't
|
||||
// happen if explicitly given
|
||||
Column column = fk.getColumn( 0 );
|
||||
if ( column.getName().equals( "explicit_native" ) ) {
|
||||
foundCount++;
|
||||
assertEquals( fk.getName(), EXPLICIT_FK_NAME_NATIVE );
|
||||
}
|
||||
else if ( column.getName().equals( "explicit_jpa" ) ) {
|
||||
foundCount++;
|
||||
assertEquals( fk.getName(), EXPLICIT_FK_NAME_JPA );
|
||||
if ( column.getName().equals( "explicit" ) ) {
|
||||
assertEquals( fk.getName(), EXPLICIT_FK_NAME );
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,13 +103,10 @@ else if ( column.getName().equals( "explicit_jpa" ) ) {
|
||||
// happen if explicitly given
|
||||
Column column = uk.getColumn( 0 );
|
||||
if ( column.getName().equals( "explicit" ) ) {
|
||||
foundCount++;
|
||||
assertEquals( uk.getName(), EXPLICIT_UK_NAME );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Could not find the necessary columns.", 3, foundCount);
|
||||
}
|
||||
|
||||
@Entity
|
||||
@ -154,12 +139,7 @@ public static class DataPoint2 {
|
||||
public DataPoint dp;
|
||||
|
||||
@OneToOne
|
||||
@org.hibernate.annotations.ForeignKey(name = EXPLICIT_FK_NAME_NATIVE)
|
||||
@JoinColumn(name = "explicit_native")
|
||||
public DataPoint explicit_native;
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "explicit_jpa", foreignKey = @javax.persistence.ForeignKey(name = EXPLICIT_FK_NAME_JPA))
|
||||
public DataPoint explicit_jpa;
|
||||
@org.hibernate.annotations.ForeignKey(name = EXPLICIT_FK_NAME)
|
||||
public DataPoint explicit;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user