facebook

Hibernate and WebLogic setup

  1. MyEclipse Archived
  2.  > 
  3. General
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #250217 Reply

    closec1
    Member

    I’m new to hibernate and I’m trying to use the JNDI DAO that is generated by myeclipse. I can’t seem to setup hibernate correctly to use WebLogic JNDI. Please help.

    my hibernate.cfg.xml
    ————————-
    <?xml version=’1.0′ encoding=’UTF-8′?>
    <!DOCTYPE hibernate-configuration PUBLIC
    “-//Hibernate/Hibernate Configuration DTD 3.0//EN”
    http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd”&gt;

    <!– Generated by MyEclipse Hibernate Tools. –>
    <hibernate-configuration>

    <session-factory>
    <property name=”dialect”>org.hibernate.dialect.OracleDialect</property>
    <property name=”jndi.url”>t3://localhost:7001</property>
    <property name=”jndi.class”>weblogic.jndi.WLInitialContextFactory</property>
    <property name=”connection.datasource”>orcl-milemarker-jdbc</property>
    <mapping resource=”com/autotrader/milemarkers/reports/Reports.hbm.xml” />

    </session-factory>

    </hibernate-configuration>
    ——————

    I keep getting the error below:

    Error 500–Internal Server Error
    java.lang.IllegalStateException: Could not locate SessionFactory in JNDI
    at com.autotrader.milemarkers.reports.ReportsDAO.getSessionFactory(ReportsDAO.java:27)
    at com.autotrader.milemarkers.reports.ReportsDAO.(ReportsDAO.java:20)
    at jsp_servlet._jsp.__myjsp._jspService(__myjsp.java:138)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:33)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1006)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:419)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:315)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6718)
    at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
    at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3764)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2644)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:219)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:178)

    my ReportsDAO.java
    ————————
    import java.util.List;
    import javax.naming.InitialContext;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.hibernate.LockMode;
    import org.hibernate.SessionFactory;
    import org.hibernate.criterion.Example;

    Public class ReportsDAO {

    private static final Log log = LogFactory.getLog(ReportsDAO.class);

    private final SessionFactory sessionFactory = getSessionFactory();

    protected SessionFactory getSessionFactory() {
    try {
    return (SessionFactory) new InitialContext().lookup(“orcl-milemarker-jdbc”);
    } catch (Exception e) {
    log.error(“Could not locate SessionFactory in JNDI”, e);
    throw new IllegalStateException(“Could not locate SessionFactory in JNDI”);
    }
    }
    public Reports findById( java.lang.Long id) {
    log.debug(“getting Reports instance with id: ” + id);
    try {
    Reports instance = (Reports) sessionFactory.getCurrentSession()
    .get(“com.autotrader.milemarkers.reports.Reports”, id);
    return instance;
    } catch (RuntimeException re) {
    log.error(“get failed”, re);
    throw re;
    }
    }
    }

    #250233 Reply

    Riyad Kalla
    Member

    Did you actually go into the WebLogic administration console and setup the JNDI data source to point at your database?

    #250259 Reply

    closec1
    Member

    Yes the datasource was setup previously. I’m trying to convert the application to use hibernate. I know this probably isn’t the correct forum for this issue but I’m stuck and just shooting in the dark for any answers.

    #250279 Reply

    Riyad Kalla
    Member

    Your JNDI url doesn’t make sense… if your app server is hosting up your data source under JNDI, then it will look something like java:/comp/env/jdbc/weblogic or something like that…

    Have a look here for more help: http://www.hibernate.org/hib_docs/v3/reference/en/html/session-configuration.html#configuration-optional-jndi

    #253555 Reply

    lambo82669
    Member

    you must call “new Configuration().configure().buildSessionFactory()” in order to have the sessionfactory register itself with the weblogic jndi context.

    #261217 Reply

    jguatemala
    Member

    Hello, tell me please Where do you call “new Configuration().configure().buildSessionFactory()” in the DAO class or HibernateSessionFactory

    #262549 Reply

    Haris Peco
    Member

    jguatemala,

    It is called :

    – HibernateSessionFactory#rebuildSessionFactory()
    – in Spring DAO it is called with Spring – Spring have session factory bean
    – in Base DAO it is called in BaseHibernateDAO (call HibernateSessionFactory)
    – in JNDI DAO you have to make session factory JNIDI in your application server

    Regards,

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Hibernate and WebLogic setup

You must be logged in to post in the forum log in