-->
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.  [ 11 posts ] 
Author Message
 Post subject: Unable to see any any persisted data using CMT/Weblogic8.1
PostPosted: Sat Aug 30, 2003 7:04 pm 
Newbie

Joined: Sat Aug 30, 2003 5:55 pm
Posts: 7
I'm sorry that this is such a basic question, but I have not been able to figure out why Hibernate is not persisting my data. I am trying to use Hibernate2 within my session beans and let the session beans manage the transactions (CMT). However, although the code acts like everything is ok and no exceptions are thrown, I never see any changes to the database. I have 'view SQL output' turned on and I never see any SQL output. I am using Weblogic8.1 and a datasource pointing to a MySql database. I'm thinking its got to be a configuration error on my part, but I have not been able to figure out what it is. What's driving me even more crazy is that I've used similar code successfully on JBoss using Hibernate 1.2. Anyway, any and all input on what my problem may be would be GREATLY appreciated!

EJB Code
public void createPerson(String identifier) {
Assert.assertNotNull(identifier);
Session s = null;
try {
InitialContext ctx = new InitialContext();
SessionFactory factory =
(SessionFactory) ctx.lookup (Config.getHibernateSessionFactory());

s = factory.openSession();
Person p = new Person();
p.setIdentifier(identifier);

s.save(p);
s.flush();
s.close();
} catch(Exception e) {
// Rethrow as SystemException
throw new SystemException(e);
}

}

hibernate.cfg.xml
<hibernate-configuration>
<!-- a SessionFactory instance listed as /jndi/name -->
<session-factory name="HibernateSessionFactory">
<!-- MySQL -->

<property name="connection.datasource">jdbc/MysqlDS</property>
<property "dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="jdbc.use_streams_for_binary">true</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory</property>

<!-- mapping files -->
<mapping resource="Person.hbm.xml"/>
</session-factory>
</hibernate-configuration>

hibernate.properties
hibernate.show_sql true
hibernate.use_outer_join true
hibernate.jdbc.use_streams_for_binary true
hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory
hibernate.connection.datasource jdbc/MysqlDS
hibernate.dialect net.sf.hibernate.dialect.MySQLDialect
hibernate.session_factory_name HibernateSessionFactory


Hibernate Mapping File
<?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>
<class
name="com.harley_davidson.wup.persist.model.system.Person"
table="wupprsn"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="id"
column="id"
type="java.lang.String"
unsaved-value="any"
>
<generator class="uuid.hex">
</generator>
</id>

<version
name="version"
type="java.lang.Integer"
column="version"
/>

<property
name="identifier"
type="java.lang.String"
update="true"
insert="true"
column="identifier"
/>

<property
name="createdBy"
type="java.lang.String"
update="true"
insert="true"
column="createdBy"
/>

<property
name="createdOn"
type="java.util.Date"
update="true"
insert="true"
column="createdOn"
/>

<property
name="updatedBy"
type="java.lang.String"
update="true"
insert="true"
column="updatedBy"
/>

<property
name="updatedOn"
type="java.util.Date"
update="true"
insert="true"
column="updatedOn"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Person.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 30, 2003 9:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks to me like the transaction is not beimng committed. Are you absolutely certain that your datasource is using JTA?

And are you certain Hibernate is fetching the connection from the datasource (check the hibernate log).


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 8:42 pm 
Newbie

Joined: Sat Aug 30, 2003 5:55 pm
Posts: 7
Thank you for the quick response. I believe that I have the DataSource setup correctly. I can subsitute the following code in my Session bean and I see the data in the database... (Note: Here I am using a SQL Server DataSource). Once I found that by explicitly getting a Connection from the DataSource and executing a PreparedStatement worked I then tried to create a Hibernate Session by passing in a Connection from the same DataSource. However, this did not result in any data being persisted. I'm wondering if there is a special property that I need to make sure is set and if it needs to be specified in the hibernate.cfg.xml or in the hibernate.properties file. I'm using Weblogic8.1, so I'm also wondering if anyone has successfuly used Hibernate on this platform? Also, I am using Java logging with ".level = ALL", but I have not seen any output from Hibernate other than when I call Hibernate.configure().buildSessionFactory().


