These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Using ejb transaction instead of hibernate transaction
PostPosted: Wed Nov 24, 2004 6:31 pm 
Newbie

Joined: Thu Nov 18, 2004 9:28 pm
Posts: 11
Location: Costa Rica
Hibernate version:
2.1.6
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="test.ProviderPerson"
table="ProviderPerson"
>

<id
name="idproviderPerson"
type="java.lang.String"
column="IdProviderPerson"
>
<generator class="uuid.hex"/>
</id>

<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="18"
/>
<property
name="idnumber"
type="java.lang.String"
column="IdNumber"
not-null="true"
length="18"
/>

<!-- Associations -->

<!-- bi-directional one-to-many association to ProviderBill -->
<set
name="providerBills"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="IdProviderPerson"/>
</key>
<one-to-many
class="test.ProviderBill"
/>
</set>
</class>

<sql-query name="ProviderPersonByIdNumber">
<return alias="person" class="test.ProviderPerson"/>
<![CDATA[
select {person.*} from ProviderPerson {person} where IdNumber = :idnumber
]]>
</sql-query>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
See below
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MS SQL Server 2000
The generated SQL (show_sql=true):
N/A
Debug level Hibernate log excerpt:
N/A

I'm using hibernate + session beans on bea weblogic 8.1 sp3. What I'm trying to do is letting the work of managing transactions to the application server, but I think that I have some configuration missing.

When I use the following code between sessionFactory.openSession() and session.close()

it doesn't save anything to the database. The implementation of dao.add it's just a plain call to the session.save().

Code:
String key = (String) dao.add(providerPerson);


But, if I use the above code with a hibernate transaction it works:

Code:
      Transaction transaction = dao.getCurrentTransaction();
      String key = (String) dao.add(providerPerson);
      transaction.commit();


What do I need to configure in order to use the underlying app-container's transaction for my db commands?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 6:38 pm 
Beginner
Beginner

Joined: Tue Oct 26, 2004 12:45 pm
Posts: 43
Location: Israel
Hi.

Did you do session.saveOrUpdate()? did you do session.flush()?

I think that in the first code, you didn't do session.flush(), and therefore, no sql code was executed to the db.

in the second code, the session.flush() wad executed by the transactin.commit().

try the session.flush() (without the transaction) and see if it works for you.

Jus.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 7:33 pm 
Newbie

Joined: Thu Nov 18, 2004 9:28 pm
Posts: 11
Location: Costa Rica
Thank you very much! It worked with the flush() invocation. But anyway I still have problems with the transaction, the following code is going to throw a NullPointerException and I was expecting is that the insert done previously will be rollbacked, but it didn't:

Code:
      String key = (String) dao.add(providerPerson);
      session.flush();
     
      String x = null;
      System.out.println("x.length() = " + x.length());


Do I need some special configuration on the hibernate.cfg.xml?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 10:05 pm 
Newbie

Joined: Thu Nov 18, 2004 9:28 pm
Posts: 11
Location: Costa Rica
Problem solved! I know I should had looked on the manual first but I was on a rush .... here's the solution just in case anyone appears with the same problem:

include the following lines on hibernate.cfg.xml

Code:
<!-- transactions -->
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup</property>
<property name="hibernate.jta.UserTransaction">java:comp/UserTransaction</property>
<!-- /transactions -->


and don't forget to specify the transaction attributes on ejb-jar.xml:

Code:
    <container-transaction>
      <method>
        <ejb-name>ProviderFacadeEJB</ejb-name>
        <method-intf>Local</method-intf>
        <method-name>payBill</method-name>
        <method-params>
          <method-param>test.ProviderBill</method-param>
        </method-params>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.