-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hbernate base Class
PostPosted: Wed Jul 06, 2005 3:12 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 6:29 am
Posts: 24
Hi,

I am new to newbie i am using HibernateUtil base class for getting session and transaction so when i am using this i am getting session closed error


Thankz in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 06, 2005 5:52 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Seriously, what response do you expect to this posting?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 6:24 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 6:29 am
Posts: 24
I am using Hibernate with standalone Tomcat and also using HibernateUtil
for getting session and Transaction the version i am using is Hibernate3.0

The code which i am getting the error is listed below.


public static String create(ICategory category)throws CategoryNotFoundException
{
if(category==null)
{
throw new CategoryNotFoundException("category Not Found");
}
String msg = "Category created";



try{
HibernateUtil.beginTransaction();
HibernateUtil.getSession().save(category);
HibernateUtil.commitTransaction();
HibernateUtil.closeSession();
} catch(HibernateException ex)
{
System.out.println("Class CategoryManager Function: createCategory");
ex.printStackTrace();
msg= "category All ready Exists";

}

setRefreshed(true);

return msg;
}


This is the method where i am using Hibernate.

When this method is called I am getting the error:

org.hibernate.HibernateException: Session is closed

at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:94)
at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:134)
at com.transversalnet.hibernate.HibernateUtil.rollbackTransaction(HibernateUtil.java:201)
at com.transversalnet.hibernate.HibernateUtil.commitTransaction(HibernateUtil.java:186)
at com.transversalnet.docmanager.category.CategoryManager.create(CategoryManager.java:215)
at com.transversalnet.docmanager.category.CategoryUtil.addRootCategory(CategoryUtil.java:38)

at com.transversalnet.servlets.docmanager.CategoryControllerServlet.doGet(CategoryController
Servlet.java:67)
at com.transversalnet.servlets.docmanager.CategoryControllerServlet.doPost(CategoryControlle
rServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:19
8)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11P
rotocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Class CategoryManager Function: createCategory
org.hibernate.HibernateException: Session is closed
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:94)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:95)
at com.transversalnet.hibernate.HibernateUtil.commitTransaction(HibernateUtil.java:182)
at com.transversalnet.docmanager.category.CategoryManager.create(CategoryManager.java:215)
at com.transversalnet.docmanager.category.CategoryUtil.addRootCategory(CategoryUtil.java:38)

at com.transversalnet.servlets.docmanager.CategoryControllerServlet.doGet(CategoryController
Servlet.java:67)
at com.transversalnet.servlets.docmanager.CategoryControllerServlet.doPost(CategoryControlle
rServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.j
ava:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)



Seriously chritian i am in a totally confused .
i am not able to judge the error.

if u want some other details plz don't hesitate . i am ready to explain
and also one more thing is i am not using JNDI for getting building sessionfactory.

Plz help


Thankz in advance


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 08, 2005 10:52 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
You don't build session correct, probably - see log when call HibernateUtil first time


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 09, 2005 12:35 am 
Beginner
Beginner

Joined: Thu Mar 24, 2005 6:29 am
Posts: 24
Hi,
Here is the logs when starting the Hibernate for the first time

Here i am using Hibernate.cfg.xml as properties and not hibernae.properties



my hibernate.cfg.xml file is like this:



Quote:
<!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.url">jdbc:mysql://localhost/pheonix?autoReconnect=true</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
<property name="connection.pool_size">12</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>


<!-- Mapping files -->


<mapping resource="com/transversalnet/docmanager/category/category.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/category/categorymap.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/category/reviewer.hbm.xml"/>
<mapping resource="com/transversalnet/usersandgroups/svfatwvu.hbm.xml"/>
<mapping resource="com/transversalnet/docmanager/attribute/dmsattribute.hbm.xml"/>

<!-- <mapping resource="com/transversalnet/docmanager/permission/dm_permission.hbm.xml" /> -->

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