Local Session bean code that results in data bing commited
DataSource ds = (DataSource)
(new InitialContext().lookup("jdbc/XASqlServerDS"));
Connection c = ds.getConnection();
String SQL_CREATE =
" insert into wup.wupprsn (id, version) values ( ?, ? ) ";
PreparedStatement ps = c.prepareStatement(SQL_CREATE);
ps.setString(1, "12345");
ps.setInt(2, 1);
ps.executeUpdate();
ps.close();
c.close();

Local Session bean code that does not result in data bing commited
SessionFactory sf =
(SessionFactory) new InitialContext().
lookup(Config.getHibernateSessionFactory());
DataSource ds =
(DataSource)(new InitialContext().lookup("jdbc/XASqlServerDS"));
s = sf.openSession(ds.getConnection());
Person p = new Person();
p.setIdentifier(identifier);
s.saveOrUpdate(p);
s.flush();
s.close();


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 9:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ah I think you are looking in the wrong place for the problem. The Hibernate code looks perfect.


If you are not seeing any log output from Hibernate, then absolutely certainly the problem is that the Hibernate code is not being called!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 9:48 pm 
Newbie

Joined: Sat Aug 30, 2003 5:55 pm
Posts: 7
I do see the logging 'INFO' output from when I do a Hibernate.configure().createSessionFactory(). What could be the reason that the Hibernate code is not being executed? Is is a configuation problem I have in my hibernate.cfg.xml or hibernate.properties? I guess I'm really wondering where I go from here. I loved using Hibernate on JBoss/MySQL and I would like to do the same with Weblogic8.1/SQLServer. Any and all information would be greatly appreciated!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 9:52 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I do see the logging 'INFO' output from when I do a Hibernate.configure().createSessionFactory().



But are you doing that from the same method as the one you just showed me? Doesn't look like it!

Are you CERTAIN that method is being called?



P.S. Other people are using Hibernate with WLS. We know there are some issues with a braindead JNDI implementation in at least some versions, but otherwise it works fine.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 10:41 pm 
Newbie

Joined: Sat Aug 30, 2003 5:55 pm
Posts: 7
Originally I had a servlet which called 'new Configuration().configure().buildSesionFactory() and then did a bind of the SessionFactory for JNDI lookup. This time I tried the following code so that I built the SessionFactory in the same EJB method call. I see Hibernate logging INFO messages when it configures and builds the SessionFactory, but I still didn't see Hibernate logging when I do a flush() and I don't see any data persisted. I'll bet it is some simple setting I must be missing and I appreciate your patience very much. Would it be possible to refer me to some other developers who have been working with Hibernate and Weblogic? Also, if I am creating the SessionFactory on the fly and I create a Session by directly passing in the Connection object, what could be a possible reason for it seeming to bypass Hibernate? Thanks again for your help! NOTE: I also listed the output I am seeing at the console in case that helps...


SessionFactory sf =
new Configuration().configure().buildSessionFactory();
DataSource ds =
(DataSource)(new InitialContext().lookup("jdbc/XASqlServerDS"));
s = sf.openSession(ds.getConnection());
Person p = new Person();
p.setIdentifier(identifier);
s.saveOrUpdate(p);
s.flush();
s.close();

