Ok, I have a bit more information now.
I start off with a completely empty database - no tables, no constraints, nothing.
I call my code, which results in the incorrectly created constraints, and the logging output below.
The logging output below has the correct SQL for generating the constraints, but immediately complains that the constraints already exist.
The contraints now exist in the database - they have been created incorrectly again.
This makes me believe that the constraints are being created elsewhere, and the SQL for this is not being logged. They are definitely being created by Hibernate as I delete them from the database each time.
The constraint Hibernate tries to generate according to the log
Code:
alter table USERS_TO_GROUPS add constraint FK92935E81F73AEE0F foreign key (USER_ID) references USERS
The constraint Hibernate has already created in the database:
Code:
ALTER TABLE USERS_TO_GROUPS ADD (
CONSTRAINT FK92935E81F73AEE0F FOREIGN KEY (USER_ID)
REFERENCES GROUPS (GROUP_ID));
Code:
Jan 17, 2005 9:22:42 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Jan 17, 2005 9:22:42 AM net.sf.ehcache.config.Configurator configure
WARNING: No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: file:/home/colin/.netbeans/4.0/jakarta-tomcat-5.0.28_base/work/Catalina/localhost/prototype/loader/ehcache-failsafe.xml
Jan 17, 2005 9:22:42 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Jan 17, 2005 9:22:42 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.Oracle9Dialect
Jan 17, 2005 9:22:42 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Jan 17, 2005 9:22:42 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Jan 17, 2005 9:22:42 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Jan 17, 2005 9:22:42 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: oracle.jdbc.driver.OracleDriver at URL: jdbc:oracle:thin:@10.0.0.124:1521:bcgbdev1
Jan 17, 2005 9:22:42 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=colin, password=****}
Jan 17, 2005 9:22:42 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
Jan 17, 2005 9:22:42 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
Jan 17, 2005 9:22:42 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
Jan 17, 2005 9:22:42 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
Jan 17, 2005 9:22:42 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
Jan 17, 2005 9:22:42 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
Jan 17, 2005 9:22:42 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: ROLES
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS_TO_CHILD_GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS_TO_ROLES
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: USERS_TO_GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: USERS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: ROLES
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS_TO_CHILD_GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUPS_TO_ROLES
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: USERS_TO_GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: USERS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: ROLE_ID_SEQ
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: USER_ID_SEQ
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
INFO: table not found: GROUP_ID_SEQ
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: alter table GROUPS_TO_ROLES add constraint FK3DB0ADE41E2E76DB foreign key (GROUP_ID) references GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: ORA-02264: name already used by an existing constraint
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: alter table GROUPS_TO_ROLES add constraint FK3DB0ADE452119584 foreign key (ROLE_ID) references ROLES
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: ORA-02264: name already used by an existing constraint
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: alter table USERS_TO_GROUPS add constraint FK92935E811E2E76DB foreign key (GROUP_ID) references GROUPS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: ORA-02264: name already used by an existing constraint
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: Unsuccessful: alter table USERS_TO_GROUPS add constraint FK92935E81F73AEE0F foreign key (USER_ID) references USERS
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
SEVERE: ORA-02264: name already used by an existing constraint
Jan 17, 2005 9:22:43 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
Jan 17, 2005 9:22:43 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:oracle:thin:@10.0.0.124:1521:bcgbdev1
Jan 17, 2005 9:22:43 AM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
...
Jan 17, 2005 9:22:44 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2291, SQLState: 23000
Jan 17, 2005 9:22:44 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02291: integrity constraint (COLIN.FK3DB0ADE41E2E76DB) violated - parent key not found
Jan 17, 2005 9:22:44 AM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 2291, SQLState: 23000
Jan 17, 2005 9:22:44 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-02291: integrity constraint (COLIN.FK3DB0ADE41E2E76DB) violated - parent key not found
Jan 17, 2005 9:22:44 AM org.hibernate.event.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:155)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:69)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:65)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:125)
at org.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:692)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:23)
at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:255)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:814)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:75)