Hibernate version: Hibernate 3
Hi Pravin here i am new to Hibernate using above hibernate verion i used the cascade="all" in mapping file and i have foreign key ralation. tables are : Eevents and Domains domains having foreign key of events so if i delete the record from Events table the relevent record in domains table should be deleted as i specified cascade="all"
[b]Mapping documents:<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="events.Domain" table="DOMAINS" lazy="true"> <id name="domains_Id" column="DOMAINS_ID" type="java.lang.String"> <generator class="uuid.hex"> <!-- To add non XDoclet generator parameters, create a file named hibernate-generator-params-Domain.xml containing the additional parameters and place it in your merge dir. --> </generator> </id> <property name="domains_Date" type="timestamp" update="true" insert="true" column="DOMAINS_DATE" /> <property name="domains_Name" type="java.lang.String" update="true" insert="true" column="DOMAINS_NAME" /> <many-to-one name="events" class="events.Events" cascade="none" outer-join="auto" update="true" insert="true" column="EVENT_ID" /> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-Domain.xml containing the additional properties and place it in your merge dir. --> </class> </hibernate-mapping>
AND
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="events.Domain" table="DOMAINS" lazy="true"> <id name="domains_Id" column="DOMAINS_ID" type="java.lang.String"> <generator class="uuid.hex"> <!-- To add non XDoclet generator parameters, create a file named hibernate-generator-params-Domain.xml containing the additional parameters and place it in your merge dir. --> </generator> </id> <property name="domains_Date" type="timestamp" update="true" insert="true" column="DOMAINS_DATE" /> <property name="domains_Name" type="java.lang.String" update="true" insert="true" column="DOMAINS_NAME" /> <many-to-one name="events" class="events.Events" cascade="none" outer-join="auto" update="true" insert="true" column="EVENT_ID" /> <!-- To add non XDoclet property mappings, create a file named hibernate-properties-Domain.xml containing the additional properties and place it in your merge dir. --> </class> </hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Events events = new Events(); events.setEvent_Id("8a9e829c1c2bcedb011c2bcedd420001"); session.delete(events); session.getTransaction().commit(); HibernateUtils.getSessionFactory().close();
Full stack trace of any exception that occurs: 11:57:11,965 INFO Environment:500 - Hibernate 3.2.0 11:57:11,981 INFO Environment:518 - loaded properties from resource hibernate.properties: {hibernate.connection.username=PRAVIN, hibernate.connection.password=****, hibernate.dialect=org.hibernate.dialect.OracleDialect, hibernate.connection.url=jdbc:oracle:thin:@10.30.2.34:1521:ORCL, hibernate.bytecode.use_reflection_optimizer=false, hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver, hibernate.current_session_context_class=thread} 11:57:11,981 INFO Environment:667 - Bytecode provider name : cglib 11:57:11,981 INFO Environment:584 - using JDK 1.4 java.sql.Timestamp handling 11:57:12,043 INFO Configuration:1350 - configuring from resource: /hibernate.cfg.xml 11:57:12,043 INFO Configuration:1327 - Configuration resource: /hibernate.cfg.xml 11:57:12,121 INFO Configuration:507 - Reading mappings from resource: events/Domain.hbm.xml 11:57:12,231 INFO HbmBinder:300 - Mapping class: events.Domain -> DOMAINS 11:57:12,309 INFO Configuration:507 - Reading mappings from resource: events/Events.hbm.xml 11:57:12,340 INFO HbmBinder:300 - Mapping class: events.Events -> EVENTS 11:57:12,340 INFO Configuration:507 - Reading mappings from resource: events/Person.hbm.xml 11:57:12,371 INFO HbmBinder:300 - Mapping class: events.Person -> PERSON 11:57:12,371 INFO HbmBinder:1412 - Mapping collection: events.Person.events -> PERSON_EVENTS 11:57:12,371 INFO Configuration:507 - Reading mappings from resource: events/Person_Events.hbm.xml 11:57:12,387 INFO HbmBinder:300 - Mapping class: events.Person_Events -> PERSON_EVENTS 11:57:12,403 INFO Configuration:1465 - Configured SessionFactory: null 11:57:12,403 INFO HbmBinder:2375 - Mapping collection: events.Events.domains -> DOMAINS 11:57:12,403 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!) 11:57:12,403 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20 11:57:12,403 INFO DriverManagerConnectionProvider:45 - autocommit mode: false 11:57:12,496 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.30.2.34:1521:ORCL 11:57:12,496 INFO DriverManagerConnectionProvider:86 - connection properties: {user=PRAVIN, password=****} 11:57:12,762 INFO SettingsFactory:81 - RDBMS: Oracle, version: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production With the Partitioning, OLAP and Data Mining options 11:57:12,762 INFO SettingsFactory:82 - JDBC driver: Oracle JDBC driver, version: 9.2.0.3.0 11:57:12,778 INFO Dialect:141 - Using dialect: org.hibernate.dialect.OracleDialect 11:57:12,793 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions) 11:57:12,793 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended) 11:57:12,793 INFO SettingsFactory:134 - Automatic flush during beforeCompletion(): disabled 11:57:12,793 INFO SettingsFactory:138 - Automatic session close at end of transaction: disabled 11:57:12,793 INFO SettingsFactory:145 - JDBC batch size: 15 11:57:12,793 INFO SettingsFactory:148 - JDBC batch updates for versioned data: disabled 11:57:12,793 INFO SettingsFactory:153 - Scrollable result sets: enabled 11:57:12,793 INFO SettingsFactory:161 - JDBC3 getGeneratedKeys(): disabled 11:57:12,793 INFO SettingsFactory:169 - Connection release mode: auto 11:57:12,793 INFO SettingsFactory:196 - Default batch fetch size: 1 11:57:12,793 INFO SettingsFactory:200 - Generate SQL with comments: disabled 11:57:12,793 INFO SettingsFactory:204 - Order SQL updates by primary key: disabled 11:57:12,793 INFO SettingsFactory:369 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory 11:57:12,793 INFO ASTQueryTranslatorFactory:24 - Using ASTQueryTranslatorFactory 11:57:12,793 INFO SettingsFactory:212 - Query language substitutions: {} 11:57:12,793 INFO SettingsFactory:217 - JPA-QL strict compliance: disabled 11:57:12,793 INFO SettingsFactory:222 - Second-level cache: enabled 11:57:12,793 INFO SettingsFactory:226 - Query cache: disabled 11:57:12,793 INFO SettingsFactory:356 - Cache provider: org.hibernate.cache.NoCacheProvider 11:57:12,809 INFO SettingsFactory:241 - Optimize cache for minimal puts: disabled 11:57:12,809 INFO SettingsFactory:250 - Structured second-level cache entries: disabled 11:57:12,809 INFO SettingsFactory:277 - Statistics: disabled 11:57:12,809 INFO SettingsFactory:281 - Deleted entity synthetic identifier rollback: disabled 11:57:12,809 INFO SettingsFactory:296 - Default entity-mode: pojo 11:57:12,840 INFO SessionFactoryImpl:161 - building session factory 11:57:13,153 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured 11:57:13,387 WARN JDBCExceptionReporter:71 - SQL Error: 2292, SQLState: 23000 11:57:13,387 ERROR JDBCExceptionReporter:72 - ORA-02292: integrity constraint (PRAVIN.FK_EVENTS) violated - child record found
11:57:13,387 WARN JDBCExceptionReporter:71 - SQL Error: 2292, SQLState: 23000 11:57:13,387 ERROR JDBCExceptionReporter:72 - ORA-02292: integrity constraint (PRAVIN.FK_EVENTS) violated - child record found
11:57:13,387 ERROR AbstractFlushingEventListener:301 - Could not synchronize database state with session org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at events.Startup.main(Startup.java:53) Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (PRAVIN.FK_EVENTS) violated - child record found
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:460) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242) ... 8 more Exception in thread "main" org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106) at events.Startup.main(Startup.java:53) Caused by: java.sql.BatchUpdateException: ORA-02292: integrity constraint (PRAVIN.FK_EVENTS) violated - child record found
at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:460) at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242) ... 8 more
Name and version of the database you are using:
Oracle10g
_________________ Learning Hibernate
|