INFO cfg.Environment - Hibernate 2.0.3
INFO cfg.Environment - loaded properties from resource hibernate.properties: {hibernate.sessio
n_factory_name=HibernateSessionFactory, hibernate.transaction.manager_lookup_cla
ss=net.sf.hibernate.transaction.WeblogicTransactionManagerLookup, hibernate.cgli
b.use_reflection_optimizer=true, hibernate.jdbc.use_streams_for_binary=true, hib
ernate.use_outer_join=true , hibernate.show_sql=true , hibernate.transaction.fac
tory_class=net.sf.hibernate.transaction.JTATransactionFactory}
INFO cfg.Environment - using java.io streams to persist binary types
INFO cfg.Environment - using CGLIB reflection optimizer
INFO cfg.Environment - JVM proxy support: true
INFO cfg.Configuration - Configuration resource: /hibernate.cfg.xml
INFO cfg.Configuration - Mapping resource:com/harley_davidson/wup/persist/model/system/SystemRoot.hbm.xml
INFO cfg.Binder - Mapping class: com.harley_davidson.wup.persist.model.system.SystemRoot ->wupsystmrt
INFO cfg.Configuration - Mapping resource: com/harley_davidson/wup/persist/model/system/Person.hbm.xml
INFO cfg.Binder- Mapping class: com.harley_davidson.wup.persist.model.system.Person -> wupprsn
INFO cfg.Configuration - Configured SessionFactory: HibernateSessionFactory
INFO cfg.Configuration - processing one-to-many association mappings
INFO cfg.Configuration - processing foreign key constraints
INFO impl.SessionFactoryImpl - building session factory
INFO dialect.Dialect - Using dialect: net.sf.hibernate.dialect.SybaseDialect
INFO util.NamingHelper - JNDI InitialContext properties:{hibernate.jndi=HibernateSessionFactory}
INFO connection.DatasourceConnectionProvider - Using datasource: jdbc/XASqlServerDS
INFO impl.SessionFactoryImpl - Use outer join fetching: true
INFO impl.SessionFactoryImpl - Use scrollable result sets: true
INFO impl.SessionFactoryImpl - Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
INFO util.NamingHelper - JNDI InitialContext properties:{hibernate.jndi=HibernateSessionFactory}
INFO transaction.JTATransactionFactory - Locating TransactionManager using: net.sf.hibernate.transaction.WeblogicTransactionManagerLookup
INFO util.NamingHelper - JNDI InitialContext properties:{hibernate.jndi=HibernateSessionFactory}
INFO transaction.JTATransactionFactory - TransactionManager lookup successful
INFO impl.SessionFactoryImpl - echoing all SQL to stdout
INFO impl.SessionFactoryObjectFactory - Factory name: HibernateSessionFactory
INFO util.NamingHelper - JNDI InitialContext properties:{hibernate.jndi=HibernateSessionFactory}
INFO impl.SessionFactoryObjectFactory - Bound factory to JNDI name: HibernateSessionFactory
WARN impl.SessionFactoryObjectFactory - InitialContext did not implement EventContext
INFO impl.SessionFactoryImpl - Query language substitutions: {}


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 11:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Looks like you did not actually enable debug-level logging. This would help a lot, obviously.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Aug 31, 2003 11:38 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I use Hibernate with weblogic (although we currently are on 6.1.5). I have not seen anything like this. As Gavin mentioned, it really seems as if your method might not be getting called.

Can you put some log statements in your session bean code? Maybe something like:
Code:
public void createPerson(String identifier)
{
    Assert.assertNotNull(identifier);
    Session s = null;
    try
    {
        String namespace = Config.getHibernateSessionFactory();
        log.debug( "Looking up session factory [" + namespace + "]" );
        InitialContext ctx = new InitialContext();
        SessionFactory factory = (SessionFactory)ctx.lookup( namespace );

        log.debug( "Getting session from obtained factory" );
        s = factory.openSession();
        Person p = new Person();
        p.setIdentifier( identifier );

        log.debug( "Saving and flushing new Person" );
        s.save(p);
        s.flush();
        s.close();
    }
    catch( Exception e )
    {
        log.error( "Error performing operation", e );
        // Rethrow as SystemException
        throw new SystemException( e );
    }

}


Then how does the output appear?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2003 2:18 am 
Newbie

Joined: Sat Aug 30, 2003 5:55 pm
Posts: 7
First of all I would like to thank you all for putting up with me. After looking at my class structure (Person subclassing abstract class Entity) I noticed that my base class which implemented Lifecycle was actually vetoing any attempt to persist the subclass. DOH!!!! Anyway, after changing this I am now able to successfully persist data to SQL Server.

Thanks again to everyone!


Top
 Profile  
 
 Post subject: same problem in WLS8.1 with data not persisting
PostPosted: Wed Sep 08, 2004 6:43 pm 
Newbie

Joined: Mon Jun 07, 2004 12:31 pm
Posts: 1
Hi,

I am having the same problem above but unfortunely it does not seem the VETO issue as described. Any help would be really appreciated.

