Discussions

EJB design: How connect EJB + Hibernate

  1. How connect EJB + Hibernate (4 messages)

    Does anyone know how can i connect EJB + Hibernate?
    Or is somewhere tutorial how to make this?
    Please some help :).
    Luk

    Threaded Messages (4)

  2. How connect EJB + Hibernate[ Go to top ]

    Which Application server are you using?


    regards,
    Rajesh Kumar Ilango
  3. How connect EJB + Hibernate[ Go to top ]

    I'm using JBoss 3.0.8 + MySql.

    Thanks,
    Luk.
  4. How connect EJB + Hibernate[ Go to top ]

    Follow the steps:
    1. Create jBoss-Hib-Service.xml and put it in the deploy directory. The purpose is to create a service and register at JNDI, so that it can use to interact with DB using Hibernate.
    Following is an example(This I generate using xDoclet.):
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE server>
    <server>
                <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateLaborMgmt">
             <depends>jboss.jca:service=RARDeployer</depends>
                    <attribute name="MapResources">org/learn/labormgmt/employee/value/EmployeeValues.hbm.xml,org/learn/labormgmt/customer/value/CustomerValues.hbm.xml,org/learn/labormgmt/location/value/StateValues.hbm.xml,org/learn/labormgmt/association/value/AssociationValues.hbm.xml</attribute>
           <attribute name="JndiName">java:/hibernate/labormgmt</attribute>
           <attribute name="Datasource">java:/labormgmt</attribute>
           <attribute name="Dialect">org.hibernate.dialect.SAPDBDialect</attribute>
           <attribute name="ShowSql">true</attribute>
           <attribute name="UserTransactionName">UserTransaction</attribute>
           <attribute name="TransactionStrategy">org.hibernate.transaction.JTATransactionFactory</attribute>
           <attribute name="TransactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
       </mbean>
    </server>

    2. In the code get the service, which is actually a Session factory. e.g. code:
     try {
    //JNDI lookup to get Hibernate Session factory.
        SessionFactory factory = (SessionFactory)ServiceLocator.getInstance()
            .getService("java:/hibernate/labormgmt");
          
        } catch (HibernateException e) {
          logger.debug("Error while initilising Hibernate." + e.getMessage());
          throw new InstantiationError("Error while initilising Hibernate."
              + e.getMessage());
        } catch (LocatorException e) {
          logger.debug("Error while initilising Hibernate." + e.getMessage());
          throw new InstantiationError("Error while initilising Hibernate."
              + e.getMessage());
        }

    3. Start using it for creating Hibernate Session.
        Session session = null;
        session = factory.openSession();

    I hope it helps you.

    Regards,
    Rajesh Kumar Ilango
  5. And Jonas ?[ Go to top ]

    Same question with Jonas server ...
    Ways more difficult to find than Jboss outhere !