[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4553) Hibernate doesn't support official JPA2 escape char for table name
Steve Ebersole (JIRA)
noreply at atlassian.com
Wed Nov 25 13:22:08 EST 2009
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4553?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=34762#action_34762 ]
Steve Ebersole commented on HHH-4553:
-------------------------------------
IMO, the most correct psuedo-logic here is:
{code}
String objectName = [getExplicitName];
// apply naming strategy
if ( objectName == null ) {
// No explicit name given, so allow the naming strategy the chance
// to determine it based on the corresponding mapped java name
objectName = namingStrategy.[determineDatabaseObjectNameBasedOnMappedJavaName];
// Conceivable that the naming strategy could return a quoted identifier, or
// that user enabled <delimited-identifiers/>
objectName = normalizeQuotedIdentifier( objectName );
}
else {
// An explicit name was given:
// in some cases we allow the naming strategy to "fine tune" these, but first
// handle any quoting for consistent handling in naming strategies
objectName = normalizeQuotedIdentifier( objectName );
objectName = namingStrategy.[fineTuneExplicitName];
objectName = normalizeQuotedIdentifier( objectName );
}
private String normalizeQuotedIdentifier(String identifier) {
if ( identifier != null
&& identifier.startsWith( "\"" )
&& identifier.endsWith( "\"" ) ) {
return '`' + identifier.substring( 1, identifier.length() - 1 ) + '`';
}
if ( identifier != null && useQuotedIdentifiersGlobally
&& ! ( identifier.startsWith( "`" ) && identifier.endsWith( "`" ) ) {
return '`' + identifier + '`';
}
return identifier;
}
{code}
> Hibernate doesn't support official JPA2 escape char for table name
> ------------------------------------------------------------------
>
> Key: HHH-4553
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4553
> Project: Hibernate Core
> Issue Type: Sub-task
> Affects Versions: 3.5.0-Beta-2
> Environment: Oracle 9i
> Derby
> Reporter: Julien HENRY
> Assignee: Steve Ebersole
> Fix For: 3.5
>
>
> One of the table of my schema is named FUNCTION. As it is a reserved name with Derby (used for my JUnit tests), I have escaped the table name to make it works with Derby (as specified by JPA2 spec $2.13):
> @Entity
> @Table(name="\"FUNCTION\"")
> public class Function {
> //...
> }
> My JUnit tests are working fine, then I tried to connect to my Oracle DB, and I have enabled schema validation:
> <property name="hibernate.hbm2ddl.auto" value="validate"/>
> But I got an exception as Hibernate is looking for a table with name "FUNCTION" in Oracle metadata.
> Caused by: org.hibernate.HibernateException: Missing table: "FUNCTION"
> at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1153) [hibernate-core-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139) [hibernate-core-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:364) [hibernate-core-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1367) [hibernate-core-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:858) [hibernate-annotations-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:733) [hibernate-entitymanager-3.5.0-Beta-2.jar:3.5.0-Beta-2]
> This is not specific to Oracle, because when I change:
> <property name="hibernate.hbm2ddl.auto" value="create"/>
> by
> <property name="hibernate.hbm2ddl.auto" value="validate"/>
> in my JUnit tests, I have the same issue with the embedded Derby DB.
> Using Hibernate specific ` as quote works fine:
> @Entity
> @Table(name="`FUNCTION`")
> public class Function {
> //...
> }
> The issue can be easily fixed in Table.setName(String name). Replace:
> if ( name.charAt( 0 ) == '`' ) {
> by
> if ( name.charAt( 0 ) == '"' ) {
> or if you want to keep backward compatibility:
> if ( name.charAt( 0 ) == '`' || name.charAt( 0 ) == '"' ) {
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list