Hibernate.cfg.xml
Code:
<hibernate-configuration>

   <session-factory name="hibernate.session-factory.Oracle">
       <property name="connection.datasource">ectrackDS</property>
       <property name="show_sql">true</property>
       <property name="dialect">net.sf.hibernate.dialect.OracleDialect</property>
       <property name="jndi.class">weblogic.jndi.WLInitialContextFactory</property>
       <property name="jndi.url">t3://127.0.0.1:7001</property>
       <property name="hibernate.transaction.manager_lookup_class">net.sf.hibernate.transaction.WeblogicTransactionManagerLookup </property>

     <mapping resource="edu/mit/ssit/mysample/model/Student.hbm.xml"/>

  </session-factory>
</hibernate-configuration


HBNSessionManager: (taken pretty well from the caveatemptor app and info from hibernate in action

Code:
public class HibernateSessionManager
{
     public String _id = "$Id: $";
     private static final Category log = Category.getInstance(HibernateSessionManager.class.getName());
      private static final ThreadLocal threadTransaction = new ThreadLocal();
      public static final ThreadLocal threadSession = new ThreadLocal();
   
   
    private static final SessionFactory sessionFactory;
    static
    {
        try
        {
           
            // Create the SessionFactory
            log.debug("Attempting to create the Hibernate Session Factory");
            //session factory is now in JNDI based on values from hibernate.cfg.xml
            sessionFactory = new Configuration().configure().buildSessionFactory();
            log.debug("Hibernate Session Factory created successfully");
         }
        catch (HibernateException ex)
        {
            log.debug("Hibernate Exception when attempting to create the session factory:"+ex.getMessage());
            ex.printStackTrace();
            throw new RuntimeException("Hibernate Configuration problem: " + ex.getMessage(), ex);
        }
    }
     
   
   
   
    public static SessionFactory getSessionFactory()
    {
        SessionFactory sessions = null;
        try
        {
            Context ctx = new InitialContext();
            String jndiName = "java:hibernate/HibernateFactory";
            sessions = (SessionFactory)ctx.lookup("hibernate.session-factory.Oracle");
        }
        catch(NamingException ex)
        {
            throw new RuntimeException("Failed to get HibernateSessionFactory from context");
        }
        return sessions;
    }
 
     /**
      * Retrieves the current Session local to the thread.
      * <p/>
      * If no Session is open, opens a new Session for the running thread.
      *
      * @return Session
      */
     public static Session getSession()
        throws HibernateException {
        Session s = (Session) threadSession.get();
        try
        {
           if (s == null)
           {
              log.debug("Opening new Session for this thread.");
              s = getSessionFactory().openSession();
           }
              threadSession.set(s);
        }
        catch (HibernateException ex)
        {
          log.error("Failed to get hibernate session:"+ex.getMessage());
           throw ex;
        }
        return s;
     }
     
     /*
    public static Session currentSession() throws HibernateException
    {
        log.debug("Attempting to get current session");
         Session s = (Session) session.get();
         log.debug("Session is "+s);
        // Open a new Session, if this Thread has none yet
        if (s == null)
        {
            log.debug("Session was null. Attempting to open a new session");
            s = sessionFactory.openSession();
            log.debug("New Session created");
            session.set(s);
            log.debug("Session set successfully");
        }
        return s;
    }
    */
     
     /*
    public static void closeSession() throws HibernateException
    {
        Session s = (Session) session.get();
        session.set(null);
        if (s != null)
        s.close();
    }
    */
     /**
      * Start a new database transaction.
      */
     public static void beginTransaction()
        throws HibernateException
   {
        Transaction tx = (Transaction) threadTransaction.get();
        try {
           if (tx == null)
           {
              log.debug("Starting new database transaction in this thread.");
              tx = getSession().beginTransaction();
              threadTransaction.set(tx);
           }
        } catch (HibernateException ex)
        {
          log.error("Failed to begin hibernate transaction."+ex.getMessage());
           throw ex;
        }
     }
     

     /**
      * Closes the Session local to the thread.
      */
     public static void closeSession()
        throws HibernateException
        {
         try
         {
              Session s = (Session) threadSession.get();
              threadSession.set(null);
              if (s != null && s.isOpen())
              {
                 log.debug("Closing Session of this thread.");
                 s.close();
              }
         }
         catch (HibernateException ex)
         {
             log.error("Failed to close hibernate session."+ex.getMessage());
             throw ex;
         }
     }
     
     public static void commitTransaction()
      throws HibernateException
      {
         Transaction tx = (Transaction) threadTransaction.get();
         try
         {
            if ( tx != null && !tx.wasCommitted()
                        && !tx.wasRolledBack() )
            {
               log.debug("Committing database transaction of this thread.");
               tx.commit();
            }
            threadTransaction.set(null);
         }
         catch (HibernateException ex)
         {
           log.error("Hibernate commit failed. Attempting to rollback. "+ex.getMessage());
            rollbackTransaction();
            throw ex;
         }
   }

   /**
    * Commit the database transaction.
    */
   public static void rollbackTransaction()
      throws HibernateException
   {
      Transaction tx = (Transaction) threadTransaction.get();
      try
      {
         threadTransaction.set(null);
         if ( tx != null && !tx.wasCommitted() && !tx.wasRolledBack() ) {
            log.debug("Tyring to rollback database transaction of this thread.");
            tx.rollback();
         }
      }
      catch (HibernateException ex)
      {
          log.error("Rollback failed. "+ex.getMessage());
          throw ex;
      }
      finally
      {
         closeSession();
      }
   }
   
} //end of class


I am using a sessionbean to call a dao (but currently handling transactions in the Session bean (or trying to anyway):
StudentSessionBean:
Code:
public void updateStudent(Student criteria)
      throws Exception
  {
      log.info("updating student ID:"+criteria.getStudentId());
      try
      {
          new StudentDAO().updateStudent(criteria);
          //we want our container to handle transactions
          HibernateSessionManager.commitTransaction();
      }
      catch(Exception e)
      {
          throw e; //we logged it already
      }
      finally
      {
          HibernateSessionManager.closeSession();
      }
     
  }

DAO that does the update:
Code:
   public void updateStudent(Student student) throws HibernateException
   {
       Session hbnsession = null;
      List results = null;
     
      try
      {
         
         hbnsession = HibernateSessionManager.getSession();
       hbnsession.update(student);
      }
      catch (HibernateException e)
     {
         log.error(e.getMessage());
         //TODO: map this to a generic infrastructure exception
         throw e;
     }
   }

I am using middlegen to generate the POJO and mark it up with hibernate tags. Here is the mapping file:

Code:
<hibernate-mapping>
<class
    name="com.mysample.model.Student"
    table="STUDENT"
>
    <meta attribute="class-description" inherit="false">
       @hibernate.class
        table="STUDENT"
    </meta>

    <composite-id>
        <meta attribute="class-description" inherit="false">
           @hibernate.id
            generator-class="assigned"
        </meta>
        <key-property
            name="studentId"
            column="STUDENT_ID"
            type="java.math.BigDecimal"
            length="22"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="STUDENT_ID"
            </meta>
        </key-property>
        <key-property
            name="firstName"
            column="FIRST_NAME"
            type="java.lang.String"
            length="30"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="FIRST_NAME"
            </meta>
        </key-property>
        <key-property
            name="lastName"
            column="LAST_NAME"
            type="java.lang.String"
            length="30"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="LAST_NAME"
            </meta>
        </key-property>
        <key-property
            name="gender"
            column="GENDER"
            type="java.lang.String"
            length="1"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="GENDER"
            </meta>
        </key-property>
        <key-property
            name="graduationYear"
            column="GRADUATION_YEAR"
            type="java.lang.Integer"
            length="4"
        >
            <meta attribute="field-description">
               @hibernate.property
                column="GRADUATION_YEAR"
            </meta>
        </key-property>
    </composite-id>   


    <!-- associations -->

</class>
</hibernate-mapping>


Everything works fine re a select so I know the JNDI mapping is fine...The problem is if I try and persist it never gets saved when running in Weblogic8.1 I do not see an messages get written to the log (although I can only set it to INFO as DEBUG makes my app server (running on a laptop) run out of memory.

Any help would be appreciated..

Thanks!


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