I have the following problem. I have a class called AttachmentExtension which is used to give information about file extensions that are valid or not for file uploads. The property value is mapped directly to the column EXTENSION in the database. The text is something like, "doc" or "txt". What's happening is upon runtime, instead of mapping the EXTENSION column to value it maps the id instead. This is very strange behavior. What's even stanger is that the column isn't even selected (see below SQL) at all!
To top things off, I've written a unit test that tries to duplicate this problem against an in-memory database and off Oracle, and the problem does not occur! This seems to point to a difference between environments, but I don't see how Tomcat 5.0.9 could be affecting Hibernate at all (very common configuration). All deployed libraries in the war are the same as being used in the unit test. Any assitance is appreciated, but for now I'm going to try and upgrade to Hibernate 3.1 to see if the problem is fixed there.
Hibernate version: 3.0.5
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping>
<class name="com.netg.forums.entities.AttachmentExtension" table="EXTENSIONS" >
<id name="id" column="EXTENSION_ID" type="int">
<generator class="native">
<param name="sequence">EXTENSIONS_SEQ</param>
</generator>
</id>
<property name="value" column="EXTENSION" type="string" not-null="true"/>
<property name="allow" column="ALLOW" type="boolean" not-null="true"/>
<property name="comment" column="DESCRIPTION" type="string" not-null="false"/>
<many-to-one
name="attachmentExtensionGroup"
class="com.netg.forums.entities.AttachmentExtensionGroup"
column="EXTENSION_GROUP_ID"
not-null="true" />
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Using Spring Templates:
public List loadAll() {
return getHibernateTemplate().find("FROM AttachmentExtension ae ORDER BY ae.value");
}
Full stack trace of any exception that occurs:
None
Name and version of the database you are using:
Oracle 9i, HSQL 1.8.1
The generated SQL (show_sql=true):
Hibernate: select attachment0_.EXTENSION_ID as EXTENSION1_, attachment0_.ALLOW as ALLOW1_, attachment0_.DESCRIPTION as DESCRIPT4_1_, attachment0_.EXTENSION_GROUP_ID as EXTENSION5_1_ from EXTENSIONS attachment0_ order by attachment0_.EXTENSION
Debug level Hibernate log excerpt:
[DEBUG - 23 Nov 2005 10:15:08] org.hibernate.impl.SessionImpl: find: FROM AttachmentExtension ae ORDER BY ae.value
[DEBUG - 23 Nov 2005 10:15:08] org.hibernate.engine.QueryParameters: named parameters: {}
[DEBUG - 23 Nov 2005 10:15:08] org.hibernate.hql.ast.QueryTranslatorImpl: parse() - HQL: FROM com.netg.forums.entities.AttachmentExtension ae ORDER BY ae.value
[DEBUG - 23 Nov 2005 10:15:08] org.hibernate.hql.ast.AST: --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| \-[FROM] 'FROM'
| \-[RANGE] 'RANGE'
| +-[DOT] '.'
| | +-[DOT] '.'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[IDENT] 'com'
| | | | | \-[IDENT] 'netg'
| | | | \-[IDENT] 'forums'
| | | \-[IDENT] 'entities'
| | \-[IDENT] 'AttachmentExtension'
| \-[ALIAS] 'ae'
\-[ORDER] 'ORDER'
\-[DOT] '.'
+-[IDENT] 'ae'
\-[IDENT] 'value'
Hibernate: select attachment0_.EXTENSION_ID as EXTENSION1_, attachment0_.ALLOW as ALLOW1_, attachment0_.DESCRIPTION as DESCRIPT4_1_, attachment0_.EXTENSION_GROUP_ID as EXTENSION5_1_ from EXTENSIONS attachment0_ order by attachment0_.EXTENSION
[DEBUG - 23 Nov 2005 10:15:08] org.hibernate.hql.ast.ErrorCounter: throwQueryException() : no errors
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.antlr.HqlSqlBaseWalker: query() << begin, level = 1
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.FromElement: FromClause{level=1} : com.netg.forums.entities.AttachmentExtension (ae) -> attachment0_
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.FromReferenceNode: Resolved : ae -> attachment0_.EXTENSION_ID
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.DotNode: getDataType() : value -> org.hibernate.type.StringType@1b1d931
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.FromReferenceNode: Resolved : ae.value -> attachment0_.EXTENSION
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.antlr.HqlSqlBaseWalker: query() : finishing up , level = 1
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.HqlSqlWalker: processQuery() : ( SELECT ( FromClause{level=1} EXTENSIONS attachment0_ ) ( ORDER ( attachment0_.EXTENSION attachment0_.EXTENSION_ID value ) ) )
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.HqlSqlWalker: Derived SELECT clause created.
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.JoinProcessor: Using FROM fragment [EXTENSIONS attachment0_]
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.antlr.HqlSqlBaseWalker: query() >> end, level = 1
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.AST: --- SQL AST ---
\-[SELECT] QueryNode: 'SELECT' querySpaces (EXTENSIONS)
+-[SELECT_CLAUSE] SelectClause: '{derived select clause}'
| +-[SELECT_EXPR] SelectExpressionImpl: 'attachment0_.EXTENSION_ID as EXTENSION1_' {FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=ae,role=null,tableName=EXTENSIONS,tableAlias=attachment0_,colums={,className=com.netg.forums.entities.AttachmentExtension}}}
| \-[SQL_TOKEN] SqlFragment: 'attachment0_.ALLOW as ALLOW1_, attachment0_.DESCRIPTION as DESCRIPT4_1_, attachment0_.EXTENSION_GROUP_ID as EXTENSION5_1_'
+-[FROM] FromClause: 'FROM' FromClause{level=1, fromElementCounter=1, fromElements=1, fromElementByClassAlias=[ae], fromElementByTableAlias=[attachment0_], fromElementsByPath=[], collectionJoinFromElementsByPath=[], impliedElements=[]}
| \-[FROM_FRAGMENT] FromElement: 'EXTENSIONS attachment0_' FromElement{explicit,not a collection join,not a fetch join,fetch non-lazy properties,classAlias=ae,role=null,tableName=EXTENSIONS,tableAlias=attachment0_,colums={,className=com.netg.forums.entities.AttachmentExtension}}
\-[ORDER] OrderByClause: 'ORDER'
\-[DOT] DotNode: 'attachment0_.EXTENSION' {propertyName=value,dereferenceType=4,propertyPath=value,path=ae.value,tableAlias=attachment0_,className=com.netg.forums.entities.AttachmentExtension,classAlias=ae}
+-[ALIAS_REF] IdentNode: 'attachment0_.EXTENSION_ID' {alias=ae, className=com.netg.forums.entities.AttachmentExtension, tableAlias=attachment0_}
\-[IDENT] IdentNode: 'value' {originalText=value}
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.ErrorCounter: throwQueryException() : no errors
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.QueryTranslatorImpl: HQL: FROM com.netg.forums.entities.AttachmentExtension ae ORDER BY ae.value
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.QueryTranslatorImpl: SQL: select attachment0_.EXTENSION_ID as EXTENSION1_, attachment0_.ALLOW as ALLOW1_, attachment0_.DESCRIPTION as DESCRIPT4_1_, attachment0_.EXTENSION_GROUP_ID as EXTENSION5_1_ from EXTENSIONS attachment0_ order by attachment0_.EXTENSION
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.hql.ast.ErrorCounter: throwQueryException() : no errors
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.jdbc.AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.jdbc.ConnectionManager: opening JDBC connection
[DEBUG - 23 Nov 2005 10:15:09] org.hibernate.SQL: select attachment0_.EXTENSION_ID as EXTENSION1_, attachment0_.ALLOW as ALLOW1_, attachment0_.DESCRIPTION as DESCRIPT4_1_, attachment0_.EXTENSION_GROUP_ID as EXTENSION5_1_ from EXTENSIONS attachment0_ order by attachment0_.EXTENSION
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.jdbc.AbstractBatcher: preparing statement
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.jdbc.AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: processing result set
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 0
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '4' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#4]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#4]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#4]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '4' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'Microsoft Word Files' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 1
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '7' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#7]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#7]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#7]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '7' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'GIF Images' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 2
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '6' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#6]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#6]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#6]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '6' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'JPEG Images' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 3
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '9' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#9]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#9]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#9]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '9' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'ADOBE PPF' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 4
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '8' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#8]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#8]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#8]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '8' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'Microsoft PowerPoint Files' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 5
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '5' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#5]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#5]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#5]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '5' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'Text Files' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 6
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '11' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#11]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#11]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#11]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '11' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'WordPerfect Document' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result set row: 7
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '3' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: result row: EntityKey[com.netg.forums.entities.AttachmentExtension#3]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.netg.forums.entities.AttachmentExtension#3]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.netg.forums.entities.AttachmentExtension#3]
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning '3' as column: EXTENSION1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.BooleanType: returning 'true' as column: ALLOW1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.StringType: returning 'Microsoft Excel Files' as column: DESCRIPT4_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.type.IntegerType: returning '2' as column: EXTENSION5_1_
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: done processing result set (8 rows)
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.jdbc.AbstractBatcher: about to close ResultSet (open ResultSets: 1, globally: 1)
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.jdbc.AbstractBatcher: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.jdbc.AbstractBatcher: closing statement
[DEBUG - 23 Nov 2005 10:15:30] org.hibernate.loader.Loader: total objects hydrated: 8
|