Hi,
I already posted this in the german forum but got no answers. Maybe the chance for replys is higher here. There is an issue (see
http://opensource.atlassian.com/project ... se/ANN-654 ) that could fit my problem but also there is no solution but the question for a test case. I have a test case but it does not match exactly. I'm quite new to hibernate and possibly I'm just doing something wrong. Any help is appreciated. I collected all data available but if you need anything more just ask.
What it does:
Started with the option -s it sets up the database just like hibenate has done it on my pc and fills in some data.
Started with the option -t1 it fetches the data with a working map.
Started with the option -t2 it fetches the data and fails.
The only thing that's different between the working and the failing map is the option used for LazyCollectionOption. TRUE is working, EXTRA is failing. In the last case there is an extra column created in the SQL named null. I'm pretty sure it should be named KEY to select exactly the line searched for.
Can someone tell me what's going wrong?
Hibernate version:
Code:
Hibernate Annotations 3.3.0.GA
Hibernate 3.2.5
Mapping documents:Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.url">jdbc:hsqldb:file:db/test</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>
The rest is done i the code. See below.
Code between sessionFactory.openSession() and session.close():Code:
Criteria criteria = session.createCriteria(FailingMap.class);
FailingMap map = (FailingMap) criteria.uniqueResult();
int value = map.getMappedValue("Test");
System.out.println("Value for Test: "+value);
Full stack trace of any exception that occurs:Code:
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not collection element by index
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1917)
at org.hibernate.loader.entity.CollectionElementLoader.loadElement(CollectionElementLoader.java:72)
at org.hibernate.persister.collection.OneToManyPersister.getElementByIndex(OneToManyPersister.java:360)
at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:158)
at org.hibernate.collection.PersistentMap.get(PersistentMap.java:146)
at hibernateerror.FailingMap.getMappedValue(FailingMap.java:36)
at hibernateerror.Test.main(Test.java:77)
Caused by: java.sql.SQLException: Column not found: MAPELEMENT0_.NULL in statement [select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1907)
... 6 more
Name and version of the database you are using:Code:
HSQLDB 1.8.3
The generated SQL (show_sql=true):Code:
select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?
That's the problem! There is a null column where there should be a colum named KEY.
Debug level Hibernate log excerpt:Code:
INFO [main]: Hibernate Annotations 3.3.0.GA
INFO [main]: Hibernate 3.2.5
INFO [main]: hibernate.properties not found
INFO [main]: Bytecode provider name : cglib
INFO [main]: using JDK 1.4 java.sql.Timestamp handling
INFO [main]: configuring from url: file:/E:/Projects/eclipse/WorkspaceSpammy/Tests/bin/hibernate.cfg.xml
DEBUG [main]: trying to resolve system-id [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd]
DEBUG [main]: recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/
DEBUG [main]: located [http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd] in classpath
DEBUG [main]: connection.driver_class=org.hsqldb.jdbcDriver
DEBUG [main]: connection.username=sa
DEBUG [main]: connection.password=
DEBUG [main]: connection.url=jdbc:hsqldb:file:db/test
DEBUG [main]: dialect=org.hibernate.dialect.HSQLDialect
DEBUG [main]: hibernate.show_sql=true
INFO [main]: Configured SessionFactory: null
DEBUG [main]: properties: {hibernate.connection.password=,
java.runtime.name=Java(TM) SE Runtime Environment,
sun.boot.library.path=C:\Programme\Java\jre1.6.0_02\bin,
java.vm.version=1.6.0_02-b05,
hibernate.connection.username=sa,
java.vm.vendor=Sun Microsystems Inc.,
java.vendor.url=http://java.sun.com/,
path.separator=;,
java.vm.name=Java HotSpot(TM) Client VM,
file.encoding.pkg=sun.io,
user.country=DE,
sun.java.launcher=SUN_STANDARD,
sun.os.patch.level=Service Pack 2,
java.vm.specification.name=Java Virtual Machine Specification,
user.dir=E:\Projects\eclipse\WorkspaceSpammy\Tests,
java.runtime.version=1.6.0_02-b05,
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment,
java.endorsed.dirs=C:\Programme\Java\jre1.6.0_02\lib\endorsed,
os.arch=x86,
java.io.tmpdir=e:\Temp\,
line.separator=
,
java.vm.specification.vendor=Sun Microsystems Inc.,
user.variant=,
os.name=Windows XP,
sun.jnu.encoding=Cp1252,
java.library.path=C:\Programme\Java\jre1.6.0_02\bin;
.;
C:\WINDOWS\Sun\Java\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\Programme\eclipse\jre\bin\client;
C:\Programme\eclipse\jre\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Programme\ATI Technologies\ATI Control Panel;
c:\bin\;
C:\Programme\Subversion\bin;
C:\Programme\ATI Technologies\ATI.ACE\Core-Static;
C:\programme\java\jdk1.6.0_02\bin,
java.specification.name=Java Platform API Specification,
java.class.version=50.0,
sun.management.compiler=HotSpot Client Compiler,
os.version=5.1,
connection.password=,
user.home=C:\Dokumente und Einstellungen\Admin,
user.timezone=,
connection.username=sa,
java.awt.printerjob=sun.awt.windows.WPrinterJob,
file.encoding=Cp1252,
java.specification.version=1.6,
hibernate.connection.driver_class=org.hsqldb.jdbcDriver,
user.name=Admin,
java.class.path=E:\Projects\eclipse\WorkspaceSpammy\Tests\bin;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-antlr-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-junit-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-launcher-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\antlr-2.7.6.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-swing-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\asm.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\asm-attrs.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\bsh-2.0b1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\c3p0-0.9.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\cglib-2.1.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\checkstyle-all.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\cleanimports.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\commons-collections-2.1.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\commons-logging-1.0.4.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\concurrent-1.3.2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\connector.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\dom4j-1.6.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ehcache-1.2.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\freemarker.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\hibernate-tools.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jaas.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jacc-1_0-fr.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\javassist.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jaxen-1.1-beta-7.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-cache.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-common.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-jmx.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-system.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jdbc2_0-stdext.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jgroups-2.2.8.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jta.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jtidy-r8-20060801.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\junit-3.8.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\log4j-1.2.11.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\oscache-2.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\proxool-0.8.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\swarmcache-1.0rc2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\syndiag2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\versioncheck.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\xerces-2.6.2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\xml-apis.jar;
E:\Projects\eclipse\lib\hibernate-3.2\hibernate3.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\hibernate-annotations.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\lib\hibernate-commons-annotations.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\lib\ejb3-persistence.jar;
E:\Projects\eclipse\lib\hsqldb\lib\hsqldb.jar;
E:\Projects\eclipse\WorkspaceSpammy\SpamWatch\bin;
C:\Programme\Java\jaf-1.1\activation.jar;
C:\Programme\Java\javamail-1.4\mail.jar,
hibernate.bytecode.use_reflection_optimizer=false,
hibernate.show_sql=true,
java.vm.specification.version=1.0,
java.home=C:\Programme\Java\jre1.6.0_02,
sun.arch.data.model=32,
hibernate.dialect=org.hibernate.dialect.HSQLDialect,
hibernate.connection.url=jdbc:hsqldb:file:db/test,
user.language=de,
java.specification.vendor=Sun Microsystems Inc.,
awt.toolkit=sun.awt.windows.WToolkit,
java.vm.info=mixed mode,
sharing,
java.version=1.6.0_02,
java.ext.dirs=C:\Programme\Java\jre1.6.0_02\lib\ext;C:\WINDOWS\Sun\Java\lib\ext,
sun.boot.class.path=C:\Programme\Java\jre1.6.0_02\lib\resources.jar;
C:\Programme\Java\jre1.6.0_02\lib\rt.jar;
C:\Programme\Java\jre1.6.0_02\lib\sunrsasign.jar;
C:\Programme\Java\jre1.6.0_02\lib\jsse.jar;
C:\Programme\Java\jre1.6.0_02\lib\jce.jar;
C:\Programme\Java\jre1.6.0_02\lib\charsets.jar;
C:\Programme\Java\jre1.6.0_02\classes,
java.vendor=Sun Microsystems Inc.,
connection.driver_class=org.hsqldb.jdbcDriver,
file.separator=\,
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi,
sun.io.unicode.encoding=UnicodeLittle,
sun.cpu.endian=little,
sun.desktop=windows,
connection.url=jdbc:hsqldb:file:db/test,
dialect=org.hibernate.dialect.HSQLDialect,
sun.cpu.isalist=}
DEBUG [main]: Validator not present in classpath, ignoring event listener registration
DEBUG [main]: Search not present in classpath, ignoring event listener registration
DEBUG [main]: Preparing to build session factory with filters : {}
DEBUG [main]: Execute first pass mapping processing
DEBUG [main]: Process hbm files
DEBUG [main]: Process annotated classes
INFO [main]: Binding entity from annotated class: hibernateerror.FailingMap
DEBUG [main]: Binding column DTYPE unique false
DEBUG [main]: Import with entity name=FailingMap
INFO [main]: Bind entity hibernateerror.FailingMap on table MAP
DEBUG [main]: Processing hibernateerror.FailingMap property annotation
DEBUG [main]: Processing hibernateerror.FailingMap field annotation
DEBUG [main]: Processing annotations of hibernateerror.FailingMap.id
DEBUG [main]: Binding column id unique false
DEBUG [main]: id is an id
DEBUG [main]: building SimpleValue for id
DEBUG [main]: Building property id
DEBUG [main]: Cascading id with null
DEBUG [main]: Bind @Id on id
DEBUG [main]: Processing annotations of hibernateerror.FailingMap.map
DEBUG [main]: Binding column MAP_ID unique false
DEBUG [main]: Binding column map unique false
DEBUG [main]: Binding column null unique false
DEBUG [main]: Binding column element unique false
DEBUG [main]: Binding column mapkey unique false
DEBUG [main]: Binding column null unique false
DEBUG [main]: Binding column null unique false
DEBUG [main]: Binding column null unique false
DEBUG [main]: Collection role: hibernateerror.FailingMap.map
DEBUG [main]: Building property map
DEBUG [main]: Cascading map with none
INFO [main]: Binding entity from annotated class: hibernateerror.MapElement
DEBUG [main]: Binding column DTYPE unique false
DEBUG [main]: Import with entity name=MapElement
INFO [main]: Bind entity hibernateerror.MapElement on table ELEMENT
DEBUG [main]: Processing hibernateerror.MapElement property annotation
DEBUG [main]: Processing hibernateerror.MapElement field annotation
DEBUG [main]: Processing annotations of hibernateerror.MapElement.key
DEBUG [main]: Binding column KEY unique false
DEBUG [main]: key is an id
DEBUG [main]: building SimpleValue for key
DEBUG [main]: Building property key
DEBUG [main]: Cascading key with null
DEBUG [main]: Bind @Id on key
DEBUG [main]: Processing annotations of hibernateerror.MapElement.value
DEBUG [main]: Binding column VALUE unique false
DEBUG [main]: binding property value with lazy=false
DEBUG [main]: building SimpleValue for value
DEBUG [main]: Building property value
DEBUG [main]: Cascading value with null
DEBUG [main]: processing manytoone fk mappings
DEBUG [main]: processing extends queue
DEBUG [main]: processing collection mappings
DEBUG [main]: Second pass for collection: hibernateerror.FailingMap.map
DEBUG [main]: Binding a OneToMany: hibernateerror.FailingMap.map through a foreign key
INFO [main]: Mapping collection: hibernateerror.FailingMap.map -> ELEMENT
DEBUG [main]: Mapped collection key: MAP_ID, index: KEY, one-to-many: hibernateerror.MapElement
DEBUG [main]: processing native query and ResultSetMapping mappings
DEBUG [main]: processing association property references
DEBUG [main]: processing foreign key constraints
DEBUG [main]: resolving reference to class: hibernateerror.FailingMap
INFO [main]: Hibernate Validator not found: ignoring
INFO [main]: Using Hibernate built-in connection pool (not for production use!)
INFO [main]: Hibernate connection pool size: 20
INFO [main]: autocommit mode: false
INFO [main]: using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:file:db/test
INFO [main]: connection properties: {user=sa, password=}
DEBUG [main]: total checked-out connections: 0
DEBUG [main]: opening new JDBC connection
DEBUG [main]: created connection to: jdbc:hsqldb:file:db/test, Isolation Level: 2
INFO [main]: RDBMS: HSQL Database Engine, version: 1.8.0
INFO [main]: JDBC driver: HSQL Database Engine Driver, version: 1.8.0
DEBUG [main]: returning connection to pool, pool size: 1
INFO [main]: Using dialect: org.hibernate.dialect.HSQLDialect
INFO [main]: Using default transaction strategy (direct JDBC transactions)
INFO [main]: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO [main]: Automatic flush during beforeCompletion(): disabled
INFO [main]: Automatic session close at end of transaction: disabled
INFO [main]: JDBC batch size: 15
INFO [main]: JDBC batch updates for versioned data: disabled
INFO [main]: Scrollable result sets: enabled
DEBUG [main]: Wrap result sets: disabled
INFO [main]: JDBC3 getGeneratedKeys(): disabled
INFO [main]: Connection release mode: auto
INFO [main]: Default batch fetch size: 1
INFO [main]: Generate SQL with comments: disabled
INFO [main]: Order SQL updates by primary key: disabled
INFO [main]: Order SQL inserts for batching: disabled
INFO [main]: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO [main]: Using ASTQueryTranslatorFactory
INFO [main]: Query language substitutions: {}
INFO [main]: JPA-QL strict compliance: disabled
INFO [main]: Second-level cache: enabled
INFO [main]: Query cache: disabled
INFO [main]: Cache provider: org.hibernate.cache.NoCacheProvider
INFO [main]: Optimize cache for minimal puts: disabled
INFO [main]: Structured second-level cache entries: disabled
DEBUG [main]: Using dialect defined converter
INFO [main]: Echoing all SQL to stdout
INFO [main]: Statistics: disabled
INFO [main]: Deleted entity synthetic identifier rollback: disabled
INFO [main]: Default entity-mode: pojo
INFO [main]: Named query checking : enabled
INFO [main]: building session factory
DEBUG [main]: Session factory constructed with filter configurations : {}
DEBUG [main]: instantiating session factory with properties: {java.runtime.name=Java(TM) SE Runtime Environment,
hibernate.connection.password=,
sun.boot.library.path=C:\Programme\Java\jre1.6.0_02\bin,
java.vm.version=1.6.0_02-b05,
hibernate.connection.username=sa,
java.vm.vendor=Sun Microsystems Inc.,
java.vendor.url=http://java.sun.com/,
path.separator=;,
java.vm.name=Java HotSpot(TM) Client VM,
file.encoding.pkg=sun.io,
user.country=DE,
sun.java.launcher=SUN_STANDARD,
sun.os.patch.level=Service Pack 2,
java.vm.specification.name=Java Virtual Machine Specification,
user.dir=E:\Projects\eclipse\WorkspaceSpammy\Tests,
java.runtime.version=1.6.0_02-b05,
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment,
java.endorsed.dirs=C:\Programme\Java\jre1.6.0_02\lib\endorsed,
os.arch=x86,
java.io.tmpdir=e:\Temp\,
line.separator=
,
java.vm.specification.vendor=Sun Microsystems Inc.,
user.variant=,
os.name=Windows XP,
sun.jnu.encoding=Cp1252,
java.library.path=C:\Programme\Java\jre1.6.0_02\bin;
.;
C:\WINDOWS\Sun\Java\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\Programme\eclipse\jre\bin\client;
C:\Programme\eclipse\jre\bin;
C:\WINDOWS\system32;
C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\Programme\ATI Technologies\ATI Control Panel;
c:\bin\;
C:\Programme\Subversion\bin;
C:\Programme\ATI Technologies\ATI.ACE\Core-Static;
C:\programme\java\jdk1.6.0_02\bin,
java.specification.name=Java Platform API Specification,
java.class.version=50.0,
sun.management.compiler=HotSpot Client Compiler,
os.version=5.1,
user.home=C:\Dokumente und Einstellungen\Admin,
connection.password=,
user.timezone=,
java.awt.printerjob=sun.awt.windows.WPrinterJob,
connection.username=sa,
java.specification.version=1.6,
file.encoding=Cp1252,
hibernate.connection.driver_class=org.hsqldb.jdbcDriver,
java.class.path=E:\Projects\eclipse\WorkspaceSpammy\Tests\bin;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-antlr-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-junit-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-launcher-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\antlr-2.7.6.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ant-swing-1.6.5.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\asm.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\asm-attrs.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\bsh-2.0b1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\c3p0-0.9.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\cglib-2.1.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\checkstyle-all.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\cleanimports.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\commons-collections-2.1.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\commons-logging-1.0.4.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\concurrent-1.3.2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\connector.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\dom4j-1.6.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\ehcache-1.2.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\freemarker.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\hibernate-tools.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jaas.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jacc-1_0-fr.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\javassist.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jaxen-1.1-beta-7.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-cache.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-common.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-jmx.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jboss-system.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jdbc2_0-stdext.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jgroups-2.2.8.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jta.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\jtidy-r8-20060801.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\junit-3.8.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\log4j-1.2.11.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\oscache-2.1.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\proxool-0.8.3.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\swarmcache-1.0rc2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\syndiag2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\versioncheck.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\xerces-2.6.2.jar;
E:\Projects\eclipse\lib\hibernate-3.2\lib\xml-apis.jar;
E:\Projects\eclipse\lib\hibernate-3.2\hibernate3.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\hibernate-annotations.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\lib\hibernate-commons-annotations.jar;
E:\Projects\eclipse\lib\hibernate-annotations-3.3.0.GA\lib\ejb3-persistence.jar;
E:\Projects\eclipse\lib\hsqldb\lib\hsqldb.jar;
E:\Projects\eclipse\WorkspaceSpammy\SpamWatch\bin;
C:\Programme\Java\jaf-1.1\activation.jar;
C:\Programme\Java\javamail-1.4\mail.jar,
user.name=Admin,
hibernate.bytecode.use_reflection_optimizer=false,
hibernate.show_sql=true,
java.vm.specification.version=1.0,
sun.arch.data.model=32,
java.home=C:\Programme\Java\jre1.6.0_02,
hibernate.connection.url=jdbc:hsqldb:file:db/test,
hibernate.dialect=org.hibernate.dialect.HSQLDialect,
java.specification.vendor=Sun Microsystems Inc.,
user.language=de,
awt.toolkit=sun.awt.windows.WToolkit,
java.vm.info=mixed mode,
sharing,
java.version=1.6.0_02,
java.ext.dirs=C:\Programme\Java\jre1.6.0_02\lib\ext;C:\WINDOWS\Sun\Java\lib\ext,
sun.boot.class.path=C:\Programme\Java\jre1.6.0_02\lib\resources.jar;
C:\Programme\Java\jre1.6.0_02\lib\rt.jar;
C:\Programme\Java\jre1.6.0_02\lib\sunrsasign.jar;
C:\Programme\Java\jre1.6.0_02\lib\jsse.jar;
C:\Programme\Java\jre1.6.0_02\lib\jce.jar;
C:\Programme\Java\jre1.6.0_02\lib\charsets.jar;
C:\Programme\Java\jre1.6.0_02\classes,
java.vendor=Sun Microsystems Inc.,
file.separator=\,
connection.driver_class=org.hsqldb.jdbcDriver,
java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi,
sun.cpu.endian=little,
sun.io.unicode.encoding=UnicodeLittle,
sun.desktop=windows,
connection.url=jdbc:hsqldb:file:db/test,
sun.cpu.isalist=,
dialect=org.hibernate.dialect.HSQLDialect}
DEBUG [main]: Static SQL for entity: hibernateerror.FailingMap
DEBUG [main]: Version select: select id from MAP where id =?
DEBUG [main]: Snapshot select: select failingmap_.id from MAP failingmap_ where failingmap_.id=?
DEBUG [main]: Insert 0: insert into MAP (id) values (?)
DEBUG [main]: Update 0: null
DEBUG [main]: Delete 0: delete from MAP where id=?
DEBUG [main]: Identity insert: insert into MAP (id) values (null)
DEBUG [main]: Static SQL for entity: hibernateerror.MapElement
DEBUG [main]: Version select: select KEY from ELEMENT where KEY =?
DEBUG [main]: Snapshot select: select mapelement_.KEY, mapelement_.VALUE as VALUE1_ from ELEMENT mapelement_ where mapelement_.KEY=?
DEBUG [main]: Insert 0: insert into ELEMENT (VALUE, KEY) values (?, ?)
DEBUG [main]: Update 0: update ELEMENT set VALUE=? where KEY=?
DEBUG [main]: Delete 0: delete from ELEMENT where KEY=?
DEBUG [main]: Static SQL for collection: hibernateerror.FailingMap.map
DEBUG [main]: Row insert: update ELEMENT set MAP_ID=? where KEY=?
DEBUG [main]: Row delete: update ELEMENT set MAP_ID=null where MAP_ID=? and KEY=?
DEBUG [main]: One-shot delete: update ELEMENT set MAP_ID=null where MAP_ID=?
DEBUG [main]: Static select for entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for action ACTION_MERGE on entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for action ACTION_REFRESH on entity hibernateerror.FailingMap: select failingmap0_.id as id0_0_ from MAP failingmap0_ where failingmap0_.id=?
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for action ACTION_MERGE on entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for action ACTION_REFRESH on entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.KEY=?
DEBUG [main]: Static select for one-to-many hibernateerror.FailingMap.map: select map0_.MAP_ID as MAP3_1_, map0_.KEY as KEY1_, map0_.KEY as formula0_1_, map0_.KEY as KEY1_0_, map0_.VALUE as VALUE1_0_ from ELEMENT map0_ where map0_.MAP_ID=?
DEBUG [main]: initializing class SessionFactoryObjectFactory
DEBUG [main]: registered: 4028fa7e15325f3e0115325f40600000 (unnamed)
INFO [main]: Not binding factory to JNDI, no JNDI name configured
DEBUG [main]: instantiated session factory
DEBUG [main]: Checking 0 named HQL queries
DEBUG [main]: Checking 0 named SQL queries
DEBUG [main]: opened session at timestamp: 11905510442
DEBUG [main]: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main]: opening JDBC connection
DEBUG [main]: total checked-out connections: 0
DEBUG [main]: using pooled JDBC connection, pool size: 0
DEBUG [main]: select this_.id as id0_0_ from MAP this_
Hibernate: select this_.id as id0_0_ from MAP this_
DEBUG [main]: preparing statement
DEBUG [main]: about to open ResultSet (open ResultSets: 0, globally: 0)
DEBUG [main]: processing result set
DEBUG [main]: result set row: 0
DEBUG [main]: returning '0' as column: id0_0_
DEBUG [main]: result row: EntityKey[hibernateerror.FailingMap#0]
DEBUG [main]: Initializing object from ResultSet: [hibernateerror.FailingMap#0]
DEBUG [main]: Hydrating entity: [hibernateerror.FailingMap#0]
DEBUG [main]: done processing result set (1 rows)
DEBUG [main]: about to close ResultSet (open ResultSets: 1, globally: 1)
DEBUG [main]: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main]: closing statement
DEBUG [main]: total objects hydrated: 1
DEBUG [main]: resolving associations for [hibernateerror.FailingMap#0]
DEBUG [main]: creating collection wrapper:[hibernateerror.FailingMap.map#0]
DEBUG [main]: done materializing entity [hibernateerror.FailingMap#0]
DEBUG [main]: initializing non-lazy collections
DEBUG [main]: after autocommit
DEBUG [main]: aggressively releasing JDBC connection
DEBUG [main]: releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
DEBUG [main]: returning connection to pool, pool size: 1
DEBUG [main]: Static select for entity hibernateerror.MapElement: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?
DEBUG [main]: loading collection element by index
DEBUG [main]: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main]: opening JDBC connection
DEBUG [main]: total checked-out connections: 0
DEBUG [main]: using pooled JDBC connection, pool size: 0
DEBUG [main]: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?
Hibernate: select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?
DEBUG [main]: preparing statement
DEBUG [main]: could not collection element by index [select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?]
java.sql.SQLException: Column not found: MAPELEMENT0_.NULL in statement [select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1907)
at org.hibernate.loader.entity.CollectionElementLoader.loadElement(CollectionElementLoader.java:72)
at org.hibernate.persister.collection.OneToManyPersister.getElementByIndex(OneToManyPersister.java:360)
at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:158)
at org.hibernate.collection.PersistentMap.get(PersistentMap.java:146)
at hibernateerror.FailingMap.getMappedValue(FailingMap.java:36)
at hibernateerror.Test.main(Test.java:77)
WARN [main]: SQL Error: -28, SQLState: S0022
ERROR [main]: Column not found: MAPELEMENT0_.NULL in statement [select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?]
Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not collection element by index
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1917)
at org.hibernate.loader.entity.CollectionElementLoader.loadElement(CollectionElementLoader.java:72)
at org.hibernate.persister.collection.OneToManyPersister.getElementByIndex(OneToManyPersister.java:360)
at org.hibernate.collection.AbstractPersistentCollection.readElementByIndex(AbstractPersistentCollection.java:158)
at org.hibernate.collection.PersistentMap.get(PersistentMap.java:146)
at hibernateerror.FailingMap.getMappedValue(FailingMap.java:36)
at hibernateerror.Test.main(Test.java:77)
Caused by: java.sql.SQLException: Column not found: MAPELEMENT0_.NULL in statement [select mapelement0_.KEY as KEY1_0_, mapelement0_.VALUE as VALUE1_0_ from ELEMENT mapelement0_ where mapelement0_.MAP_ID=? and mapelement0_.null=?]
at org.hsqldb.jdbc.Util.throwError(Unknown Source)
at org.hsqldb.jdbc.jdbcPreparedStatement.<init>(Unknown Source)
at org.hsqldb.jdbc.jdbcConnection.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:423)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1547)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1907)
... 6 more
Mapped classCode:
package hibernateerror;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="ELEMENT")
public class MapElement {
@Id
@Column(name="KEY")
private String key;
@Column(name="VALUE")
private int value;
public MapElement() {
key = "";
value = 0;
}
public String getKey() {
return key;
}
public int getValue() {
return value;
}
}
Working map (LazyCollectionOption.TRUE)Code:
package hibernateerror;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name="MAP")
public class WorkingMap {
@SuppressWarnings("unused")
@Id
@GeneratedValue()
private long id;
@OneToMany
@JoinColumn(name="MAP_ID")
@MapKey(name="key")
@LazyCollection(LazyCollectionOption.TRUE)
private Map<String, MapElement> map;
public WorkingMap() {
map = new HashMap<String, MapElement>();
}
public int getMappedValue(String key) {
MapElement element = map.get(key);
return element.getValue();
}
}
Gailing map (LazyCollectionOption.EXTRA)Code:
package hibernateerror;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MapKey;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
@Entity
@Table(name="MAP")
public class FailingMap {
@SuppressWarnings("unused")
@Id
@GeneratedValue
private long id;
@OneToMany
@JoinColumn(name="MAP_ID")
@MapKey(name="key")
@LazyCollection(LazyCollectionOption.EXTRA)
private Map<String, MapElement> map;
public FailingMap() {
map = new HashMap<String, MapElement>();
}
public int getMappedValue(String key) {
MapElement element = map.get(key);
return element.getValue();
}
}
Test classCode:
package hibernateerror;
import java.net.URL;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;
import org.apache.log4j.WriterAppender;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.classic.Session;
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
if (args.length != 1) {
usage();
}
Logger.getRootLogger().addAppender(new WriterAppender(new PatternLayout("%-5p [%t]: %m%n"), System.out));
Logger.getRootLogger().setLevel(Level.DEBUG);
AnnotationConfiguration configuration = new AnnotationConfiguration();
if (args[0].equals("-t1")) {
configuration.addAnnotatedClass(WorkingMap.class);
configuration.addAnnotatedClass(MapElement.class);
}
if (args[0].equals("-t2")) {
configuration.addAnnotatedClass(FailingMap.class);
configuration.addAnnotatedClass(MapElement.class);
}
URL configURL = Test.class.getResource("/hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.configure(configURL).buildSessionFactory();
Session session = sessionFactory.openSession();
if (args[0].equals("-s")) {
//setup db
Transaction tx = session.beginTransaction();
session.createSQLQuery("CREATE CACHED TABLE MAP (ID BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL , CONSTRAINT SYS_IDX_92 PRIMARY KEY (ID) )").executeUpdate();
session.createSQLQuery("CREATE CACHED TABLE ELEMENT (KEY VARCHAR NOT NULL ,VALUE INTEGER,MAP_ID BIGINT, CONSTRAINT SYS_IDX_82 PRIMARY KEY (KEY), CONSTRAINT FK6C4B5BD93AD2F82 FOREIGN KEY (MAP_ID) REFERENCES MAP (ID) )").executeUpdate();
tx.commit();
//insert data
tx = session.beginTransaction();
session.createSQLQuery("INSERT INTO MAP VALUES(null)").executeUpdate();
session.createSQLQuery("INSERT INTO ELEMENT VALUES('Test', 15, 0)").executeUpdate();
session.createSQLQuery("INSERT INTO ELEMENT VALUES('SomeKey', 17, 0)").executeUpdate();
tx.commit();
//exit
tx = session.beginTransaction();
session.createSQLQuery("CHECKPOINT").executeUpdate();
tx.commit();
session.close();
sessionFactory.close();
System.out.println("Setup complete");
System.exit(0);
}
if (args[0].equals("-t1")) {
Criteria criteria = session.createCriteria(WorkingMap.class);
WorkingMap map = (WorkingMap) criteria.uniqueResult();
int value = map.getMappedValue("Test");
System.out.println("Value for Test: "+value);
//exit
session.close();
sessionFactory.close();
System.exit(0);
}
if (args[0].equals("-t2")) {
Criteria criteria = session.createCriteria(FailingMap.class);
FailingMap map = (FailingMap) criteria.uniqueResult();
int value = map.getMappedValue("Test");
System.out.println("Value for Test: "+value);
//exit
session.close();
sessionFactory.close();
System.exit(0);
}
}
private static void usage() {
System.out.println("Args:");
System.out.println("-s: Setup");
System.out.println("-t1: Working test");
System.out.println("-t2: Failing test");
System.exit(0);
}
}