Felipe Leão
Felipe Leão

Reputation: 925

Migrate app with Hibernate+DataSource from Tomcat 7 to Weblogic 12

I have a webapp running on Tomcat 7. It uses Hibernate 4 to connect to a DataSource defined in Tomcat server.xml and context.xml files.

Due to internal company reasons I have to migrate the webapp to Weblogic 12. I have deployed it successfully, except for the connection with the database. I created a DataSource on Weblogic console and tested it through the Console, it works fine (JNDI name is jdbc/MyAppDB).

To run my application in Tomcat I only had to tell the hibernate.cfg.xml file to look for the datasource, but aparently it is not enough for Weblogic. I'm really confused on how to configure the DataSource Connection. Basic Questions are:

Below is my current hibernate.cfg.xml file and former Tomcat Datasource config.

OBS: the application structure was created with Maven.

Hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>   

        <property name="hibernate.connection.datasource">java:/comp/env/jdbc/MyAppDB</property>

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">false</property>
        <property name="current_session_context_class">thread</property>
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
        <property name="hbm2ddl.auto">update</property>
        <property name="hibernate.max_fetch_depth">3</property>

        <mapping class="org.my.app.model.ServerInfo"/>
        <mapping class="org.my.app.model.Parameter"/>

    </session-factory>
</hibernate-configuration>

Tomcat DataSource

<Resource name="jdbc/MyAppDB" global="jdbc/MyAppDB" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           username="root" password="#####" driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://127.0.0.1:3306/myappdb"/>

Upvotes: 1

Views: 1098

Answers (1)

Felipe Le&#227;o
Felipe Le&#227;o

Reputation: 925

So apparently I was defining the datasource path in a wrong way. It should only be th JNDI name. therefore, in my case, the datasource should be refered in hibernate.cfg.xml as:

<property name="hibernate.connection.datasource">jdbc/MyAppDB</property>

EDIT: It is also worth noting that at this point Weblogic 12c simply can work well with Hibernate 4.3.5+. I have succeded with 4.1.1, though. Using old, deprecated, HibernateUtil methods such as buildSessionFactory().

Upvotes: 1

Related Questions