You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Sean McDowell <Se...@ca.ibm.com> on 2017/10/24 16:44:46 UTC
Problem with delimiters and MySQL
Hi, I am having an issue with openjpa-2.2.3.
I have set the property: openjpa.jdbc.DBDictionary=mysql
This seems to be recognized as I see SQL queries going to the database
using the backtick quoting that the MySQLDictionary employs.
However, I eventually run into issues where a field like T1.`KEY_ID` is
not located:
Caused by: java.sql.SQLException: t1."KEY_ID"
at
org.apache.openjpa.jdbc.sql.SelectImpl$SelectResult.findObject(SelectImpl.java:2510)
at
org.apache.openjpa.jdbc.sql.ResultSetResult.translate(ResultSetResult.java:497)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.load(JDBCStoreManager.java:1059)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initializeState(JDBCStoreManager.java:411)
at
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.initialize(JDBCStoreManager.java:306)
Note that the key in the exception message uses double quotes -- this is
why the one with backticks is not found.
I was able to find where these double-quoted column names came from
(please excuse any weirdness in the names below, I had to use OCR from a
screenshot to get this stack due to Eclipse bug):
DefaultIdentifierConfiguration.getLeadingDelimiter() line: 55
DBIdentifierUtilImpl(IdentifierUtilImpl).isDelimited(IdentifierConfiguration,
IdentifierRuIe, String) line: 329
DBIdentifierUtilImpl(IdentifierUtilImpl).delimit(IdentifierConfiguration,
IdentifierRuIe, String, boolean) line: 315
DBIdentifierUtilImpl(IdentifierUtilImpl).delimit(1dentifierRuIe, String,
boolean) line: 307
Normalizer.delimit(String, boolean) line: 288
DBIdentifier.setName(String, boolean) line: 140
DBIdentifier.<init> (String, DBIdentifierSDBIdentifierType, boolean) line:
102
DBIdentifier.toArray(String[], DBIdentifierSDBIdentifierType, boolean)
line: 432
AnnotationPersistenceMappingParser.createUniqueConstraint(MetaDataContext,
UniqueConstraint) line: 543
AnnotationPersistenceMappingParser.addUniqueConstraints(String,
MetaDataContext, MappingInfo, UniqueConstraint...) line: 562
AnnotationPersistenceMappingParser.parseTabIe(ClassMapping, Table) line:
535
AnnotationPersistenceMappingParser.parseClassMappingAnnotations(ClassMetaData)
line: 350
AnnotationPersistenceMappingParser(AnnotationPersistenceMetaDataParser).parseClassAnnotationsO
line: 697
AnnotationPersistenceMappingParser(AnnotationPersistenceMetaDataParser).parse(Class<?>)
line: 415
PersistenceMappingFactory(PersistenceMetaDataFactory).Ioad(Class<?>, int,
ClassLoader) line: 260
MappingRepository(MetaDataRepository).getMetaDataInternal(Class<?>,
ClassLoader) line: 586
MappingRepository(MetaDataRepository).getMetaDataInternal(Class ?>,
ClassLoader, boolean) line: 396
MappingRepository(MetaDataRepository).getMetaData(Class< ?>, ClassLoader,
boolean) line: 388
VaIueMappingImpIWalueMetaDataImpl).resolveDecIaredType(Class) line: 491
VaIueMappingImpIWalueMetaDataImpl).resolve(int) line: 470
VaIueMappingIran.resoIve(int) line: 508
FieldMapping(FieldMetaData).resolve(int) line: 1883
FieldMapping.resolve(int) line: 460
ClassMapping(ClassMetaData).resolveMeta(booIean) line: 1874
ClassMapping(ClassMetaData).resolve(int) line: 1808
MappingRepository(MetaDataRepository).processBuffer(ClassMetaData,
List<ClassMetaData>, int) line: 828
MappingRepository(MetaDataRepository).resolveMeta(ClassMetaData) line: 725
MappingRepository(MetaDataRepository).resolve(ClassMetaData) line: 649
MappingRepository(MetaDataRepository).getMetaDataInternaI(Class< ?>,
ClassLoader, boolean) line: 417
MappingRepository(MetaDataRepository).getMetaData(Class< ?>, ClassLoader,
boolean) line: 388
PCEnhancer.<init>(OpenJPAConfiguration, BCClass, MetaDataRepository,
ClassLoader) line: 286
PCEnhancer.<init>(OpenJPAConfiguration, BCClass, MetaDataRepository) line:
257
PCClassFiIeTransformer.transformo(String, Class, bytell) line: 146
PCClassFiIeTransformer.transform(ClassLoader, String, Class,
ProtectionDornain, bytell) line: 126
PersistenceProviderImplSClassTransformerIran.transform(ClassLoader,
String, Class< ?>, ProtectionDomain, bytell) line: 292
OSGiJPAPUnitInfo(JPAPUnitInfo).transformClass(String, bytel], CodeSource,
ClassLoader) line: 1426
ClassLoadingServiceIranSClassFiIeTransformerAdapter.transform(ClassLoader,
String, Class< ?>, ProtectionDomain, bytell) line: 278
AppClassLoader.findClass(String) line: 289
In the DBIdentifier.java class it uses the static Normalizer to delimit
names:
/**
* Set the name of the identifier and optionally force delimiting of
the identifier.
*/
public void setName(String name, boolean delimit) {
assertNotNull();
// Normalize the name, if necessary. Do not normalize constants
or column definitions.
if (DBIdentifierType.CONSTANT != getType() && DBIdentifierType.
COLUMN_DEFINITION != getType()) {
if (delimit) {
name = Normalizer.delimit(name, true);
} else {
name = Normalizer.normalizeString(name);
}
}
super.setName(name);
}
And that Normalizer uses a DefaultIdentifierConfiguration instance which
has double-quote for leading and trailing identifier.
Is this a bug? Is there some configuration I am missing? Any guidance is
appreciated.