-->
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.  [ 5 posts ] 
Author Message
 Post subject: EJB - insert fails, non-EJB - insert succeeds
PostPosted: Wed Nov 05, 2003 5:22 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 4:22 pm
Posts: 29
I wrote a simple DAO stateless session bean following several article's recommendation. The bean deploys successfully in JBoss 3.2.1. So I called the insert method from a client, and no error msg displayed. But I checked my database, and nothing was inserted.

So I took converted my DAO code and changed it to the non-EJB version (where you explicitly begin and commit a transaction) and it worked! I'm wondering if I'm missing a declaration in hibernate.cfg.xml or something??


Here is the EJB version of my code:

<ejb code>
Code:
            Context ctx = new InitialContext();
            String jndiName = "java:/hibernate/HibernateFactory";
            SessionFactory factory = (SessionFactory)ctx.lookup(jndiName);
            net.sf.hibernate.Session session = factory.openSession();

            Cat princess = new Cat();
            princess.setId(2);
            princess.setName("Princess Deuce");
            princess.setSex('F');
            princess.setWeight(12.4f);

            session.save(princess);
            session.flush(); // tried w/ and w/out this line, no effect

            session.close();

</ejb code>



Plain vanilla version of code:

<vanilla code>
Code:
            net.sf.hibernate.SessionFactory sessionFactory =
                    new Configuration().configure().buildSessionFactory();

            net.sf.hibernate.Session session = sessionFactory.openSession();
            Transaction transaction = session.beginTransaction();

            Cat princess = new Cat();
            princess.setId(1);
            princess.setName("Princess Deuce");
            princess.setSex('F');
            princess.setWeight(12.4f);

            session.save(princess);
            transaction.commit();

</vanilla code>


EJB hibernate.cfg.xml

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>

        <property name="connection.datasource">java:/TeradataDS</property>
        <property name="dialect">net.sf.hibernate.dialect.TeradataDialect</property>
        <property name="show_sql">true</property>
   <property name="net.sf.hibernate.transaction.JTATransactionFactory">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>

        <!-- Mapping files -->
        <mapping resource="Cat.hbm.xml"/>
        <mapping resource="Employee.hbm.xml"/>
        <mapping resource="Department.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


Vanilla hibernate.cfg.xml

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
    PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>

    <session-factory>

        <property name="show_sql">false</property>
        <property name="dialect">net.sf.hibernate.dialect.TeradataDialect</property>

        <!-- Mapping files -->
        <mapping resource="Cat.hbm.xml"/>
        <mapping resource="Department.hbm.xml"/>
        <mapping resource="Employee.hbm.xml"/>

    </session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You need to set jta.UserTransaction

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 05, 2003 8:01 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 4:22 pm
Posts: 29
Emmanual,

Where are you referring to? In my hibernate sar, I did specify java:/UserTransaction for the UserTransactionName attribute (see below)

Also, in my hibernate.cfg.xml, I specified
<property name="net.sf.hibernate.transaction.JTATransactionFactory">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>

as recommended in articles. Could you clarify? Thanks -

Alex


jboss-service.xml for hibernate sar

Code:
<server>
   <mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
                            name=HibernateFactory">
      <depends>jboss.jca:service=RARDeployer</depends>
      <depends>jboss.jca:service=LocalTxCM,name=TeradataDS</depends>
      <!-- Make it deploy ONLY after DataSource had been started -->
      <attribute name="MapResources">Cat.hbm.xml,Department.hbm.xml,Employee.hbm.xml</attribute>
      <attribute name="JndiName">java:/hibernate/HibernateFactory</attribute>
      <attribute name="Datasource">java:/TeradataDS</attribute>
      <attribute name="Dialect">net.sf.hibernate.dialect.TeradataDialect</attribute>
      <attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
      <attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
      <attribute name="UseOuterJoin">false</attribute>
      <attribute name="ShowSql">true</attribute>
      <attribute name="UserTransactionName">java:/UserTransaction</attribute>
   </mbean>
</server>


Top
 Profile  
 
 Post subject: Re: EJB - insert fails, non-EJB - insert succeeds
PostPosted: Thu Nov 06, 2003 6:59 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
OK, so I don't know (don't use jmx config)

swordsman wrote:
<property name="net.sf.hibernate.transaction.JTATransactionFactory">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>

Is certainly wrong.
Should be
Code:
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>


But I think it's useless since it is defined in your service file as TransactionManagerLookupStrategy

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 5:24 pm 
Beginner
Beginner

Joined: Wed Oct 08, 2003 4:22 pm
Posts: 29
It works now! Thanks for the help.

FYI I'm writing a dialect for Teradata. If you haven't heard of the Teradata RDBMS, you haven't dealt with multi-terabyte databases.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.