• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Hibernate 3 + Weblogic 8.1 with Oracle Configuration

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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


4) Now the most important part 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">

<hibernate-configuration>
<session-factory>

<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="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="transaction.factory.class">org.hibernate.transaction.JTATransactionFactory</property >


<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

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">jta</property>

<mapping resource="Event.hbm.xml"/>

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


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();

if(sessionFactory == null) {
System.out.println("NULL"); //Testing it
}
else {
System.out.println("NOT NULL");
}


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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Prem Kashyap
SCJP 1.4
 
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Joy for very useful information. I dont know Hibernate but I am planning to learn it.
 
Sandeep Awasthi
Ranch Hand
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joy,

I tried to configure, but got error

org.hibernate.HibernateException: Unable to locate current JTA transaction


I am new to Hibernate.

My cfg file is


<?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">

<hibernate-configuration>
<session-factory>

<property name="connection.username">weblogic</property>
<property name="connection.password">weblogic</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.datasource">PBDS</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="transaction.factory.class">org.hibernate.transaction.JTATransactionFactory</property >


<property name ="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<!--property name="jndi.url">t3://127.0.0.1:7050</property -->
<property name="jndi.url">t3://localhost:7001</property>;



<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">jta</property>

<mapping resource="Emp.hbm.xml"/>

</session-factory>
</hibernate-configuration >
 
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My hibernate.cfg.xml looks like this :

<?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">

<hibernate-configuration>
<session-factory>

<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="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="transaction.factory.class">org.hibernate.transaction.JTATransactionFactory</property >


<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

<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">jta</property>

<mapping resource="Event.hbm.xml"/>


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

I am getting ther error:

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*)".

Please guide..
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Satish Kumar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I am deploying the same file as seen here.
I do not find any problem with that. Then why would the error be coming.
Please guide.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 597
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi can someone help me , I dont know why I am getting this error

org.hibernate.HibernateException: Unable to locate current JTA transaction
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajesh Thakare:
Hi can someone help me , I dont know why I am getting this error

org.hibernate.HibernateException: Unable to locate current JTA transaction



Please post this question in a new topic, rather than adding it to an existing one.
 
Satish Kumar
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am getting the following error :

�java.lang.NoSuchMethodError: com.trend.iwss.jscan.appscan.runtime.PolicyProps: method <init>()V not found�



The error encounters at the statement :

SessionFactory sessions = new Configuration().configure().buildSessionFactory();



Can anyone help in resolving this?
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

Sergiu

Hibernate CONFIGURATION:
<property name="enableDefaultFiltering">true</property>
<property name="hibernate.show_sql">true</property>
<property name="show_sql">true</property>
<property name="hibernate.default_entity_mode">pojo</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.TreeCacheProvider</property>
<property name="hibernate.cache.use_second_level_cache">false</property>

<!-- //jndi URL not required Weblogic knows it -->
<property name="jndi.url">t3://127.0.0.1:10102</property>;
<property name ="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>

<!--
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
-->
<property name="transaction.manager_lookup_class">org.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

<property name="dialect">org.hibernate.dialect.Oracle9iDialect</property>

<!-- //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 ]
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

Please tell me what are the steps need to take.

Thanks in advance....
 
I'm sure glad that he's gone. Now I can read this tiny ad in peace!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic