[hibernate-issues] [Hibernate-JIRA] Created: (HHH-2022) ORA-00911: invalid character when field begins with underscore

Jerry Cattell (JIRA) noreply at atlassian.com
Tue Aug 22 02:16:19 EDT 2006


ORA-00911: invalid character when field begins with underscore
--------------------------------------------------------------

         Key: HHH-2022
         URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2022
     Project: Hibernate3
        Type: Bug

  Components: core  
    Versions: 3.0.5, 3.1.3, 3.2.0.cr3    
 Environment: Hibernate 3.1.3
Oracle 10.2.0.1
    Reporter: Jerry Cattell
    Priority: Minor
 Attachments: InvalidCharacterErrorCase.java, SimpleObject.hbm.xml, SimpleObject.java

Hibernate is generating invalid SQL (for Oracle) for collections that are stored in fields with names that start with underscores.

In this SQL:
Hibernate: select _tags0_.SIMPLE_OBJECT_ID as SIMPLE1_0_, _tags0_.TAG as TAG0_ from SIMPLE_OBJECT_TAG _tags0_ where _tags0_.SIMPLE_OBJECT_ID=?

an alias called "_tags0_" is created for the collection table.  Unfortunately, Oracle does not allow non-alphabetic characters for the first character in an alias.

Here's the stacktrace:
Hibernate: select _tags0_.SIMPLE_OBJECT_ID as SIMPLE1_0_, _tags0_.TAG as TAG0_ from SIMPLE_OBJECT_TAG _tags0_ where _tags0_.SIMPLE_OBJECT_ID=?
WARN JDBCExceptionReporter 20060822-011120.817 - SQL Error: 911, SQLState: 42000
ERROR JDBCExceptionReporter 20060822-011120.818 - ORA-00911: invalid character

INFO DefaultLoadEventListener 20060822-011120.820 - Error performing load command
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [SimpleObject._tags#1]
	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
	at org.hibernate.loader.Loader.loadCollection(Loader.java:1926)
	at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)
	at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:520)
	at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
	at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1676)
	at org.hibernate.collection.AbstractPersistentCollection.forceInitialization(AbstractPersistentCollection.java:454)
	at org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(StatefulPersistenceContext.java:755)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:229)
	at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
	at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
	at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
	at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
	at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
	at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
	at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:161)
	at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
	at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
	at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
	at InvalidCharacterErrorCase.runTest(InvalidCharacterErrorCase.java:28)
	at InvalidCharacterErrorCase.main(InvalidCharacterErrorCase.java:11)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.sql.SQLException: ORA-00911: invalid character

	at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
	at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
	at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1039)
	at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1132)
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
	at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
	at org.hibernate.loader.Loader.doQuery(Loader.java:662)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
	at org.hibernate.loader.Loader.loadCollection(Loader.java:1919)
	... 26 more

I have attached a test case that causes this error.

After a little bit of research, it appears that a change to StringHelper.generateAlias(String description, int unique) (or StringHelper.generateAliasRoot(String description)) to remove all characters up to the first alphabetic character would solve this problem. 



-- 
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