And my hibernae logs are as follows:

    INFO: Server startup in 17141 ms
    0 [http-80-Processor25] INFO org.hibernate.cfg.Environment - Hibernate 3.0rc1
    0 [http-80-Processor25] INFO org.hibernate.cfg.Environment - hibernate.properties not found
    15 [http-80-Processor25] INFO org.hibernate.cfg.Environment - using CGLIB reflection optimizer
    15 [http-80-Processor25] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp h
    andling
    15 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibe
    rnate.cfg.xml
    15 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Configuration resource: /hiberna
    te.cfg.xml
    265 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Mapping resource: com/transversa
    lnet/docmanager/category/category.hbm.xml
    453 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.category.Category -> dm_category
    546 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Mapping resource: com/transversa
    lnet/docmanager/category/categorymap.hbm.xml
    812 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.category.CategoryMap -> dm_category_map
    812 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Mapping resource: com/transversa
    lnet/docmanager/category/reviewer.hbm.xml
    843 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.category.CategoryReviewer -> dm_reviewers
    859 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Mapping resource: com/transversa
    lnet/usersandgroups/svfatwvu.hbm.xml
    875 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.ut
    ils.DocmanagerUser -> svfatwvu
    875 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Mapping resource: com/transversa
    lnet/docmanager/attribute/dmsattribute.hbm.xml
    906 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.attribute.Attribute -> dm_attribute
    921 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.attribute.MetadataAttributeMap -> dm_metadata_attribute_map
    921 [http-80-Processor25] INFO org.hibernate.cfg.HbmBinder - Mapping class: com.transversalnet.do
    cmanager.metadata.Metadata -> dm_metadata
    937 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
    937 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - processing extends queue
    937 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - processing collection mappings
    937 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - processing association property
    references
    937 [http-80-Processor25] INFO org.hibernate.cfg.Configuration - processing foreign key constrain
    ts
    1187 [http-80-Processor25] INFO org.hibernate.dialect.Dialect - Using dialect: org.hibernate.diale
    ct.MySQLDialect
    1203 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Maximum outer join fetch depth
    : 2
    1203 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Default batch fetch size: 1
    1218 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Generate SQL with comments: di
    sabled
    1218 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Order SQL updates by primary k
    ey: disabled
    1218 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Query translator: org.hibernat
    e.hql.ast.ASTQueryTranslatorFactory
    1234 [http-80-Processor25] INFO org.hibernate.hql.ast.ASTQueryTranslatorFactory - Using ASTQueryTr
    anslatorFactory
    1234 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Query language substitutions:
    {}
    1265 [http-80-Processor25] INFO org.hibernate.connection.DriverManagerConnectionProvider - Using H
    ibernate built-in connection pool (not for production use!)
    1265 [http-80-Processor25] INFO org.hibernate.connection.DriverManagerConnectionProvider - Hiberna
    te connection pool size: 12
    1265 [http-80-Processor25] INFO org.hibernate.connection.DriverManagerConnectionProvider - autocom
    mit mode: false
    1281 [http-80-Processor25] INFO org.hibernate.connection.DriverManagerConnectionProvider - using d
    river: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/pheonix?autoReconnect=true
    1281 [http-80-Processor25] INFO org.hibernate.connection.DriverManagerConnectionProvider - connect
    ion properties: {user=root, password=****}
    1531 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - JDBC batch size: 15
    1531 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - JDBC batch updates for version
    ed data: disabled
    1531 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Scrollable result sets: enable
    d
    1546 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - JDBC3 getGeneratedKeys(): enab
    led
    1546 [http-80-Processor25] INFO org.hibernate.transaction.TransactionFactoryFactory - Using defaul
    t transaction strategy (direct JDBC transactions)
    1562 [http-80-Processor25] INFO org.hibernate.transaction.TransactionManagerLookupFactory - No Tra
    nsactionManagerLookup configured (in JTA environment, use of read-write or transactional second-leve
    l cache is not recommended)
    1562 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Automatic flush during beforeC
    ompletion(): disabled
    1578 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Automatic session close at end
    of transaction: disabled
    1578 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Cache provider: org.hibernate.
    cache.EhCacheProvider
    1593 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Second-level cache: enabled
    1593 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Optimize cache for minimal put
    s: disabled
    1593 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Structured second-level cache
    entries: enabled
    1593 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Query cache: disabled
    1593 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Echoing all SQL to stdout
    1625 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Statistics: disabled
    1625 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Deleted entity synthetic ident
    ifier rollback: disabled
    1625 [http-80-Processor25] INFO org.hibernate.cfg.SettingsFactory - Default entity-mode: pojo
    2031 [http-80-Processor25] INFO org.hibernate.impl.SessionFactoryImpl - building session factory
    2062 [http-80-Processor25] WARN net.sf.ehcache.config.Configurator - No configuration found. Confi
    guring ehcache from ehcache-failsafe.xml found in the classpath: file:/E:/Phoenix/PHONEIX II/jakarta
    -tomcat-5.0.28/work/Catalina/localhost/phoenix/loader/ehcache-failsafe.xml
    3421 [http-80-Processor25] INFO org.hibernate.impl.SessionFactoryObjectFactory - Not binding facto
    ry to JNDI, no JNDI name configured


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 15, 2006 3:04 am 
Newbie

Joined: Wed Mar 15, 2006 10:31 am
Posts: 5
Hi,

I think your HibernateUtil is not good.

Can you paste the code of the HibernateUtil Class please ?

Piwi


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