cancel
Showing results for 
Search instead for 
Did you mean: 

Adding custom hibernate mappings (hbm.xml) to Alfresco

jzulu2000
Champ in-the-making
Champ in-the-making
Hi

I'm trying to add some custom hibernate mapping files to alfresco, and I don't know how to do this.

Any helps?

I tried overriding the sessionFactoryBase bean definition in a custom hibernate context file, but I had to re-define the bean entirely to ad my new mapping… something like this…
    <bean id="sessionFactoryBase" abstract="true">
        <property name="schemaUpdate">
           <value>false</value>
        </property>
        <property name="mappingResources">
            <list>
                <!–  –>
                <!– My custom mapping –>
                <!–  –>
                <value>co/com/arkimia/alfresco/repo/audit/hibernate/SearchAudit.hbm.xml</value>

                <!–  –>
                <!– Alfresco Node Storage –>
                <!–  –>
               
                <value>org/alfresco/repo/domain/hibernate/Node.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Store.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Transaction.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/VersionCount.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml</value>
                <value>org/alfresco/repo/domain/hibernate/Permission.hbm.xml</value>
                <value>org/alfresco/repo/avm/hibernate/AVM.hbm.xml</value>
                <value>org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml</value>
               
                <!– Audit config –>
                <!– TODO: Move into org/alfresco/repo/domain/hibernate/ –>
                <value>org/alfresco/repo/audit/hibernate/Audit.hbm.xml</value>

                <!–  –>
                <!– JBoss jBPM Workflow Engine –>
                <!–  –>
                <!– TODO: Determine if it's possible to inject the following mappings –>
                <!–       from elsewhere –>
                <!–  –>
                <value>org/jbpm/graph/action/Script.hbm.xml</value>
                <value>org/jbpm/db/hibernate.queries.hbm.xml</value>
                <value>org/jbpm/graph/def/ProcessDefinition.hbm.xml</value>
                <value>org/jbpm/graph/def/Node.hbm.xml</value>
                <value>org/jbpm/graph/def/Transition.hbm.xml</value>
                <value>org/jbpm/graph/def/Event.hbm.xml</value>
                <value>org/jbpm/graph/def/Action.hbm.xml</value>
                <value>org/jbpm/graph/def/SuperState.hbm.xml</value>
                <value>org/jbpm/graph/def/ExceptionHandler.hbm.xml</value>
                <value>org/jbpm/instantiation/Delegation.hbm.xml</value>
                <value>org/jbpm/graph/node/StartState.hbm.xml</value>
                <value>org/jbpm/graph/node/EndState.hbm.xml</value>
                <value>org/jbpm/graph/node/ProcessState.hbm.xml</value>
                <value>org/jbpm/graph/node/Decision.hbm.xml</value>
                <value>org/jbpm/graph/node/Fork.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.Join.hbm.xml</value>
                <value>org/jbpm/graph/node/State.hbm.xml</value>
                <value>org/jbpm/graph/node/TaskNode.hbm.xml</value>
                <value>org/jbpm/context/def/ContextDefinition.hbm.xml</value>
                <value>org/jbpm/context/def/VariableAccess.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/TaskMgmtDefinition.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/Swimlane.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/Task.hbm.xml</value>
                <value>org/jbpm/taskmgmt/def/TaskController.hbm.xml</value>
                <value>org/jbpm/module/def/ModuleDefinition.hbm.xml</value>
                <value>org/jbpm/bytes/ByteArray.hbm.xml</value>
                <value>org/jbpm/file/def/FileDefinition.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.CreateTimerAction.hbm.xml</value>
                <value>org/jbpm/scheduler/def/CancelTimerAction.hbm.xml</value>
                <value>org/jbpm/graph/exe/Comment.hbm.xml</value>
                <value>org/jbpm/graph/exe/ProcessInstance.hbm.xml</value>
                <value>org/jbpm/graph/exe/Token.hbm.xml</value>
                <value>org/jbpm/graph/exe/RuntimeAction.hbm.xml</value>
                <value>org/jbpm/module/exe/ModuleInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/ContextInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/TokenVariableMap.hbm.xml</value>
                <value>org/jbpm/context/exe/VariableInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/ByteArrayInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/DateInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/DoubleInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/HibernateLongInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/HibernateStringInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/LongInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/NullInstance.hbm.xml</value>
                <value>org/jbpm/context/exe/variableinstance/StringInstance.hbm.xml</value>
                <value>org/jbpm/job/Job.hbm.xml</value>
                <value>org/jbpm/job/Timer.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/jbpm.Timer.hbm.xml</value>
                <value>org/jbpm/job/ExecuteNodeJob.hbm.xml</value>
                <value>org/jbpm/job/ExecuteActionJob.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/TaskMgmtInstance.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/TaskInstance.hbm.xml</value>
                <value>org/alfresco/repo/workflow/jbpm/WorkflowTaskInstance.hbm.xml</value>          
                <value>org/jbpm/taskmgmt/exe/PooledActor.hbm.xml</value>
                <value>org/jbpm/taskmgmt/exe/SwimlaneInstance.hbm.xml</value>
                <value>org/jbpm/logging/log/ProcessLog.hbm.xml</value>
                <value>org/jbpm/logging/log/MessageLog.hbm.xml</value>
                <value>org/jbpm/logging/log/CompositeLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ActionLog.hbm.xml</value>
                <value>org/jbpm/graph/log/NodeLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessInstanceCreateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessInstanceEndLog.hbm.xml</value>
                <value>org/jbpm/graph/log/ProcessStateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/SignalLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TokenCreateLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TokenEndLog.hbm.xml</value>
                <value>org/jbpm/graph/log/TransitionLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableCreateLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableDeleteLog.hbm.xml</value>
                <value>org/jbpm/context/log/VariableUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/ByteArrayUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/DateUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/DoubleUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/HibernateLongUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/HibernateStringUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/LongUpdateLog.hbm.xml</value>
                <value>org/jbpm/context/log/variableinstance/StringUpdateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskCreateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskAssignLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/TaskEndLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneCreateLog.hbm.xml</value>
                <value>org/jbpm/taskmgmt/log/SwimlaneAssignLog.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties" ref="hibernateConfigProperties" />
        <property name="entityCacheStrategies" >
            <props>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.NodeStatusImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.ChildAssocImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.NodeAssocImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.StoreImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.TransactionImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.ServerImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.VersionCountImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.AppliedPatchImpl">${cache.strategy}</prop>
               
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlEntryImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbPermissionImpl">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAuthorityImpl">${cache.strategy}</prop>
               
                 <prop key="org.alfresco.repo.audit.hibernate.AuditConfigImpl">${cache.strategy}</prop>
                 <prop key="org.alfresco.repo.audit.hibernate.AuditDateImpl">${cache.strategy}</prop>
                 <prop key="org.alfresco.repo.audit.hibernate.AuditSourceImpl">${cache.strategy}</prop>
            </props>
        </property>
        <property name="collectionCacheStrategies" >
            <props>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl.properties">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl.aspects">${cache.strategy}</prop>
