Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Info

Help is available by sending an email to csf-support@mit.edu
Have any suggestion on how improve this wiki?  Please give us your feedback at csf-support@mit.edu

Panel

Anchor
Hibernate Mappings and CSF version 2
Hibernate Mappings and CSF version 2

Hibernate Mappings and CSF version 2

The manner in which hibernate mappings are configured has changed from the manner in which hibernate mappings were configured in sais-common and in the CSF Version 1 series.  In sais-common and in CSF version 1, the sessionFactory's mappingResources property was used to configure hibernate mappings.  The use of the mappingResources property has been deprecated and will no longer be used except to support legacy applications.

With the release of the CSF version 2 series, the sessionFactory's mappingLocations property will be used to configure hibernate mappings.  The mappingLocations property allow for more flexibility when configuring hibernate mappings from several different sources.

The principal advantage of using the mappingLocations property is that you can specify a resource path to the mapping files as opposed to the absolute path to the mapping file.  This is all well and good but what does this actually mean.  Rather than specifying the individual hibernate mappings as shown below:

Code Block
Wiki Markup

{anchor:Hibernate Mappings and CSF version 2}
h3. Hibernate Mappings and CSF version 2
The manner in which hibernate mappings are configured has changed from the manner in which hibernate mappings were configured in *sais-common* and in the *CSF Version 1* series.  In *sais-common* and in *CSF version 1*, the sessionFactory's *mappingResources* property was used to configure hibernate mappings.  The use of the *mappingResources property has been deprecated* and will no longer be used except to support legacy applications.

With the release of the CSF version 2 series, the sessionFactory's *mappingLocations* property will be used to configure hibernate mappings.  The *mappingLocations* property allow for more flexibility when configuring hibernate mappings from several different sources.

The principal advantage of using the *mappingLocations* property is that you can specify a resource path to the mapping files as opposed to the absolute path to the mapping file.  This is all well and good but what does this actually mean.  Rather than specifying the individual hibernate mappings as shown below:
{code}
        <value>edu/mit/csf/example/academic/hibernate/AcademicTerm.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/AcademicTermDate.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/AcademicYear.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/Department.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/EnrollmentStatus.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/Course.hbm.xml</value>
        <value>edu/mit/csf/example/academic/hibernate/Citizenship.hbm.xml</value>

        <value>edu/mit/csf/example/student/hibernate/Student.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/StudentOtherMitId.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/StudentMitId.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/ArchivedStudent.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/ArchivedStudentOtherMitId.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/ArchivedStudentMitId.hbm.xml</value>
        
        <value>edu/mit/csf/example/student/hibernate/Country.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/State.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/StudentAddress.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/StudentEmail.hbm.xml</value>
        <value>edu/mit/csf/example/student/hibernate/StudentPhone.hbm.xml</value>
{code}

Using

the

*

mappingLocations

*

property,

you

can

now

specify

wildcards

in

the

resource

path

to

match

multiple

files

so

that

you

don't

have

to

configure

a

hibernate

mapping

file

location

every

time

you

add

a

new

mapping

file.  This reduces the 16 lines in the above to the following 2 lines shown below:

Code Block
&nbsp;&nbsp;This reduces the 16 lines in the above to the following 2 lines shown below:
{code}
        <value>classpath*:edu/mit/csf/example/academic/hibernate/*.hbm.xml</value>
        <value>classpath*:edu/mit/csf/example/student/hibernate/*.hbm.xml</value>
{code}

Panel

Anchor
Session Factory configuration of hibernate mappings for CSF version 2
Session Factory configuration of hibernate mappings for CSF version 2

Session Factory configuration of hibernate mappings for CSF version 2

Locate your project's sessionFactory bean and add the mappingLocations property as shown below (replacing the mappingLocations resource paths with those from your project):

Code Block
Wiki Markup

{anchor:Session Factory configuration of hibernate mappings for CSF version 2}
h3.Session Factory configuration of hibernate mappings for CSF version 2
Locate your project's *sessionFactory bean* and add the *mappingLocations* property as shown below (replacing the *mappingLocations* resource paths with those from your project):
{code}
    <bean id="sessionFactory" parent="abstractSessionFactory" >
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.jdbc.use_scrollable_resultset">true</prop>
                <prop key="hibernate.jdbc.batch_size">20</prop>
                <prop key="hibernate.cache.use_second_level_cache">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.cache.use_structured_entries">true</prop>
                <prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
                <prop key="edu.mit.common.domain.student.hibernate.cache.use_query_cache">true</prop>
            </props>
        </property>
        <property name="mappingLocations">
            <list>
                <value>classpath*:edu/mit/csf/example/academic/hibernate/*.hbm.xml</value>
                <value>classpath*:edu/mit/csf/example/student/hibernate/*.hbm.xml</value>
            </list>
        </property> 
    </bean>
{code}
# Each of your project should only have 1 sessionFactory bean defined.
#* For a WAR project:&nbsp;&nbsp;The sessionFactory bean should be defined in the project's *
  1. Each of your project should only have 1 sessionFactory bean defined.
    • For a WAR project:  The sessionFactory bean should be defined in the project's /src/main/resouces/applicationContext-<projectName>-config.xml
*
    • file.
#*
    • For
    • a
    • JAR
    • project:
&nbsp;&nbsp;The sessionFactory bean should be defined in the
    •   The sessionFactory bean should be defined in the project's
*
    • src/test/resources/applicationContext-csf-<projectName>-config-test.xml
*
    • file.
#
  1. All
*
  1. csf-common-legacy
*
  1. hibernate
  1. mappings
  1. are
  1. automatically
  1. added
  1. to
  1. your
  1. project
  1. via
  1. the
  1. CSF
*
  1. abstractSessionFactory
*
  1. bean.
#
  1. Hibernate
  1. mappings
  1. for
  1. the
  1. csf-email
  1. and
  1. csf-ruleengine
  1. jars
  1. must
  1. be
  1. added
  1. to
  1. the
*
  1. mappingLocations
*.&nbsp;&nbsp;The resource paths are: #* For
  1. .  The resource paths are:
    • For csf-email:
{
    • Code Block
}
    • 
      <value>classpath*:edu/mit/es/csf/email/hibernate/*.hbm.xml</value>				
      
{code} #* For
    • For csf-ruleengine:
{
    • Code Block
}
    • 
      <value>classpath*:edu/mit/es/csf/ruleengine/hibernate/*.hbm.xml</value>				
      
{code} # 3rd party hibernate mapping (located in a jar) can be used by: ## Adding the dependency for the jar to your project's pom.xml and ## Adding the resource path for the hibernate mapping to the session factory's *mappingLocations* list.
  1. 3rd party hibernate mapping (located in a jar) can be used by:
    1. Adding the dependency for the jar to your project's pom.xml and
    2. Adding the resource path for the hibernate mapping to the session factory's mappingLocations list.