Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORA-00972: identifier is too long. Oracle 12.1.0.2.0 #1483

Closed
davidbasilashvili opened this issue Mar 31, 2022 · 1 comment
Closed

ORA-00972: identifier is too long. Oracle 12.1.0.2.0 #1483

davidbasilashvili opened this issue Mar 31, 2022 · 1 comment

Comments

@davidbasilashvili
Copy link

Hi everyone,

I'm trying to create reference and facing to identifier limitation in Oracle 12.1.0.2.0.

Seems like expected behaviour: Exposed trim long id to supported length in current database version.
Actual behaviour: on Oracle 12.1.0.2.0 Exposed doesn't trim long ids to 30 digit ids

Regarding documentation long ids introduced in 12.2 Oracle release: Long Identifiers in Oracle Database 12c Release 2 (12.2)

The same issue was fixed in #654, but for Oracle 11.

Regarding actual code we can go from reference creation:
val refColumn: Column<Long> = reference(name = "reference_name", refColumn = referenceColumn) regarding actual code we have:

fun <T : Comparable<T>> reference(
name: String,
refColumn: Column<T>,
onDelete: ReferenceOption? = null,
onUpdate: ReferenceOption? = null,
fkName: String? = null
): Column<T> {
val column = Column<T>(this, name, refColumn.columnType.cloneAsBaseType()).references(refColumn, onDelete, onUpdate, fkName)
_columns.addColumn(column)
return column
}

And next fkName go to ForeignKeyConstraint as name:

fun <T : Comparable<T>, S : T, C : Column<S>> C.references(
ref: Column<T>,
onDelete: ReferenceOption? = null,
onUpdate: ReferenceOption? = null,
fkName: String? = null
): C = apply {
this.foreignKey = ForeignKeyConstraint(
target = ref,
from = this,
onUpdate = onUpdate,
onDelete = onDelete,
name = fkName
)
}

And next we can see how fkName should created:

val fkName: String
get() = tx.db.identifierManager.cutIfNecessaryAndQuote(
name ?: "fk_${fromTable.tableNameWithoutScheme}_${from.joinToString("_") { it.name }}__${target.joinToString("_") { it.name }}"
).inProperCase()

And cutting code here, you can see that it depends on identifierLengthLimit:

fun cutIfNecessaryAndQuote(identity: String) = quoteIfNecessary(identity.take(identifierLengthLimit))

And limit init found here:

protected enum class OracleVersion { Oracle11g, Oracle12plus, NonOracle }
protected val identifierLengthLimit by lazy {
when (oracleVersion) {
OracleVersion.Oracle11g -> 30
OracleVersion.Oracle12plus -> 128
else -> maxColumnNameLength.takeIf { it > 0 } ?: Int.MAX_VALUE
}
}

Seems like there is no case for oracle version later 11g but before 12.2.

Workaround: put fk name explicitly in reference method like val refColumn: Column<Long> = reference(name = "reference_name", refColumn = referenceColumn, fkName = "fk_constraint_name")
but for big codebase it can be overkill.

Could you please advise another workaround if possible or fix it somehow?

Many thanks!

@Tapac
Copy link
Contributor

Tapac commented Apr 16, 2022

Will be fixed in 0.38.2

@Tapac Tapac closed this as completed Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants