| hibernate version:2.1.2db version:hsqldb,1.7.2
 eclipse version:3.0
 when i cascade insert the parent/child ,there are not problems,but when i delete the parent,and i want delete child auto.there are problem,pls see the log.help me pls.Thanks
 the following is my code(all the other is generated by eclipse plug in the Hibernate Synchronizer):
 Parent.hbm.xml
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
 <hibernate-mapping
 package="org.hibernate.auction.model">
 <class name="Parent" table="ParentTable">
 <id type="int" name="id" unsaved-value="0">
 <generator class="assigned"/>
 </id>
 <property type="java.lang.String" name="userName" not-null="true"/>
 <property type="java.lang.String" name="password" column="password"/>
 <property type="java.lang.String" name="email"/>
 <bag name="childs" inverse="true" cascade="all">
 <key column="parent_id"/>
 <one-to-many class="Child"/>
 </bag>
 </class>
 </hibernate-mapping>
 Child.hbm.xml
 <?xml version="1.0"?>
 <!DOCTYPE hibernate-mapping PUBLIC
 "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
 "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
 <hibernate-mapping
 package="org.hibernate.auction.model" >
 <class name="Child" >
 <id type="int" name="id" unsaved-value="0">
 <generator class="native"/>
 </id>
 <property type="java.lang.String" name="description"/>
 <property type="java.util.Date" name="ends"/>
 <property type="int" name="condition"/>
 <many-to-one class="Parent" name="parent_id" not-null="true"/>
 </class>
 </hibernate-mapping>
 ParentDAO.java
 package org.hibernate.auction.model.dao;
 
 import java.util.ArrayList;
 import java.util.Date;
 
 import org.hibernate.auction.model.Child;
 import org.hibernate.auction.model.Parent;
 import org.hibernate.auction.model.base.BaseParentDAO;
 
 /**
 * This is the DAO class for Parent.  Any customizations
 * specific to this class belong here.
 */
 public class ParentDAO extends BaseParentDAO {
 public static void main(String[] args)
 {
 
 Parent parent = new Parent();
 parent.setId(2003);
 parent.setUserName("oldirty");
 parent.setEmail("oldirty@hibernate.org");
 parent.setChilds( new ArrayList() );
 
 Child child = new Child();
 child.setDescription("auction item ");
 child.setEnds( new Date() );
 child.setCondition(2);
 child.setParent_id(parent);
 
 parent.getChilds().add(child);
 try {
 ParentDAO parentDAO=new ParentDAO();
 _RootDAO.initialize();
 parentDAO.save(parent);			parentDAO.delete(parent);
 } catch (Exception e) {
 e.printStackTrace();
 }
 
 }
 }
 
 BaseParent.java
 package org.hibernate.auction.model.base;
 
 import java.io.Serializable;
 import java.util.ArrayList;
 
 /**
 * This is an object that contains data related to the ParentTable table.
 * Do not modify this class because it will be overwritten if the configuration file
 * related to this class is modified.
 * For more information visit <a href="http://hibernatesynch.sourceforge.net">
 * The Hibernate Synchronizer page</a>, or contact
 * <a href="mailto: jhudson8.users.sourceforge.net">Joe Hudson</a>
 *
 * @hibernate.class
 *  table="ParentTable"
 */
 
 public abstract class BaseParent   implements Serializable {
 
 private int hashCode = Integer.MIN_VALUE;
 
 // primary key
 private int id;
 
 // fields
 private java.lang.String userName;
 private java.lang.String password;
 private java.lang.String email;
 
 // collections
 private java.util.Collection childs;
 
 // constructors
 public BaseParent () {}
 
 /**
 * Constructor for primary key
 */
 public BaseParent (int id) {
 this.setId(id);
 }
 
 /**
 * Constructor for required fields
 */
 public BaseParent (
 int id,
 java.lang.String userName	) {
 
 this.setId(id);
 this.setUserName(userName);
 }
 
 /**
 * Return the unique identifier of this class
 * @hibernate.id
 *  generator-class="assigned"
 *  column="id"
 */
 public int getId () {
 return id;
 }
 
 /**
 * Set the unique identifier of this class
 * @param id the new ID
 */
 public void setId (int id) {
 this.id = id;
 this.hashCode = Integer.MIN_VALUE;
 }
 
 /**
 * @hibernate.property
 *  column=userName
 * not-null=true
 */
 public java.lang.String getUserName () {
 return this.userName;
 }
 
 /**
 * Set the value related to the column: userName
 * @param userName the userName value
 */
 public void setUserName (java.lang.String userName) {
 this.userName = userName;
 }
 
 /**
 * @hibernate.property
 *  column=password
 */
 public java.lang.String getPassword () {
 return this.password;
 }
 
 /**
 * Set the value related to the column: password
 * @param password the password value
 */
 public void setPassword (java.lang.String password) {
 this.password = password;
 }
 
 /**
 * @hibernate.property
 *  column=email
 */
 public java.lang.String getEmail () {
 return this.email;
 }
 
 /**
 * Set the value related to the column: email
 * @param email the email value
 */
 public void setEmail (java.lang.String email) {
 this.email = email;
 }
 
 public java.util.Collection getChilds () {
 return this.childs;
 }
 
 public void setChilds (java.util.Collection childs) {
 this.childs = childs;
 }
 
 public void addToChilds (Object obj) {
 if (null == this.childs) this.childs = new ArrayList();
 this.childs.add(obj);
 }
 
 
 public boolean equals (Object obj) {
 if (null == obj) return false;
 if (!(obj instanceof org.hibernate.auction.model.base.BaseParent)) return false;
 else {
 org.hibernate.auction.model.base.BaseParent mObj = (org.hibernate.auction.model.base.BaseParent) obj;
 return (this.getId() == mObj.getId());
 }
 }
 
 public int hashCode () {
 if (Integer.MIN_VALUE == this.hashCode) {
 return (int) this.getId();
 }
 return this.hashCode;
 }
 
 }
 
 Execute the ParendDAO.java will show the following
 2004-4-10 10:56:09 net.sf.hibernate.cfg.Environment <clinit>
 信息: Hibernate 2.1.2
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Environment <clinit>
 信息: loaded properties from resource hibernate.properties: {hibernate.c3p0.acquire_increment=2, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', hibernate.c3p0.idle_test_period=3000, hibernate.show_sql=true, hibernate.proxool.pool_alias=pool1, hibernate.c3p0.max_statements=100, hibernate.jdbc.batch_size=0, hibernate.c3p0.validate=false, hibernate.c3p0.timeout=5000, hibernate.hbm2ddl.auto=update, hibernate.cache.use_query_cache=true, hibernate.c3p0.min_size=2, hibernate.jdbc.use_streams_for_binary=true, hibernate.max_fetch_depth=1, hibernate.cache.provider_class=net.sf.hibernate.cache.HashtableCacheProvider, hibernate.c3p0.max_size=2, hibernate.connection.provider_class=net.sf.hibernate.connection.C3P0ConnectionProvider, hibernate.cglib.use_reflection_optimizer=true}
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Environment <clinit>
 信息: using java.io streams to persist binary types
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Environment <clinit>
 信息: using CGLIB reflection optimizer
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Configuration configure
 信息: configuring from resource: /hibernate.cfg.xml
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
 信息: Configuration resource: /hibernate.cfg.xml
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Configuration addResource
 信息: Mapping resource: org/hibernate/auction/model/AuctionItem.hbm.xml
 2004-4-10 10:56:10 net.sf.hibernate.cfg.Binder bindRootClass
 信息: Mapping class: org.hibernate.auction.model.AuctionItem -> AuctionItem
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration addResource
 信息: Mapping resource: org/hibernate/auction/model/User.hbm.xml
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindRootClass
 信息: Mapping class: org.hibernate.auction.model.User -> AuctionUser
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration addResource
 信息: Mapping resource: org/hibernate/auction/model/TestID.hbm.xml
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindRootClass
 信息: Mapping class: org.hibernate.auction.model.TestID -> TestID
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration addResource
 信息: Mapping resource: org/hibernate/auction/model/Child.hbm.xml
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindRootClass
 信息: Mapping class: org.hibernate.auction.model.Child -> Child
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration addResource
 信息: Mapping resource: org/hibernate/auction/model/Parent.hbm.xml
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindRootClass
 信息: Mapping class: org.hibernate.auction.model.Parent -> ParentTable
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration doConfigure
 信息: Configured SessionFactory: null
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-many association mappings
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
 信息: Mapping collection: org.hibernate.auction.model.User.auctions -> AuctionItem
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
 信息: Mapping collection: org.hibernate.auction.model.Parent.childs -> Child
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-one association property references
 2004-4-10 10:56:11 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing foreign key constraints
 2004-4-10 10:56:11 net.sf.hibernate.dialect.Dialect <init>
 信息: Using dialect: net.sf.hibernate.dialect.HSQLDialect
 2004-4-10 10:56:11 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Maximim outer join fetch depth: 1
 2004-4-10 10:56:11 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Use outer join fetching: true
 2004-4-10 10:56:11 net.sf.hibernate.connection.ConnectionProviderFactory newConnectionProvider
 信息: Initializing connection provider: net.sf.hibernate.connection.C3P0ConnectionProvider
 2004-4-10 10:56:11 net.sf.hibernate.connection.C3P0ConnectionProvider configure
 信息: C3P0 using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
 2004-4-10 10:56:11 net.sf.hibernate.connection.C3P0ConnectionProvider configure
 信息: Connection properties: {user=sa, password=}
 2004-4-10 10:56:11 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
 信息: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
 Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@cdb06e [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@ef137d [ acquireIncrement -> 2, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 2, maxIdleTime -> 5000, maxPoolSize -> 2, maxStatements -> 100, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@1fa1bb6 [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:hsqldb:hsql://localhost, properties -> {user=sa, password=} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
 2004-4-10 10:56:11 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Use scrollable result sets: true
 2004-4-10 10:56:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Use JDBC3 getGeneratedKeys(): false
 2004-4-10 10:56:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Optimize cache for minimal puts: false
 2004-4-10 10:56:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: echoing all SQL to stdout
 2004-4-10 10:56:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: Query language substitutions: {no='N', true=1, yes='Y', false=0}
 2004-4-10 10:56:12 net.sf.hibernate.cfg.SettingsFactory buildSettings
 信息: cache provider: net.sf.hibernate.cache.HashtableCacheProvider
 2004-4-10 10:56:12 net.sf.hibernate.cfg.Configuration configureCaches
 信息: instantiating and configuring caches
 2004-4-10 10:56:12 net.sf.hibernate.impl.SessionFactoryImpl <init>
 信息: building session factory
 2004-4-10 10:56:13 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
 信息: no JNDI name configured
 2004-4-10 10:56:13 net.sf.hibernate.dialect.Dialect <init>
 信息: Using dialect: net.sf.hibernate.dialect.HSQLDialect
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-many association mappings
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-one association property references
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing foreign key constraints
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-many association mappings
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing one-to-one association property references
 2004-4-10 10:56:13 net.sf.hibernate.cfg.Configuration secondPassCompile
 信息: processing foreign key constraints
 2004-4-10 10:56:13 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
 信息: Running hbm2ddl schema export
 2004-4-10 10:56:13 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
 信息: exporting generated schema to database
 2004-4-10 10:56:13 net.sf.hibernate.connection.ConnectionProviderFactory newConnectionProvider
 信息: Initializing connection provider: net.sf.hibernate.connection.C3P0ConnectionProvider
 2004-4-10 10:56:13 net.sf.hibernate.connection.C3P0ConnectionProvider configure
 信息: C3P0 using driver: org.hsqldb.jdbcDriver at URL: jdbc:hsqldb:hsql://localhost
 2004-4-10 10:56:13 net.sf.hibernate.connection.C3P0ConnectionProvider configure
 信息: Connection properties: {user=sa, password=}
 Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@b02928 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@364641 [ acquireIncrement -> 2, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, idleConnectionTestPeriod -> 3000, initialPoolSize -> 2, maxIdleTime -> 5000, maxPoolSize -> 2, maxStatements -> 100, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@15e234c [ description -> null, driverClass -> null, factoryClassLocation -> null, jdbcUrl -> jdbc:hsqldb:hsql://localhost, properties -> {user=sa, password=} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , factoryClassLocation -> null, numHelperThreads -> 3 ]
 2004-4-10 10:56:13 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
 严重: Unsuccessful: create table ParentTable (id INTEGER not null, userName VARCHAR(255) not null, password VARCHAR(255), email VARCHAR(255), primary key (id))
 2004-4-10 10:56:13 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
 严重: connection is broken
 2004-4-10 10:56:13 net.sf.hibernate.tool.hbm2ddl.SchemaExport execute
 信息: schema export complete
 2004-4-10 10:56:13 net.sf.hibernate.cache.UpdateTimestampsCache <init>
 信息: starting update timestamps cache at region: net.sf.hibernate.cache.UpdateTimestampsCache
 2004-4-10 10:56:13 net.sf.hibernate.cache.QueryCache <init>
 信息: starting query cache at region: net.sf.hibernate.cache.QueryCache
 Hibernate: insert into ParentTable (userName, password, email, id) values (?, ?, ?, ?)
 Hibernate: insert into Child (description, ends, condition, parent_id, id) values (?, ?, ?, ?, null)
 Hibernate: CALL IDENTITY()
 Hibernate: delete from ParentTable where id=?2004-4-10 10:56:13 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
 警告: SQL Error: 0, SQLState: null
 2004-4-10 10:56:13 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
 严重: connection is broken
 2004-4-10 10:56:13 net.sf.hibernate.JDBCException <init>
 严重: could not delete: [org.hibernate.auction.model.Parent#2003]
 java.sql.SQLException: connection is broken
 at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
 at org.hsqldb.jdbcConnection.execute(Unknown Source)
 at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
 at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
 at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
 at com.mchange.v2.sql.filter.FilterCallableStatement.executeUpdate(FilterCallableStatement.java:309)
 at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
 at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:598)
 at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
 at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
 at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
 at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
 at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
 at org.hibernate.auction.model.dao._RootDAO.delete(_RootDAO.java:346)
 at org.hibernate.auction.model.base.BaseParentDAO.delete(BaseParentDAO.java:101)
 at org.hibernate.auction.model.dao.ParentDAO.main(ParentDAO.java:38)
 2004-4-10 10:56:13 net.sf.hibernate.impl.SessionImpl execute
 严重: Could not synchronize database state with session
 net.sf.hibernate.JDBCException: could not delete: [org.hibernate.auction.model.Parent#2003]
 at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:617)
 at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
 at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
 at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
 at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
 at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
 at org.hibernate.auction.model.dao._RootDAO.delete(_RootDAO.java:346)
 at org.hibernate.auction.model.base.BaseParentDAO.delete(BaseParentDAO.java:101)
 at org.hibernate.auction.model.dao.ParentDAO.main(ParentDAO.java:38)
 Caused by: java.sql.SQLException: connection is broken
 at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
 at org.hsqldb.jdbcConnection.execute(Unknown Source)
 at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
 at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
 at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
 at com.mchange.v2.sql.filter.FilterCallableStatement.executeUpdate(FilterCallableStatement.java:309)
 at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
 at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:598)
 ... 8 more
 net.sf.hibernate.JDBCException: could not delete: [org.hibernate.auction.model.Parent#2003]
 at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:617)
 at net.sf.hibernate.impl.ScheduledDeletion.execute(ScheduledDeletion.java:29)
 at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
 at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2340)
 at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
 at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
 at org.hibernate.auction.model.dao._RootDAO.delete(_RootDAO.java:346)
 at org.hibernate.auction.model.base.BaseParentDAO.delete(BaseParentDAO.java:101)
 at org.hibernate.auction.model.dao.ParentDAO.main(ParentDAO.java:38)
 Caused by: java.sql.SQLException: connection is broken
 at org.hsqldb.jdbcConnection.executeHSQL(Unknown Source)
 at org.hsqldb.jdbcConnection.execute(Unknown Source)
 at org.hsqldb.jdbcStatement.fetchResult(Unknown Source)
 at org.hsqldb.jdbcStatement.executeUpdate(Unknown Source)
 at org.hsqldb.jdbcPreparedStatement.executeUpdate(Unknown Source)
 at com.mchange.v2.sql.filter.FilterCallableStatement.executeUpdate(FilterCallableStatement.java:309)
 at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
 at net.sf.hibernate.persister.EntityPersister.delete(EntityPersister.java:598)
 ... 8 more
 
 
 |