emmanuel wrote:
you actually have a collection of elements (you should use @CollectionOfElements BTW), so the element does not have any id hence the default does not work
I don't have the mapping of TestCase so I can only guess.
Maybe the MapKey algorithm has a hole for collection of elements. Try to minimize the testcase to 1 Entity and 1 collection of elements and a map key referencing a property of this composite element. If it fails, put it to JIRa, I'll check it and fix it.
OK, I have created a simple case and I get the same problem. I ran into another question/problem using @CollectionOfElements (it seems that there is no option for any cascading behavior on it -- see
related post), so I am manually saving the child and then the parent.
The mappings:
Code:
@Entity
public class Parent
{
@Id
@GeneratedValue
private Long id;
@CollectionOfElements
@MapKey
private Map<String, Child> children = new HashMap<String, Child>();
public Parent(){}
public void addChild(Child child)
{
this.children.put("" + System.currentTimeMillis(), child);
}
public Map<String, Child> getChildren()
{
return this.children;
}
}
Code:
@Entity
public class Child
{
@Id
@GeneratedValue
private Long id;
public Child() {}
}
The test:
Code:
Parent parent = new Parent();
Child child = new Child();
parent.addChild(child);
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
Transaction tx = session.beginTransaction();
session.save(child);
session.save(parent);
tx.commit();
session = HibernateUtil.getSessionFactory().getCurrentSession();
tx = session.beginTransaction();
session.merge(parent);
tx.commit();
It fails on the attempt to merge, because the generated SQL refers to a column that does not exist (in the table created by the earlier generated SQL). Here is the exception:
Code:
could not initialize a collection: [org.aitools.Parent.children#1] [select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0
_ from Parent_Child children0_ left outer join Child child1_ on children0_.children_id=child1_.id where children0_.Parent_id=?]
java.sql.SQLException: Unknown column 'children0_.id' in 'field list'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
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)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:71)
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:1693)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:183)
at org.hibernate.collection.PersistentMap.clear(PersistentMap.java:181)
at org.hibernate.type.MapType.replaceElements(MapType.java:66)
at org.hibernate.type.CollectionType.replace(CollectionType.java:437)
at org.hibernate.type.TypeFactory.replace(TypeFactory.java:431)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:281)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:247)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:100)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:52)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:699)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:683)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:687)
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 org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:292)
at $Proxy8.merge(Unknown Source)
at org.aitools.TestServlet.doGet(TestServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
SQL Error: 1054, SQLState: 42S22
Unknown column 'children0_.id' in 'field list'
Servlet.service() for servlet TestServlet threw exception
org.hibernate.exception.SQLGrammarException: could not initialize a collection: [org.aitools.Parent.children#1]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:65)
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:71)
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:1693)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:183)
at org.hibernate.collection.PersistentMap.clear(PersistentMap.java:181)
at org.hibernate.type.MapType.replaceElements(MapType.java:66)
at org.hibernate.type.CollectionType.replace(CollectionType.java:437)
at org.hibernate.type.TypeFactory.replace(TypeFactory.java:431)
at org.hibernate.event.def.DefaultMergeEventListener.copyValues(DefaultMergeEventListener.java:281)
at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:247)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:100)
at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:52)
at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:699)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:683)
at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:687)
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 org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:292)
at $Proxy8.merge(Unknown Source)
at org.aitools.TestServlet.doGet(TestServlet.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.SQLException: Unknown column 'children0_.id' in 'field list'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2928)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1571)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1666)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2994)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:936)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1030)
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)
... 40 more
Here's the generated SQL:
Code:
Static SQL for entity: org.aitools.Parent
Version select: select id from Parent where id =?
Snapshot select: select parent_.id from Parent parent_ where parent_.id=?
Insert 0: insert into Parent (id) values (?)
Update 0: null
Delete 0: delete from Parent where id=?
Identity insert: insert into Parent values ( )
Static SQL for entity: org.aitools.Child
Version select: select id from Child where id =?
Snapshot select: select child_.id from Child child_ where child_.id=?
Insert 0: insert into Child (id) values (?)
Update 0: null
Delete 0: delete from Child where id=?
Identity insert: insert into Child values ( )
Static SQL for collection: org.aitools.Parent.children
Row insert: insert into Parent_Child (Parent_id, children_id) values (?, ?)
Row update: update Parent_Child set children_id=? where Parent_id=? and children_id=?
Row delete: delete from Parent_Child where Parent_id=? and children_id=?
One-shot delete: delete from Parent_Child where Parent_id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=? for update
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=? for update
Static select for action ACTION_MERGE on entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for action ACTION_REFRESH on entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=? for update
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=? for update
Static select for action ACTION_MERGE on entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for action ACTION_REFRESH on entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for collection org.aitools.Parent.children: select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0_ from Par
ent_Child children0_ left outer join Child child1_ on children0_.children_id=child1_.id where children0_.Parent_id=?
Here's the whole Hibernate debug output:
Code:
Hibernate 3.1.1
hibernate.properties not found
using CGLIB reflection optimizer
using JDK 1.4 java.sql.Timestamp handling
configuring from resource: /hibernate.cfg.xml
Configuration resource: /hibernate.cfg.xml
trying to locate http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd in classpath under org/hibernate/
found http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd in classpath
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.password=WERUIOWERUOIWER
hibernate.connection.url=jdbc:mysql:///hibernatetest
hibernate.connection.username=test
connection.pool_size=1
hibernate.dialect=org.hibernate.dialect.MySQLDialect
current_session_context_class=thread
cache.provider_class=org.hibernate.cache.NoCacheProvider
show_sql=true
hbm2ddl.auto=create
hibernate.current_session_context_class=thread
null<-org.dom4j.tree.DefaultAttribute@6cb8 [Attribute: name class value "org.aitools.Parent"]
null<-org.dom4j.tree.DefaultAttribute@ee22f7 [Attribute: name class value "org.aitools.Child"]
Configured SessionFactory: null
properties: {show_sql=true, java.vendor=Sun Microsystems Inc., catalina.base=/home/noel/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1, hibernate.connection.url=jdbc:mysql:///hibernatet
est, sun.management.compiler=HotSpot Client Compiler, catalina.useNaming=true, hbm2ddl.auto=create, os.name=Linux, sun.boot.class.path=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/rt.jar:/usr/lib/jvm/
java-1.5.0-sun-1.5.0.05/jre/lib/i18n.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/jsse.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/
jce.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/charsets.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/classes, hibernate.current_session_context_class=thread, sun.desktop=gnome, java.vm.specifica
tion.vendor=Sun Microsystems Inc., java.runtime.version=1.5.0_05-b05, hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider, user.name=noel, shared.loader=${catalina.base}/shared/classes,
${catalina.base}/shared/lib/*.jar, tomcat.util.buf.StringCache.byte.enabled=true, current_session_context_class=thread, user.language=en, java.naming.factory.initial=org.apache.naming.java.javaURLCont
extFactory, sun.boot.library.path=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i386, java.version=1.5.0_05, user.timezone=America/New_York, sun.arch.data.model=32, java.endorsed.dirs=/usr/local/tomcat
5/common/endorsed, sun.cpu.isalist=, sun.jnu.encoding=UTF-8, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., fil
e.separator=/, java.specification.name=Java Platform API Specification, hibernate.cglib.use_reflection_optimizer=true, java.class.version=49.0, user.country=US, java.home=/usr/lib/jvm/java-1.5.0-sun-1
.5.0.05/jre, java.vm.info=mixed mode, sharing, os.version=2.6.14-1.1656_FC4, path.separator=:, java.vm.version=1.5.0_05-b05, hibernate.connection.password=WERUIOWERUOIWER, java.awt.printerjob=sun.prin
t.PSPrinterJob, sun.io.unicode.encoding=UnicodeLittle, hibernate.connection.username=test, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,
java.naming.factory.url.pkgs=org.apache.naming, user.home=/home/noel, java.specification.vendor=Sun Microsystems Inc., hibernate.hbm2ddl.auto=create, java.library.path=/usr/lib/jvm/java-1.5.0-sun-1.5.
0.05/jre/lib/i386/client:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i386:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/../lib/i386:/usr/lib/mozilla-1.7.12, java.vendor.url=http://java.sun.com/, hibernate
.connection.driver_class=com.mysql.jdbc.Driver, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=org.hibernate.dialect.MySQLDialect, common.loader=${catalina.home}/common/classes,${catalina.hom
e}/common/i18n/*.jar,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=/usr/local/tomcat5/bi
n/bootstrap.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/lib/tools.jar, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=/usr/local/tomcat5,
sun.cpu.endian=little, sun.os.patch.level=unknown, connection.pool_size=1, java.io.tmpdir=/tmp, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, server.loader=${catalina.home}/server/cla
sses,${catalina.home}/server/lib/*.jar, os.arch=i386, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.ext.dirs=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/ext, user.dir=/home/noel, line.sep
arator=
, java.vm.name=Java HotSpot(TM) Client VM, cache.provider_class=org.hibernate.cache.NoCacheProvider, file.encoding=UTF-8, java.specification.version=1.5, hibernate.show_sql=true, hibernate.connection.
pool_size=1}
Preparing to build session factory with filters : {}
Execute first pass mapping processing
Process hbm files
Process annotated classes
Binding entity from annotated class: org.aitools.Parent
Binding column TYPE unique false
Import with entity name=Parent
Bind entity org.aitools.Parent on table Parent
Processing org.aitools.Parent per property annotation
Processing org.aitools.Parent per field annotation
Processing annotations of org.aitools.Parent.id
Binding column id unique false
id is an id
building SimpleValue for id
Building property id
Cascading id with null
Bind @Id on id
Processing annotations of org.aitools.Parent.children
Binding column null unique false
Binding column children unique false
Binding column null unique false
Binding column null unique false
Binding column null unique false
Collection role: org.aitools.Parent.children
Building property children
Cascading children with null
ResourceBundle ValidatorMessages not found. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
Binding entity from annotated class: org.aitools.Child
Binding column TYPE unique false
Import with entity name=Child
Bind entity org.aitools.Child on table Child
Processing org.aitools.Child per property annotation
Processing org.aitools.Child per field annotation
Processing annotations of org.aitools.Child.id
Binding column id unique false
id is an id
building SimpleValue for id
Building property id
Cascading id with null
Bind @Id on id
ResourceBundle ValidatorMessages not found. Delegate to org.hibernate.validator.resources.DefaultValidatorMessages
processing manytoone fk mappings
processing extends queue
processing collection mappings
Second pass for collection: org.aitools.Parent.children
Binding a OneToMany: org.aitools.Parent.children through an association table
Mapped collection key: Parent_id, index: id, element: children_id
processing native query and ResultSetMapping mappings
processing association property references
processing foreign key constraints
resolving reference to class: org.aitools.Child
resolving reference to class: org.aitools.Parent
Using Hibernate built-in connection pool (not for production use!)
Hibernate connection pool size: 1
autocommit mode: false
using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql:///hibernatetest
connection properties: {user=test, password=WERUIOWERUOIWER}
total checked-out connections: 0
opening new JDBC connection
created connection to: jdbc:mysql:///hibernatetest, Isolation Level: 4
RDBMS: MySQL, version: 4.1.16-log
JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.12 ( $Date: 2005-11-17 15:53:48 +0100 (Thu, 17 Nov 2005) $, $Revision$ )
returning connection to pool, pool size: 1
Using dialect: org.hibernate.dialect.MySQLDialect
Using default transaction strategy (direct JDBC transactions)
No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Automatic flush during beforeCompletion(): disabled
Automatic session close at end of transaction: disabled
JDBC batch size: 15
JDBC batch updates for versioned data: disabled
Scrollable result sets: enabled
Wrap result sets: disabled
JDBC3 getGeneratedKeys(): enabled
Connection release mode: auto
Maximum outer join fetch depth: 2
Default batch fetch size: 1
Generate SQL with comments: disabled
Order SQL updates by primary key: disabled
Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Using ASTQueryTranslatorFactory
Query language substitutions: {}
Second-level cache: enabled
Query cache: disabled
Cache provider: org.hibernate.cache.NoCacheProvider
Optimize cache for minimal puts: disabled
Structured second-level cache entries: disabled
Using dialect defined converter
Echoing all SQL to stdout
Statistics: disabled
Deleted entity synthetic identifier rollback: disabled
Default entity-mode: pojo
building session factory
Session factory constructed with filter configurations : {}
instantiating session factory with properties: {java.vendor=Sun Microsystems Inc., show_sql=true, catalina.base=/home/noel/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1, hibernate.conn
ection.url=jdbc:mysql:///hibernatetest, sun.management.compiler=HotSpot Client Compiler, catalina.useNaming=true, os.name=Linux, hbm2ddl.auto=create, sun.boot.class.path=/usr/lib/jvm/java-1.5.0-sun-1.
5.0.05/jre/lib/rt.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i18n.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/jsse.jar:/usr/lib/j
vm/java-1.5.0-sun-1.5.0.05/jre/lib/jce.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/charsets.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/classes, hibernate.current_session_context_class=thread, s
un.desktop=gnome, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.5.0_05-b05, hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider, user.name=noel, shared.load
er=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar, tomcat.util.buf.StringCache.byte.enabled=true, current_session_context_class=thread, user.language=en, java.naming.factory.initial
=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i386, java.version=1.5.0_05, user.timezone=America/New_York, sun.arch.data.model=32, j
ava.endorsed.dirs=/usr/local/tomcat5/common/endorsed, sun.cpu.isalist=, sun.jnu.encoding=UTF-8, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.
,org.apache.jasper.,sun.beans., file.separator=/, java.specification.name=Java Platform API Specification, hibernate.cglib.use_reflection_optimizer=true, java.class.version=49.0, user.country=US, java
.home=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre, java.vm.info=mixed mode, sharing, os.version=2.6.14-1.1656_FC4, path.separator=:, java.vm.version=1.5.0_05-b05, hibernate.connection.password=WERUIOWERU
OIWER, java.awt.printerjob=sun.print.PSPrinterJob, sun.io.unicode.encoding=UnicodeLittle, hibernate.connection.username=test, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.
apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=/home/noel, java.specification.vendor=Sun Microsystems Inc., hibernate.hbm2ddl.auto=create, java.library.pa
th=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i386/client:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib/i386:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/../lib/i386:/usr/lib/mozilla-1.7.12, java.vendor.
url=http://java.sun.com/, hibernate.connection.driver_class=com.mysql.jdbc.Driver, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=org.hibernate.dialect.MySQLDialect, common.loader=${catalina.
home}/common/classes,${catalina.home}/common/i18n/*.jar,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, ja
va.class.path=/usr/local/tomcat5/bin/bootstrap.jar:/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/lib/tools.jar, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0,
catalina.home=/usr/local/tomcat5, sun.cpu.endian=little, sun.os.patch.level=unknown, connection.pool_size=1, java.io.tmpdir=/tmp, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, server
.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar, os.arch=i386, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.ext.dirs=/usr/lib/jvm/java-1.5.0-sun-1.5.0.05/jre/lib
/ext, user.dir=/home/noel, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, cache.provider_class=org.hibernate.cache.NoCacheProvider, file.encoding=UTF-8, java.specification.version=1.5, hibernate.connection.pool_size=1, hibernate.sh
ow_sql=true}
Static SQL for entity: org.aitools.Parent
Version select: select id from Parent where id =?
Snapshot select: select parent_.id from Parent parent_ where parent_.id=?
Insert 0: insert into Parent (id) values (?)
Update 0: null
Delete 0: delete from Parent where id=?
Identity insert: insert into Parent values ( )
Static SQL for entity: org.aitools.Child
Version select: select id from Child where id =?
Snapshot select: select child_.id from Child child_ where child_.id=?
Insert 0: insert into Child (id) values (?)
Update 0: null
Delete 0: delete from Child where id=?
Identity insert: insert into Child values ( )
Static SQL for collection: org.aitools.Parent.children
Row insert: insert into Parent_Child (Parent_id, children_id) values (?, ?)
Row update: update Parent_Child set children_id=? where Parent_id=? and children_id=?
Row delete: delete from Parent_Child where Parent_id=? and children_id=?
One-shot delete: delete from Parent_Child where Parent_id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=? for update
Static select for entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=? for update
Static select for action ACTION_MERGE on entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for action ACTION_REFRESH on entity org.aitools.Parent: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=? for update
Static select for entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=? for update
Static select for action ACTION_MERGE on entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for action ACTION_REFRESH on entity org.aitools.Child: select child0_.id as id1_0_ from Child child0_ where child0_.id=?
Static select for collection org.aitools.Parent.children: select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0_ from Par
ent_Child children0_ left outer join Child child1_ on children0_.children_id=child1_.id where children0_.Parent_id=?
initializing class SessionFactoryObjectFactory
registered: ff80808108fde2af0108fde2b3cf0000 (unnamed)
Not binding factory to JNDI, no JNDI name configured
instantiated session factory
Execute first pass mapping processing
Process hbm files
Process annotated classes
processing manytoone fk mappings
processing extends queue
processing collection mappings
processing native query and ResultSetMapping mappings
processing association property references
processing foreign key constraints
resolving reference to class: org.aitools.Child
resolving reference to class: org.aitools.Parent
Execute first pass mapping processing
Process hbm files
Process annotated classes
processing manytoone fk mappings
processing extends queue
processing collection mappings
processing native query and ResultSetMapping mappings
processing association property references
processing foreign key constraints
resolving reference to class: org.aitools.Child
resolving reference to class: org.aitools.Parent
Running hbm2ddl schema export
import file not found: /import.sql
exporting generated schema to database
total checked-out connections: 0
using pooled JDBC connection, pool size: 0
alter table Parent_Child drop foreign key FK5AF11D472EC2DFD2
alter table Parent_Child drop foreign key FK5AF11D473026197F
drop table if exists Child
drop table if exists Parent
drop table if exists Parent_Child
create table Child (id bigint not null auto_increment, primary key (id))
create table Parent (id bigint not null auto_increment, primary key (id))
create table Parent_Child (Parent_id bigint not null, children_id bigint not null, primary key (Parent_id, children_id), unique (children_id))
alter table Parent_Child add index FK5AF11D472EC2DFD2 (children_id), add constraint FK5AF11D472EC2DFD2 foreign key (children_id) references Child (id)
alter table Parent_Child add index FK5AF11D473026197F (Parent_id), add constraint FK5AF11D473026197F foreign key (Parent_id) references Parent (id)
schema export complete
returning connection to pool, pool size: 1
Checking 0 named HQL queries
Checking 0 named SQL queries
opened session at timestamp: 11381308622
allowing method [beginTransaction] in non-transacted context
begin
opening JDBC connection
total checked-out connections: 0
using pooled JDBC connection, pool size: 0
current autocommit status: false
after transaction begin
saving transient instance
saving [org.aitools.Child#<null>]
executing insertions
Inserting entity: org.aitools.Child (native id)
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
insert into Child values ( )
Hibernate: insert into Child values ( )
preparing statement
Dehydrating entity: [org.aitools.Child#<null>]
Natively generated identity: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
saving transient instance
saving [org.aitools.Parent#<null>]
executing insertions
Wrapped collection in role: org.aitools.Parent.children
Inserting entity: org.aitools.Parent (native id)
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
insert into Parent values ( )
Hibernate: insert into Parent values ( )
preparing statement
Dehydrating entity: [org.aitools.Parent#<null>]
Natively generated identity: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
commit
automatically flushing session
flushing session
processing flush-time cascades
dirty checking collections
Flushing entities and processing referenced collections
Collection found: [org.aitools.Parent.children#1], was: [<unreferenced>] (initialized)
Processing unreferenced collections
Scheduling collection removes/(re)creates/updates
Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
Flushed: 1 (re)creations, 0 updates, 0 removals to 1 collections
listing entities:
org.aitools.Child{id=1}
org.aitools.Parent{children=[org.aitools.Child#1], id=1}
executing flush
Inserting collection: [org.aitools.Parent.children#1]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
insert into Parent_Child (Parent_id, children_id) values (?, ?)
Hibernate: insert into Parent_Child (Parent_id, children_id) values (?, ?)
preparing statement
binding '1' to parameter: 1
binding '1' to parameter: 2
Adding to batch
done inserting collection: 1 rows inserted
Executing batch size: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
post flush
before transaction completion
before transaction completion
committed JDBC Connection
after transaction completion
aggressively releasing JDBC connection
releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
returning connection to pool, pool size: 1
after transaction completion
automatically closing session
closing session
connection already null in cleanup : no action
opened session at timestamp: 11381308626
allowing method [beginTransaction] in non-transacted context
begin
opening JDBC connection
total checked-out connections: 0
using pooled JDBC connection, pool size: 0
current autocommit status: false
after transaction begin
id unsaved-value: null
detached instance of: org.aitools.Parent
merging detached instance
loading entity: [org.aitools.Parent#1]
attempting to resolve: [org.aitools.Parent#1]
object not resolved in any cache: [org.aitools.Parent#1]
Fetching entity: [org.aitools.Parent#1]
loading entity: [org.aitools.Parent#1]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
Hibernate: select parent0_.id as id0_0_ from Parent parent0_ where parent0_.id=?
preparing statement
binding '1' to parameter: 1
about to open ResultSet (open ResultSets: 0, globally: 0)
processing result set
result set row: 0
result row: EntityKey[org.aitools.Parent#1]
Initializing object from ResultSet: [org.aitools.Parent#1]
Hydrating entity: [org.aitools.Parent#1]
done processing result set (1 rows)
about to close ResultSet (open ResultSets: 1, globally: 1)
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
total objects hydrated: 1
resolving associations for [org.aitools.Parent#1]
creating collection wrapper:[org.aitools.Parent.children#1]
done materializing entity [org.aitools.Parent#1]
initializing non-lazy collections
done entity load
initializing collection [org.aitools.Parent.children#1]
checking second-level cache
collection not cached
loading collection: [org.aitools.Parent.children#1]
about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0_ from Parent_Child children0_ left outer join Child child1_ on chil
dren0_.children_id=child1_.id where children0_.Parent_id=?
Hibernate: select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0_ from Parent_Child children0_ left outer join Child chil
d1_ on children0_.children_id=child1_.id where children0_.Parent_id=?
preparing statement
binding '1' to parameter: 1
about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
closing statement
could not initialize a collection: [org.aitools.Parent.children#1] [select children0_.Parent_id as Parent1_1_, children0_.children_id as children2_1_, children0_.id as formula0_1_, child1_.id as id1_0
_ from Parent_Child children0_ left outer join Child child1_ on children0_.children_id=child1_.id where children0_.Parent_id=?]