How to get Hibernate SessionFactory inside the ServiceImpl ?



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:

­­org.hibernate.Session session = 
   (org.hibernate.SessionFactory)S­erviceLocator.instance().getService("sessionFactory"), true);

and it didn't work with me.

then I followed the following approach:

­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

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

from inside the ServiceLocator Class from

protected synchronized org.springframework.context.ApplicationContext getContext()



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


    and copied the template directory to my



    then I created SpringTemplateMergeMappings.xml file under


    which contains the following mapping

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

    then I have inserted the following two lines:

    <property name="mergeLocation">${conf.dir}/cartridge</property>
    <property name="mergeMappingsUri">

    inside the


    inside the spring namespace

    and altered the applicationContext.vsl which is located under


    to add the following line in the

    ­­#­foreach($service in $services)
        <!-- $ Service Proxy with inner $ 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>


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

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


        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


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