Reputation: 925
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:
Do I have to add other files to my Webapp? I've seen some people talking about files such as context.xml
and weblogic.xml
, but have no idea where they should go.
Do I have to add properties to my hibernate.cfg.xml
file?
Should I have used the jdbc
prefix when defining the JNDI name for the DataSource? Only used because that's how I have used on Tomcat
Below is my current hibernate.cfg.xml
file and former Tomcat Datasource config.
OBS: the application structure was created with Maven.
<?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>
<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
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