<!–
                <prop key="org.alfresco.repo.domain.hibernate.NodeImpl.parentAssocs">${cache.strategy}</prop>
–>

                <prop key="org.alfresco.repo.domain.hibernate.DbAccessControlListImpl.entries">${cache.strategy}</prop>
                <prop key="org.alfresco.repo.domain.hibernate.DbAuthorityImpl.externalKeys">${cache.strategy}</prop>
            </props>
        </property>
    </bean>

Is there any other way of doing this?
1 REPLY 1

jzulu2000
Champ in-the-making
Champ in-the-making
I've found another less-intrusive way of doing this…

define a custom-hibernate-mappings-context.xml in the extensions folder of alfresco, and define a new sessionFactoryBase called customSessionFactoryBase, inherited from the original sessionFactoryBase. Re-define the mappingResources property only, with the new mapping(s) you need in the list values, but put merge="true" to make spring merge this values with the values of the original sessionFactoryBase. Then, re-define the sessionFactory bean pointing to new parent customSessionFactoryBase instead of old sessionFactoryBase.

Here's the code…

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans-2.0.dtd'>

<beans>   
    <bean id="customSessionFactoryBase" abstract="true" parent="sessionFactoryBase">
        <property name="mappingResources">
            <list merge="true">
                <value>co/com/arkimia/alfresco/repo/audit/hibernate/SearchAudit.hbm.xml</value>
            </list>
        </property>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" parent="customSessionFactoryBase">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

</beans>

Be carefull of using the spring-beans-2.0.dtd instead of the spring-beans.dtd, because "merge" attribute of list was included in spring 2.0

I hope this helps!