This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Hibernate 3 + Weblogic 8.1 with Oracle Configuration
Joy Mookerji
Ranch Hand
Joined: Jul 26, 2006
Posts: 49
posted
0
Hi,
Today after 20 hrs of continous struggling I was able configure my existing Enterprise application in Weblogic 8.1 sp4 with Hibernate 3.
I have seen blogs about this in the beadev2dev that you have to create a WLS Startup class to bind the Session Factory and other things but Weblogic 8.1 works fine without any Start Up Classes
Important Things to note
1) Libraries you have to use in your startWeblogic.cmd CLASSPATH Copy this libraries in your domains/mydomain/lib folder
1) These are the important libraries log4j.jar hibernate3.jar; providerutil.jar; dom4j-1.6.1.jar; commons-collections-2.1.1.jar; jta.jar; asm.jar; asm-attrs.jar; commons-logging.jar; antlr-2.7.5H3.jar; antlr-2.7.6rc1.jar; ant-1.6.5.jar; cglib-2.1.3.jar //Very very important (took my most time to find this issue you will get NoClassDefFoundError
2) My startWeblogic.cmd relevant portion is like this JOY_DOM is my domain name Path: C:\bea\user_projects\domains\joydom JOY_DOM=C:\bea\user_projects\domains\joydom
set CLASSPATH=%WEBLOGIC_CLASSPATH%;%POINTBASE_CLASSPATH%;%JAVA_HOME%\jre\lib\rt.jar;%WL_HOME%\server\lib\webservices.jar;%JOY_DOM%\lib\commons-logging.jar;%JOY_DOM%\lib\log4j.jar;%JOY_DOM%\lib\log4j_appserver.jar;%JOY_DOM%\lib\jdom.jar;%JOY_DOM%\lib\xmlrpc-1.1.jar;%JOY_DOM%\lib\hibernate3.jar;%JOY_DOM%\lib\providerutil.jar;%JOY_DOM%\lib\dom4j-1.6.1.jar;%JOY_DOM%\lib\commons-collections-2.1.1.jar;%JOY_DOM%\lib\jta.jar;%JOY_DOM%\lib\asm.jar;%JOY_DOM%\lib\asm-attrs.jar;%JOY_DOM%\lib\commons-logging.jar ;%JOY_DOM%\lib\antlr-2.7.5H3.jar;%JOY_DOM%\lib\antlr-2.7.6rc1.jar;%JOY_DOM%\lib\ant-1.6.5.jar;%JOY_DOM%\lib\cglib-2.1.3.jar;%CLASSPATH%
3) Configure a datasource using a connectioon pool
<property name="connection.username">weblogic</property> //Use App Server Username/Pass not dbs (other wise UserNotFound SQLException) <property name="connection.password">weblogic</property> <property name="show_sql">true</property> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <property name="connection.datasource">jdbc/JOYSDataSource</property> //configure this datasource in Weblogic Admin Console //You know to do this right other wise pls feel free to ask
<property name ="jndi.class">weblogic.jndi.WLInitialContextFactory</property> <!--property name="jndi.url">t3://127.0.0.1:7050</property --> //jndi URL not required Weblogic knows it
Keep this in any folder yu like yu can keep it at domains/mydomain
I will tell how to right the code when constructing Configuration object with the file path in by code
5) Event.hbm.xml (You can keep it in the same folder as hibernate-cfg.xml or use Relative path (How it suits yu Simple file one table
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping default-cascade="none" default-access="property" default-lazy="true" auto-import="true"> <class name="com.hibernate.joy.valueobj.EventInfo" table="EVENTS"> //Give fully classified name <id name="eventId" column="EVENT_ID"> <generator class="native" /> </id> <property name="eventDate" type="timestamp" column="EVENT_DATE" /> <property name="title" /> </class> <sql-query name="select_title"> select title from events e where e.event_id = :id </sql-query> </hibernate-mapping>
6) Sample function for my EJB My EJB is Container Managed
public String getEventInfo(int eventId) throws GenEException { EventInfo info = new EventInfo(); List eventList = new ArrayList(); String name = "Default"; try { System.out.println("getEventInfo"); File file = new File("C:\\bea\\user_projects\\domains\\joydom\\hibernate-cfg.xml"); //yu see I have used full path //This is my first run I will chenge to relative path later System.out.println(file.exists()); SessionFactory sessionFactory = new Configuration().configure(file).buildSessionFactory();
Session session = sessionFactory.getCurrentSession(); //session.beginTransaction(); //Not Required as Transaction is Container Managed hence commented System.out.println("#######NAME####### " + name);
SQLQuery sql = (SQLQuery)session.getNamedQuery("select_title").setInteger("id",4); eventList = ((Query)sql).list(); name = (String)(eventList.get(0)); System.out.println("#######NAME####### " + name); //session.getTransaction().commit(); //Not Required as Transaction is Container Managed hence commented return name; }
catch(Exception ex){ ex.printStackTrace(); }
return name;
}
Hope this helps you guys and doesnt have to spend 20hrs googling till the whole Universe from Earth to Saturn
Pls feel free to ask any questions
SCJP 5<br />Brainbench Certified in C++<br />PMP<br />Dallas,TX
Halcon Guatemala
Ranch Hand
Joined: Sep 06, 2006
Posts: 57
posted
0
Hi Joy, thanks for the entire tutorial about hibernate configuration. You mentioned:
3) Configure a datasource using a connectioon pool
and You wrote:
I'm trying to configure the connection with a datasource parameter instead set indidually connection.username, connection.password, etc.
Have You done something like this?
Thanks in advance
"La verdadera sabidur�a viene del temor de Dios"
Prem Kashyap
Ranch Hand
Joined: Oct 10, 2006
Posts: 52
posted
0
Hi Joy, I was also spending lot of time solving the issue with JNDI using Hibernate and Weblogic. And your solution provided me the answer. I did not copied any of the jar file to the domain lib folder. And I do not think that is required if those jars are inside your WEB-INF/lib folder. Also I did not changed the startWeblogic.cmd file to have those jars in the classpath as weblogic will pick it from WEB-INF/lib folder.
The only thing which I tried from your solution was the username and password. I was giving the oracle username and password, and I was getting User not Authorized error. Then i tried the weblogic server username and password and it worked. Here is my snipped from hibernate.cfg.xml : <property name="show_sql">true</property> <property name="connection.autocommit">true</property> <property name="current_session_context_class">thread</property> <property name="connection.datasource">FISDS</property> <property name="connection.username">weblogic</property> <property name="connection.password">weblogic</property> <property name="dialect">org.hibernate.dialect.Oracle9Dialect</property> <property name="jndi.url">t3://127.0.0.1:7001</property> <property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
Anyway i got the solution from your post, although I did not have to do so many things as suggested by you. Thanks Again.
<property name="connection.username">weblogic</property> //Use App Server Username/Pass not dbs (other wise UserNotFound SQLException) <property name="connection.password">weblogic</property> <property name="show_sql">true</property> <property name="connection.autocommit">true</property> <property name="dialect">org.hibernate.dialect.OracleDialect</property> <property name="connection.datasource">BTBillingIMDataSource</property> //configure this datasource in Weblogic Admin Console //You know to do this right other wise pls feel free to ask
<property name ="jndi.class">weblogic.jndi.WLInitialContextFactory</property> <!--property name="jndi.url">t3://127.0.0.1:7050</property --> //jndi URL not required Weblogic knows it
37207 [ExecuteThread: '14' for queue: 'weblogic.kernel.Default'] ERROR org.hiber nate.util.XMLHelper - Error parsing XML: /hibernate.cfg.xml(31) The content of element type "session-factory" must match "(property*,mapping*,(class-cache|coll ection-cache)*,event*,listener*)".
The error is telling you that the content of your hibernate.cfg.xml file does not match that defined in the DTD. The file you posted look OK however. Are you sure it is the configuration that is being deployed?
Ah. I'm not very observant. Your hibernate.cfg.xml is not ok. Why do you have Java comments in aN XML file? [ March 16, 2007: Message edited by: Paul Sturrock ]
Sandeep Awasthi
Ranch Hand
Joined: Oct 23, 2003
Posts: 597
posted
0
Hi can someone help me , I dont know why I am getting this error
org.hibernate.HibernateException: Unable to locate current JTA transaction
That is not a Hibernate error. It looks like it might be something to do with a Trend Micro antivirus product. My guess is that when Hibernate tries to access the DTD over the network Trend gets in the way. Try changing the DOCTYPE statement to point at a local copy of the DTD.
sergiu gordea
Greenhorn
Joined: Nov 24, 2008
Posts: 1
posted
0
Hi all,
This post helped me to configure the Hibernate and weblogic to use Container Managed Transactions.... or better said it helped me to make progress with the configurations.
I was degbuging my server activity and it seams that the JTA user transactions are created correctly, but the Sql connection is not created correctly.
I defined a JDBC Datasource using Weblogic 10.3 Console, and I tested the JDBC connection when I defined the Connnection Pool.
Anyway,
When I execute my junit tests I get the following exception in: SettingsFactory.buildSettings(Properties props) { ........ catch (SQLException sqle) { log.warn("Could not obtain connection metadata", sqle); } }
Because this is cacted as SQLEception, I asume that the connection with the database was never established.
DO you have an idea about how can I solve this Problem? Best regards
<!-- //Use App Server Username/Pass not dbs (other wise UserNotFound SQLException) --> <property name="connection.datasource">HibernateDataSource</property>
EXCEPTION:
org.hibernate.TransactionException: could not register synchronization at org.hibernate.transaction.JTATransaction.registerSynchronization(JTATransaction.java:316) at org.hibernate.context.ThreadLocalSessionContext.currentSession(ThreadLocalSessionContext.java:105) at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:574) at com.uniquare.ubml.persistence.hibernate.becl.std.HibernateAccessAdapter.getSession(HibernateAccessAdapter.java:177) at com.uniquare.ubml.persistence.hibernate.becl.std.HibernateAccessAdapter.insertObject(HibernateAccessAdapter.java:570) at com.uniquare.ubml.persistence.becl.DataAccessProvider.insertObject(DataAccessProvider.java:55) at com.uniquare.ubml.s.loandetails.becl.std.LoanDetailsDao.createLoanDetails(LoanDetailsDao.java:111) at com.uniquare.ubml.s.loandetails.becl.std.LoanDetailsDao.createLoanDetails(LoanDetailsDao.java:75) at com.uniquare.ubml.s.loandetails.bofl.server.std.LoanDetailsBoc.performCreateLoanDetails(LoanDetailsBoc.java:300) at com.uniquare.ubml.s.loandetails.bofl.server.std.LoanDetailsBoc.createLoanDetails(LoanDetailsBoc.java:266) at com.uniquare.ubml.s.loandetails.bofl.server.proxy.std.LoanDetailsBocProxy.createLoanDetails(LoanDetailsBocProxy.java:168) at com.uniquare.ubml.s.loandetails.bofl.server.proxy.ejb.std.LoanDetailsBocProxyBean_eu1y87_EOImpl.createLoanDetails(LoanDetailsBocProxyBean_eu1y87_EOImpl.java:739) at com.uniquare.ubml.s.loandetails.bofl.server.proxy.ejb.std.LoanDetailsBocProxyBean_eu1y87_EOImpl_WLSkel.invoke(Unknown Source) at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:589) at weblogic.rmi.cluster.ClusterableServerRef.invoke(ClusterableServerRef.java:230) at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:477) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:363) at weblogic.security.service.SecurityManager.runAs(Unknown Source) at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:473) at weblogic.rmi.internal.wls.WLSExecuteRequest.run(WLSExecuteRequest.java:118) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201) at weblogic.work.ExecuteThread.run(ExecuteThread.java:173) Caused by: weblogic.transaction.RollbackException: Transaction timed out after 30 seconds BEA1-0000D908C44E10FFBF65 at weblogic.transaction.internal.TransactionImpl.throwRollbackException(TransactionImpl.java:1818) at weblogic.transaction.internal.ServerTransactionImpl.registerSynchronization(ServerTransactionImpl.java:586) at org.hibernate.transaction.JTATransaction.registerSynchronization(JTATransaction.java:313) ... 21 more Caused by: weblogic.transaction.internal.TimedOutException: Transaction timed out after 30 seconds BEA1-0000D908C44E10FFBF65 at weblogic.transaction.internal.ServerTransactionImpl.wakeUp(ServerTransactionImpl.java:1734) at weblogic.transaction.internal.ServerTransactionManagerImpl.processTimedOutTransactions(ServerTransactionManagerImpl.java:1607) at weblogic.transaction.internal.TransactionManagerImpl.wakeUp(TransactionManagerImpl.java:1879) at weblogic.transaction.internal.ServerTransactionManagerImpl.wakeUp(ServerTransactionManagerImpl.java:1517) at weblogic.transaction.internal.WLSTimer.timerExpired(WLSTimer.java:35) at weblogic.timers.internal.TimerImpl.run(TimerImpl.java:273) at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516) ... 2 more [ November 24, 2008: Message edited by: sergiu gordea ]
sridhar addanki
Greenhorn
Joined: Mar 04, 2009
Posts: 22
posted
0
Hi,
I am new to both Hibernate and Weblogic. I have installed weblogic 10.3 in linux machine. I have created Datasource from Weblogic admin console.
Now i want configure weblogic for Hibernate 3.2.