Consultor Eletrônico



Kbase P124330: Hibernate and Referential Integrity
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   8/15/2007
Status: Unverified

GOAL:

How to implement Referential Integrity with Hibernate.

GOAL:

How to customize Hibernate to generate foreign keys integrity

GOAL:

Hibernate 3.x

FACT(s) (Environment):

OpenEdge 10.x
All Supported Operating Systems

FIX:

Hibernate 3.2 offers a class named ProgressDialect, which is used to generate specific SQL for Progress Database.
This class was develop previous to version 10, and so, does not generate information about foreign keys when generating the schema.
In order to produce the correct SQL for foreign keys, developers should implement a new class (copy or extend the original ProgressDialect) and implement the following methods:
....public boolean hasAlterTable(){
return true;
}
public String getAddForeignKeyConstraintString(
String constraintName,
String[] foreignKey,
String referencedTable,
String[] primaryKey, boolean referencesPrimaryKey
) {
String cols = StringHelper.join(", ", foreignKey);
return new StringBuffer(30)
.append(" add constraint ")
.append(constraintName)
.append(" foreign key (")
.append(cols)
.append(") references ")
.append(referencedTable)
.append(" (")
.append( StringHelper.join(", ", primaryKey) )
.append(')')
.toString();

}