[b]Hibernate version: 3.2
[b]Mapping documents
Code:
:[<?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 auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class discriminator-value="[uk.gov.nationalarchives.xip.TypeFile]"
name="uk.gov.nationalarchives.xip.TypeFile"
table="DIGITALFILE">
<id name="FileRef">
<column name="FILEREF"/>
<type name="org.hibernate.type.StringType"/>
</id>
<property name="WorkingPath" type="org.hibernate.type.StringType">
<column name="FILELOCATION" />
</property>
<property name="FileName" type="org.hibernate.type.StringType" >
<column name="NAME" not-null="true"/>
</property>
<property name="FileSize" type="org.hibernate.type.LongType">
<column name="FILESIZE" />
</property>
<property access="com.tessella.sdb.core.metadatastore2.GregorianCalendarAccessor"
name="LastModifiedDate">
<column name="LASTMODIFIEDDATE"/>
<type name="org.hibernate.type.DateType"/>
</property>
<property name="IngestedFileSetRef" type="org.hibernate.type.StringType">
<column name="INGESTEDFILESETREF" />
</property>
<property name="Extant" type="org.hibernate.type.BooleanType">
<column name="EXTANT" not-null="true"/>
</property>
<property name="Valid" type="org.hibernate.type.BooleanType">
<column name="DELETED" />
</property>
<property name="Directory" type="org.hibernate.type.BooleanType">
<column name="DIRECTORY" />
</property>
<bag name="fileProperty" access="field" table="DIGITALFILEPROPERTY" cascade="all-delete-orphan">
<key column="FILEREF" not-null="true" />
<one-to-many class="uk.gov.nationalarchives.xip.TypeFileProperty" not-found="ignore"/>
</bag>
<bag name="fixityInfo" access="field" table="DIGITALFILEFIXITYINFO" cascade="all-delete-orphan">
<key column="FILEREF" not-null="true" />
<one-to-many class="uk.gov.nationalarchives.xip.TypeFixityInfo" not-found="ignore"/>
</bag>
<bag name="formatInfo" access="field" table="DIGITALFILEFORMAT" cascade="all-delete-orphan">
<key column="FILEREF" not-null="true" />
<one-to-many class="uk.gov.nationalarchives.xip.TypeFormatInfo" not-found="ignore"/>
</bag>
<join
table="XMLMetadata">
<key>
<column name="METADATAREF"/>
</key>
<property access="com.tessella.sdb.core.metadatastore2.FileMetadataAccessor"
name="Metadata" type="org.hibernate.type.StringClobType" column="METADATA"/>
</join>
</class>
</hibernate-mapping>]
Code:
:<?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 auto-import="false" default-cascade="all-delete-orphan" default-lazy="false">
<class discriminator-value="[uk.gov.nationalarchives.xip.TypeDeliverableUnit]"
name="uk.gov.nationalarchives.xip.TypeDeliverableUnit"
table="DELIVERABLEUNIT">
<id name="DeliverableUnitRef">
<column name="DELIVERABLEUNITREF"/>
<type name="org.hibernate.type.StringType"/>
</id>
<property name="CollectionRef" type="org.hibernate.type.StringType">
<column name="COLLECTIONREF"/>
</property>
<property name="ParentRef" type="org.hibernate.type.StringType">
<column name="PARENTREF"/>
</property>
<property name="AccessionRef" type="org.hibernate.type.StringType">
<column name="ACCESSIONREF"/>
</property>
<property name="CatalogueReference" type="org.hibernate.type.StringType">
<column name="CATALOGUEREFERENCE"/>
</property>
<property name="ScopeAndContent" type="org.hibernate.type.StringType">
<column name="DESCRIPTION"/>
</property>
<property name="ClosureType" type="org.hibernate.type.StringType">
<column name="CLOSURE"/>
</property>
<property access="com.tessella.sdb.core.metadatastore2.CFromAccessor"
name="CoverageFrom" type="org.hibernate.type.DateType">
<column name="COVERAGEFROM"/>
</property>
<property access="com.tessella.sdb.core.metadatastore2.CToAccessor"
name="CoverageTo" type="org.hibernate.type.DateType">
<column name="COVERAGETO"/>
</property>
<property name="TypeRef" type="org.hibernate.type.LongType">
<column name="TYPEREF"/>
</property>
<bag name="deliverableUnitComponent" access="field" table="DELIVERABLEUNITCOMPONENT" cascade="all-delete-orphan">
<key column="DELIVERABLEUNITREF" not-null="true" />
<one-to-many class="uk.gov.nationalarchives.xip.TypeDeliverableUnitComponent" not-found="ignore"/>
</bag>
<join
table="XMLMetadata">
<key>
<column name="MetadataRef"/>
</key>
<property access="com.tessella.sdb.core.metadatastore2.DUMetadataAccessor"
name="Metadata" type="org.hibernate.type.StringClobType" column="METADATA">
</property>
</join>
</class>
</hibernate-mapping>
Log:2008-08-20 08:52:47,785 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648]; startup date [Wed Aug 20 08:52:47 BST 2008]; root of context hierarchy>
2008-08-20 08:52:47,832 DEBUG [org.springframework.util.ClassUtils] - <Class [edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap] or one of its dependencies is not present: java.lang.ClassNotFoundException: edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap>
2008-08-20 08:52:47,879 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [com/tessella/sdb/core/metadatastore2/beans.xml]>
2008-08-20 08:52:47,910 DEBUG [org.springframework.beans.factory.xml.DefaultDocumentLoader] - <Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]>
2008-08-20 08:52:47,942 DEBUG [org.springframework.beans.factory.xml.PluggableSchemaResolver] - <Loading schema mappings from [META-INF/spring.schemas]>
2008-08-20 08:52:47,957 DEBUG [org.springframework.beans.factory.xml.PluggableSchemaResolver] - <Loaded schema mappings: {http://www.springframework.org/schema/lang/spring-lang-2.5.xsd=org/springframework/scripting/config/spring-lang-2.5.xsd,
http://www.springframework.org/schema/l ... ng-2.5.xsd,
http://www.springframework.org/schema/c ... xt-2.5.xsd,
http://www.springframework.org/schema/j ... ms-2.5.xsd,
http://www.springframework.org/schema/c ... xt-2.5.xsd,
http://www.springframework.org/schema/a ... op-2.5.xsd,
http://www.springframework.org/schema/u ... il-2.0.xsd,
http://www.springframework.org/schema/u ... il-2.5.xsd,
http://www.springframework.org/schema/t ... ol-2.0.xsd,
http://www.springframework.org/schema/t ... tx-2.0.xsd,
http://www.springframework.org/schema/t ... ol-2.5.xsd,
http://www.springframework.org/schema/t ... tx-2.5.xsd,
http://www.springframework.org/schema/b ... ns-2.0.xsd,
http://www.springframework.org/schema/j ... ms-2.5.xsd,
http://www.springframework.org/schema/b ... ns-2.5.xsd,
http://www.springframework.org/schema/b ... ns-2.5.xsd,
http://www.springframework.org/schema/j ... ee-2.5.xsd,
http://www.springframework.org/schema/t ... ol-2.5.xsd,
http://www.springframework.org/schema/t ... tx-2.5.xsd,
http://www.springframework.org/schema/j ... ee-2.0.xsd,
http://www.springframework.org/schema/a ... op-2.0.xsd,
http://www.springframework.org/schema/a ... op-2.5.xsd,
http://www.springframework.org/schema/j ... ee-2.5.xsd,
http://www.springframework.org/schema/l ... ng-2.0.xsd,
http://www.springframework.org/schema/u ... il-2.5.xsd}>
2008-08-20 08:52:47,957 DEBUG [org.springframework.beans.factory.xml.PluggableSchemaResolver] - <Found XML schema [http://www.springframework.org/schema/beans/spring-beans-2.5.xsd] in classpath: org/springframework/beans/factory/xml/spring-beans-2.5.xsd>
2008-08-20 08:52:48,067 DEBUG [org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader] - <Loading bean definitions>
2008-08-20 08:52:48,129 DEBUG [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loaded 2 bean definitions from location pattern [classpath:com/tessella/sdb/core/metadatastore2/beans.xml]>
2008-08-20 08:52:48,129 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648]: org.springframework.beans.factory.support.DefaultListableBeanFactory@ff2413>
2008-08-20 08:52:48,129 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] - <2 beans defined in org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648]; startup date [Wed Aug 20 08:52:47 BST 2008]; root of context hierarchy>
2008-08-20 08:52:48,176 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] - <Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@4f459c]>
2008-08-20 08:52:48,176 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] - <Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@1b5998f]>
2008-08-20 08:52:48,176 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@ff2413: defining beans [dataSource,sessionFactory]; root of factory hierarchy>
2008-08-20 08:52:48,176 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Creating shared instance of singleton bean 'dataSource'>
2008-08-20 08:52:48,192 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Creating instance of bean 'dataSource' with merged definition [Root bean: class [org.apache.commons.dbcp.BasicDataSource]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=close; defined in class path resource [com/tessella/sdb/core/metadatastore2/beans.xml]]>
2008-08-20 08:52:48,223 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Eagerly caching bean 'dataSource' to allow for resolving potential circular references>
2008-08-20 08:52:48,270 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Creating shared instance of singleton bean 'sessionFactory'>
2008-08-20 08:52:48,270 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Creating instance of bean 'sessionFactory' with merged definition [Root bean: class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]; scope=singleton; abstract=false; lazyInit=false; autowireCandidate=true; autowireMode=0; dependencyCheck=0; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null; defined in class path resource [com/tessella/sdb/core/metadatastore2/beans.xml]]>
2008-08-20 08:52:48,317 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Eagerly caching bean 'sessionFactory' to allow for resolving potential circular references>
2008-08-20 08:52:48,317 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Returning cached instance of singleton bean 'dataSource'>
2008-08-20 08:52:48,864 INFO [org.springframework.orm.hibernate3.LocalSessionFactoryBean] - <Building new Hibernate SessionFactory>
2008-08-20 08:52:51,803 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] - <Publishing event in context [org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648]: org.springframework.context.event.ContextRefreshedEvent[source=org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1ee4648]; startup date [Wed Aug 20 08:52:47 BST 2008]; root of context hierarchy]>
2008-08-20 08:52:51,834 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Returning cached instance of singleton bean 'sessionFactory'>
8
2008-08-20 08:52:52,554 DEBUG [org.springframework.orm.hibernate3.SessionFactoryUtils] - <Opening Hibernate Session>
2008-08-20 08:52:52,804 DEBUG [org.springframework.orm.hibernate3.HibernateTemplate] - <Eagerly flushing Hibernate session>
2008-08-20 08:52:52,882 WARN [org.hibernate.util.JDBCExceptionReporter] - <SQL Error: 2291, SQLState: 23000>
2008-08-20 08:52:52,882 ERROR [org.hibernate.util.JDBCExceptionReporter] - <ORA-02291: integrity constraint (STORE.FK960D4C4636791A0B) violated - parent key not found
>
2008-08-20 08:52:52,897 ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - <Could not synchronize database state with session>
org.hibernate.exception.ConstraintViolationException: could not insert: [uk.gov.nationalarchives.xip.TypeFile]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:693)
at com.tessella.sdb.core.metadatastore2.Store.main(Store.java:53)
Caused by: java.sql.SQLException: ORA-02291: integrity constraint (STORE.FK960D4C4636791A0B) violated - parent key not found
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1169)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2250)
... 12 more
2008-08-20 08:52:52,897 DEBUG [org.springframework.orm.hibernate3.SessionFactoryUtils] - <Closing Hibernate Session>
Exception in thread "main" org.springframework.dao.DataIntegrityViolationException: could not insert: [uk.gov.nationalarchives.xip.TypeFile]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [uk.gov.nationalarchives.xip.TypeFile]
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:622)
at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:412)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:378)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:693)
at com.tessella.sdb.core.metadatastore2.Store.main(Store.java:53)
Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [uk.gov.nationalarchives.xip.TypeFile]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:374)
... 2 more
Caused by: java.sql.SQLException: ORA-02291: integrity constraint (STORE.FK960D4C4636791A0B) violated - parent key not found
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:955)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1169)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:3368)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2250)
... 12 more
I have lots of classes which contain a property, Metadata.
I wish to create, for each of these classes, a MetadataRef which is just a unique number and then a seperate table holding the metadatarefs and the metadata from all the classes. The metadataref will also be held in the original class tables.
I can only alter the mapping files becuase the java classes are automatically generated from the database i'm working from. The java classes contain the property Metadata but that is all.
Using the idea shown in the above mapping file with a <join> table doesn't work. The key property uses the id from the class - which can't be used as the metadata-ref becuase these are only unique within the class.
If anyone has any ideas I'd be gratefull to hear them as this has rather stumped us.
Is it possible to generate a key for the MetadataRef in the relevant classes without having to add anything to the java classes? And then is it possible to reference this key rather than the primary key in the <join> table?
Is there another way of doing this?
Thank you.