How to get Hibernate SessionFactory inside the ServiceImpl ?

­­

Problem:

I have read many posts on andromda forum about How to obtain Hibernat sessionFactory and I tried two approaches which ddn't work with me then I make some solution wihch I don't know if it is dirty solution or not but at least it works with me so I guess it is not ;)


the following approaches I tried to apply them inside the ServiceImpl

first I tried the following approach:

­Code:
­­org.hibernate.Session session = 
  org.springframework.orm.hibernate3.SessionFactoryUtils.getSession(
   (org.hibernate.SessionFactory)S­erviceLocator.instance().getService("sessionFactory"), true);

and it didn't work with me.

then I followed the following approach:

­Code:
­HibernateInterceptor hibernateInterceptor = 
   (HibernateInterceptor) ServiceLocator.instance().getService("hibernateInterceptor");

SessionFactory sessionFactory = hibernateInterceptor.getSessionFactory();
Session session = sessionFactory.getCurrentSession();­          


and it didn't work with me also.

­

and both approaches fails and throw MyServiceException from it. when it reaches the execution of the following line

­Code:
­­­­ this.beanFactoryReference = ­­beanFactoryLocator.useBeanFactory(this.beanRefFactoryReferenceId);


from inside the ServiceLocator Class from

­Code:
protected synchronized org.springframework.context.ApplicationContext getContext()

method

Solution:

as I said above I need to make sessionFactory available in the services so I did the following:

    first extracted the andromda-spring-cartrige which is located under the following path

    Quote:
    $M2_HOME/repository/org/andromda/cartridges/andromda-spring-cartridge/3.3-SNAPSHOT



    and copied the template directory to my

    Quote:
    project/mda/src/main/config/cartridge

    folder

    then I created SpringTemplateMergeMappings.xml file under

    Quote:
    project/mda/src/main/config/mappings

    which contains the following mapping

    ­Code:
    <mappings name="SpringTemplateMerge">
        <mapping>
            <from><![CDATA[<!-- cartridge-template merge-point -->]]></from>
            <to>
               <![CDATA[        
                   <template path="templates/spring/applicationContext.xml.vsl"
                             outputPattern="$applicationContext"
                             outlet="spring-configuration"
                             overwrite="true" outputToSingleFile="true"
                             outputOnEmptyElements="false">
                      <modelElements>
                            <modelElement variable="entities">
                                    <type name="org.andromda.cartridges.spring.metafacades.SpringEntity"/>
                            </modelElement>
    
                            <modelElement variable="services">
                                    <type name="org.andromda.cartridges.spring.metafacades.SpringService">
                                            <property name="abstract">false</property>
                                    </type>
                            </modelElement>
    
                            <modelElement variable="manageables">
                                    <type name="org.andromda.cartridges.spring.metafacades.SpringManageableEntity"/>
                            </modelElement>
    
                      </modelElements>
                   </template>
                    ]]>
            </to>
        </mapping>
    </mappings>
    ­­

    then I have inserted the following two lines:

    ­Code:
    <property name="mergeLocation">${conf.dir}/cartridge</property>
    <property name="mergeMappingsUri">
       file:${conf.dir}/mappings/SpringTemplateMergeMappings.xml
    </property>


    inside the

    Quote:
    mda/src/main/config/andromda.xml

    inside the spring namespace

    and altered the applicationContext.vsl which is located under

    Quote:
    /mda/src/main/config/cartridge/template/spring/


    to add the following line in the

    ­Code:
    ­­#­foreach($service in $services)
        <!-- $service.name Service Proxy with inner $service.name Service Implementation -->
        <bean id="$service.getBeanName(false)" class="org.springframework.aop.framework.ProxyFactoryBean">
            <property name="target">
                <bean class="$service.fullyQualifiedImplement­ationName">
    #if ($daoRefsEnabled)­
          <!-- sessionFactory being injected by -->
          <property name="sessionFactory"><ref bean="sessionFactory"/></property>
    #foreach($entityRef in $service.allEntityReferences)
          <property name="$entityRef.daoName"><ref bean="$entityRef.targetElement.getBeanName(false)"/></property>
    #end     
    
    #end
    

    ­


    <!-- ========================= Start of SERVICE DEFINITIONS ========================= --> section

    at the end I have edited the ServiceBase.VSL to include the setter and getter for sessionFactory as follows

    Code:

        private SessionFactory sessionFactory;

        /**

         *

         * Sets the reference to <code>sessionFactory</code>.

         */

        public void setSessionFactory(SessionFactory sessionFactory) {

           this.sessionFactory = sessionFactory;

        }

        /**

         *

         * Gets the reference to <code>sessionFactory</code>.

         */

        protected SessionFactory getSessionFactory() {

    &nbs­p;      return this.sessionFactory;

        }

free roblox robux generator

Visiting this author's website will let you to generate the unlimited roblox robux generator which will help you a lot in playing roblox much comfortably.After getting its resources you will find this game much more entertaining one so you should not waste your time and grab it as soon as possible.

How to play mxf videos on

How to play mxf videos on Windows OS? U should convert mxf file with software app mxf video converter .

indah menulis-up bahwa

indah menulis-up bahwa Gambar baca aku tertarik pada itu bagaimanapun itu jauh lebih berguna dalam acara yang Anda menghasilkan konten berkaitan dengan liburan orang sama dengan saat mencapai situs web . Travel Pulau Tidung

This is a pretty amazing

This is a pretty amazing article, I can totally use this as a project material. - Dennis Wong

CSNK

Room bedroom pillows could make very best sponsorship on the spine. We
could adjust defends as well as great form of what things to make these
kinds of modernizing with regards to displaying areasWe are the professional clothing manufacturer

After read a couple of the

After read a couple of the articles on your website these few days, and I truly like your style of blogging. I tag it to my favorites internet site list and will be checking back soon. Please check out my web site also and let me know what you think. Bandar Bola

Even the nor­mally strong

Even the nor­mally strong Italians found things tough,both approaches fails and throw MyService Exception from it.  It was too late for us to change our approach .

Meticulous Rolex Datejust Online Store

I think you can find

I think you can find solutions in there. The information has been laid and I think the solution is in there.

buy youtube views

how to get more followers on twitter

Aluminum wiring installed in

Aluminum wiring installed in homes built from mid 1960's to mid 1970's are causing problems for homeowners. Fires are caused by the connections of the wiring to outlets and switches. Aluminum Testing

This is not a good practice.

after accomplishing this task I found that Its not a good practice to get  the sessionFactory inside the serviceImpl as serviceImpl should just make calles to the entityDaos and inside the entityDaoImpl you can get reference to the sessionFactory.

Ali Abdel-Aziz.

Powered by Drupal - Design by artinet