-->
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.  [ 1 post ] 
Author Message
 Post subject: Am I using hibernate correctly
PostPosted: Fri Jun 09, 2006 9:04 am 
Newbie

Joined: Fri May 26, 2006 5:16 am
Posts: 13
I'm having some problems related to persistance that don't seem to be logical, so I guess i'm doing something wrong with the way I'm using hibernate.. :P

The thing is, Hibernate will usually only let me perform one insert,update or delete. Then it just stops updating the database, no errors at all.

And then there is the transactionmanager, that keeps timing out, giving me 500 errors, or keeps complaining about beeing marked for rollback. Only solution is to restart the jboss instance.

I've read up on both these problems, and have tried multiple configurations, but nothing seems to help. The problem started when I upgraded my Jboss to 4.0.4 to take advantage of the new jbossWS.

this is the console when I deploy my app:
Code:
14:43:51,876 INFO  [Configuration] Searching for mapping documents in jar: tmp30994trim.sar
14:43:51,878 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Activity.hbm.xml
14:43:51,923 INFO  [HbmBinder] Mapping class: valueObjects.Activity -> activity
14:43:51,930 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/ActivityLine.hbm.xml
14:43:51,959 INFO  [HbmBinder] Mapping class: valueObjects.ActivityLine -> activityline
14:43:51,967 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/ActivityType.hbm.xml
14:43:52,007 INFO  [HbmBinder] Mapping class: valueObjects.ActivityType -> activitytype
14:43:52,013 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Contact.hbm.xml
14:43:52,032 INFO  [HbmBinder] Mapping class: valueObjects.Contact -> contact
14:43:52,039 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Module.hbm.xml
14:43:52,051 INFO  [HbmBinder] Mapping class: valueObjects.Module -> module
14:43:52,053 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/ModuleAccess.hbm.xml
14:43:52,065 INFO  [HbmBinder] Mapping class: valueObjects.ModuleAccess -> moduleaccess
14:43:52,067 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Relation.hbm.xml
14:43:52,080 INFO  [HbmBinder] Mapping class: valueObjects.Relation -> relation
14:43:52,085 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/RelationType.hbm.xml
14:43:52,139 INFO  [HbmBinder] Mapping class: valueObjects.RelationType -> relationtype
14:43:52,144 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Resource.hbm.xml
14:43:52,178 INFO  [HbmBinder] Mapping class: valueObjects.Resource -> resource
14:43:52,185 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/ResourceCategory.hbm.xml
14:43:52,198 INFO  [HbmBinder] Mapping class: valueObjects.ResourceCategory -> resourcecategory
14:43:52,200 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/ResourceType.hbm.xml
14:43:52,219 INFO  [HbmBinder] Mapping class: valueObjects.ResourceType -> resourcetype
14:43:52,224 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Status.hbm.xml
14:43:52,237 INFO  [HbmBinder] Mapping class: valueObjects.Status -> status
14:43:52,241 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/SystemDefault.hbm.xml
14:43:52,257 INFO  [HbmBinder] Mapping class: valueObjects.SystemDefault -> systemdefault
14:43:52,259 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Unit.hbm.xml
14:43:52,275 INFO  [HbmBinder] Mapping class: valueObjects.Unit -> unit
14:43:52,276 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/UserGroup.hbm.xml
14:43:52,322 INFO  [HbmBinder] Mapping class: valueObjects.UserGroup -> usergroup
14:43:52,325 INFO  [Configuration] Found mapping document in jar: hibernate_hbm/Users.hbm.xml
14:43:52,346 INFO  [HbmBinder] Mapping class: valueObjects.Users -> users
14:43:52,390 WARN  [RootClass] composite-id class does not override equals(): valueObjects.ModuleAccess
14:43:52,391 WARN  [RootClass] composite-id class does not override hashCode(): valueObjects.ModuleAccess
14:43:52,393 INFO  [NamingHelper] JNDI InitialContext properties:{}
14:43:52,398 INFO  [DatasourceConnectionProvider] Using datasource: java:/PostgresDS
14:43:52,406 INFO  [SettingsFactory] RDBMS: PostgreSQL, version: 8.0.4
14:43:52,406 INFO  [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.0 JDBC3 with SSL (build 314)
14:43:52,407 INFO  [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
14:43:52,409 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
14:43:52,410 INFO  [NamingHelper] JNDI InitialContext properties:{}
14:43:52,411 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
14:43:52,413 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
14:43:52,413 INFO  [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
14:43:52,415 INFO  [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
14:43:52,416 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): enabled
14:43:52,425 INFO  [SettingsFactory] Automatic session close at end of transaction: enabled
14:43:52,426 INFO  [SettingsFactory] JDBC batch size: 15
14:43:52,426 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
14:43:52,427 INFO  [SettingsFactory] Scrollable result sets: enabled
14:43:52,428 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
14:43:52,428 INFO  [SettingsFactory] Connection release mode: after_statement
14:43:52,429 INFO  [SettingsFactory] Default batch fetch size: 1
14:43:52,430 INFO  [SettingsFactory] Generate SQL with comments: disabled
14:43:52,431 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
14:43:52,431 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:43:52,432 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
14:43:52,433 INFO  [SettingsFactory] Query language substitutions: {}
14:43:52,433 INFO  [SettingsFactory] Second-level cache: enabled
14:43:52,434 INFO  [SettingsFactory] Query cache: disabled
14:43:52,435 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
14:43:52,435 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
14:43:52,436 INFO  [SettingsFactory] Structured second-level cache entries: disabled
14:43:52,437 INFO  [SettingsFactory] Echoing all SQL to stdout
14:43:52,438 INFO  [SettingsFactory] Statistics: disabled
14:43:52,438 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
14:43:52,439 INFO  [SettingsFactory] Default entity-mode: pojo
14:43:52,460 INFO  [SessionFactoryImpl] building session factory
14:43:53,278 INFO  [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
14:43:53,279 INFO  [NamingHelper] JNDI InitialContext properties:{}
14:43:53,281 INFO  [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/TRIMSessionFactory]


this is my jboss-service.xml file:
Code:
<server>
    <mbean code="org.jboss.hibernate.jmx.Hibernate" name="jboss.TRIM:name=HibernateSessionFactory">
        <!-- Wait for the Postgres Datasource to be defined -->
        <!-- <depends>jboss.jca:service=RARDeployer</depends> -->
        <!-- <depends>jboss.jca:service=LocalTxCM,name=PostgresDS</depends> -->
        <depends>jboss.jca:service=DataSourceBinding,name=PostgresDS</depends>
       
        <attribute name="DatasourceName">java:/PostgresDS</attribute>
        <attribute name="Dialect">org.hibernate.dialect.PostgreSQLDialect</attribute>
        <attribute name="Username">admin</attribute>
        <attribute name="Password">123456</attribute>
        <attribute name="SessionFactoryName">java:/hibernate/TRIMSessionFactory</attribute>
       
       
        <!--  We do want hibernate to look everywhere for mapping files-->
        <attribute name="ScanForMappingsEnabled">true</attribute>
       
        <!-- We also want to see the actual SQL -->
        <attribute name="ShowSqlEnabled">true</attribute>
       
        <!-- Second level caching   -->
        <attribute name="SecondLevelCacheEnabled">true</attribute>
        <attribute name="CacheProviderClass">org.hibernate.cache.EhCacheProvider</attribute>
        <attribute name="QueryCacheEnabled">true</attribute>
     
    </mbean>
</server>


And this is how I set up the sessionfactory:
Code:
package session;

import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;


public class HibernateSessionFactory {



   public static Session currentSession() throws HibernateException {
       InitialContext ctx;
       SessionFactory factory = null;
      try {
         ctx = new InitialContext();
         factory = (SessionFactory) ctx.lookup("java:/hibernate/TRIMSessionFactory");
      } catch (NamingException e) {
         e.printStackTrace();
      }       
       Session session = factory.openSession();
        return session;
    }

    public static void closeSession() throws HibernateException {
       InitialContext ctx;
        SessionFactory factory = null;
      try {
         ctx = new InitialContext();
         factory = (SessionFactory) ctx.lookup("java:/hibernate/TRIMSessionFactory");
         } catch (NamingException e) {
         e.printStackTrace();
      }
       Session session = factory.openSession();
        if (session != null) {
            session.close();
        }
    }

    /**
     * Default constructor.
     */
    private HibernateSessionFactory() {
    }

}



..and this is how I use it in a class:
Code:
     try {

         session = HibernateSessionFactory.currentSession();
         
         transaction = session.beginTransaction();
         
         Integer integerRelationID = ( Integer ) session.save( relation );
         

         transaction.commit();
         
         return integerRelationID;
         
      } catch (HibernateException hex) {


I'm guessing the problem is either with the way i use the sessionfactory, or the way I'm using it to create sessions/commit.

Anybody who can tell me what I'm doing wrong? Or what I should do differently?
I'm also interrested in opinions on how I'm using the sessions/transactions, is it the correct/preferred way when using an Mbean?

Regards


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

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.