-->
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: org.hibernate.HibernateException: Not able to obtain connect
PostPosted: Tue Nov 01, 2005 1:34 pm 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Hallo,

ich versuche gerade ein Beispiel aus einem Tutorial zu Hibernate nachzuprogrammieren.
Ich möchte einfach einen Datensatz, der einen Usernamen und ein Passwort enthält, in eine Datenbank schreiben.
Leider landet in der Datenbank überhaupt nichts, obwohl der erste Aufruf ohne Execption durchläuft.
Der 2. Aufruf liefert mir dann die Meldung "Hibernate ExceptionNot able to obtain connection".
Das ganze ist eine Webapplikation mit Struts und läuft in einem Tomcat5.
Erstellt habe ich das ganze Projekt mit MyEclipse, das die Hibernate Konfiguration und Mappings automatisch erstellt hat.
Ich hoffe jemand hier kann mir damit helfen, vielen Dank schonmal.

Sven


Hibernate version:

Hibernate3

Mapping documents:

<hibernate-configuration>

<session-factory>
<property name="myeclipse.connection.profile">mylocal</property>
<property name="connection.url">jdbc:mysql://localhost/userdaten</property>
<property name="connection.username">borkert</property>
<property name="connection.password">xyz</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property name="show_sql">true</property>

<mapping resource="com/borkert/Hibernate/Users.hbm.xml" />

</session-factory>

</hibernate-configuration>

<hibernate-mapping package="com.borkert.Hibernate">

<class name="Users" table="users">
<id name="id" column="id" type="integer">
<generator class="native"/>
</id>

<property name="username" column="username" type="string" />
<property name="password" column="password" type="string" />
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

public void addUserdata(Users data)
{

Session session = null;

try
{
session = SessionFactory.currentSession();
session.save(data);
session.flush();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}
/*
* Regardless of whether the above processing resulted in an Exception
* or proceeded normally, we want to close the Hibernate session. When
* closing the session, we must allow for the possibility of a Hibernate
* Exception.
*
*/
finally
{
if (session != null)
{
try
{

session.close();
}
catch (HibernateException e)
{
System.err.println("Hibernate Exception" + e.getMessage());
throw new RuntimeException(e);
}

}
}

}
}

Full stack trace of any exception that occurs:

javax.servlet.ServletException: org.hibernate.HibernateException: Not able to obtain connection
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.RuntimeException: org.hibernate.HibernateException: Not able to obtain connection
com.borkert.Hibernate.UserService.addUserdata(UserService.java:260)
com.borkert.struts.action.AdduserAction.execute(AdduserAction.java:51)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Name and version of the database you are using:

Konnte das Problem Sowohl mit Postgresql8 sowie mit Mysql5 reproduzieren.

The generated SQL (show_sql=true):

...
INFO: Server startup in 5063 ms
Hibernate: insert into users (username, password) values (?, ?)
Hibernate ExceptionNot able to obtain connection


Debug level Hibernate log excerpt:

18:13:47,225 INFO Environment:464 - Hibernate 3.0.5
18:13:47,240 INFO Environment:477 - hibernate.properties not found
18:13:47,240 INFO Environment:510 - using CGLIB reflection optimizer
18:13:47,256 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
18:13:47,475 INFO Configuration:1110 - configuring from resource: /hibernate.cfg.xml
18:13:47,475 INFO Configuration:1081 - Configuration resource: /hibernate.cfg.xml
18:13:47,662 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath under org/hibernate/
18:13:47,662 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... on-3.0.dtd in classpath
18:13:47,756 DEBUG Configuration:1067 - myeclipse.connection.profile=mylocal
18:13:47,756 DEBUG Configuration:1067 - connection.url=jdbc:mysql://localhost/userdaten
18:13:47,756 DEBUG Configuration:1067 - connection.username=borkert
18:13:47,756 DEBUG Configuration:1067 - connection.password=password
18:13:47,771 DEBUG Configuration:1067 - connection.driver_class=com.mysql.jdbc.Driver
18:13:47,771 DEBUG Configuration:1067 - dialect=org.hibernate.dialect.MySQLDialect
18:13:47,771 DEBUG Configuration:1067 - show_sql=true
18:13:47,771 DEBUG Configuration:1262 - null<-org.dom4j.tree.DefaultAttribute@b70648 [Attribute: name resource value "com/borkert/Hibernate/Users.hbm.xml"]
18:13:47,771 INFO Configuration:444 - Mapping resource: com/borkert/Hibernate/Users.hbm.xml
18:13:47,787 DEBUG DTDEntityResolver:42 - trying to locate http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath under org/hibernate/
18:13:47,787 DEBUG DTDEntityResolver:53 - found http://hibernate.sourceforge.net/hibern ... ng-3.0.dtd in classpath
18:13:48,037 INFO HbmBinder:260 - Mapping class: com.borkert.Hibernate.Users -> users
18:13:48,053 DEBUG HbmBinder:1099 - Mapped property: id -> id
18:13:48,084 DEBUG HbmBinder:1099 - Mapped property: username -> username
18:13:48,100 DEBUG HbmBinder:1099 - Mapped property: password -> password
18:13:48,100 INFO Configuration:1222 - Configured SessionFactory: null
18:13:48,100 DEBUG Configuration:1223 - properties: {show_sql=true, java.vendor=Sun Microsystems Inc., catalina.base=C:\Programme\Apache Software Foundation\Tomcat 5.5, hibernate.connection.url=jdbc:mysql://localhost/userdaten, sun.management.compiler=HotSpot Client Compiler, catalina.useNaming=true, os.name=Windows XP, sun.boot.class.path=C:\Programme\Java\jdk1.5.0_04\jre\lib\rt.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\i18n.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\sunrsasign.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\jsse.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\jce.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\charsets.jar;C:\Programme\Java\jdk1.5.0_04\jre\classes, sun.desktop=windows, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.5.0_04-b05, user.name=Sven, shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar, tomcat.util.buf.StringCache.byte.enabled=true, connection.driver_class=com.mysql.jdbc.Driver, user.language=de, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=C:\Programme\Java\jdk1.5.0_04\jre\bin, dialect=org.hibernate.dialect.MySQLDialect, sun.io.useCanonCaches=false, java.version=1.5.0_04, user.timezone=Europe/Berlin, sun.arch.data.model=32, java.endorsed.dirs=C:\Programme\Apache Software Foundation\Tomcat 5.5/common/endorsed, sun.cpu.isalist=, sun.jnu.encoding=Cp1252, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., file.separator=\, java.specification.name=Java Platform API Specification, hibernate.cglib.use_reflection_optimizer=true, java.class.version=49.0, user.country=DE, connection.url=jdbc:mysql://localhost/userdaten, java.home=C:\Programme\Java\jdk1.5.0_04\jre, java.vm.info=mixed mode, os.version=5.1, path.separator=;, connection.password=passwort, java.vm.version=1.5.0_04-b05, hibernate.connection.password=passwort, user.variant=, java.awt.printerjob=sun.awt.windows.WPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.windows.WToolkit, hibernate.connection.username=borkert, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=C:\Dokumente und Einstellungen\Sven, java.specification.vendor=Sun Microsystems Inc., java.library.path=C:\Programme\Java\jdk1.5.0_04\bin;C:\Programme\Apache Software Foundation\Tomcat 5.5\bin, java.vendor.url=http://java.sun.com/, hibernate.connection.driver_class=com.mysql.jdbc.Driver, connection.username=borkert, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=org.hibernate.dialect.MySQLDialect, common.loader=${catalina.home}/common/classes,${catalina.home}/common/i18n/*.jar,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=C:\Programme\Apache Software Foundation\Tomcat 5.5/bin/bootstrap.jar;C:\Programme\Java\jdk1.5.0_04/lib/tools.jar, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=C:\Programme\Apache Software Foundation\Tomcat 5.5, sun.cpu.endian=little, sun.os.patch.level=Service Pack 2, java.io.tmpdir=C:\Programme\Apache Software Foundation\Tomcat 5.5\temp, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, server.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar, os.arch=x86, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, myeclipse.connection.profile=mylocal, java.ext.dirs=C:\Programme\Java\jdk1.5.0_04\jre\lib\ext, user.dir=C:\Programme\Apache Software Foundation\Tomcat 5.5\bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, hibernate.myeclipse.connection.profile=mylocal, file.encoding=Cp1252, java.specification.version=1.5, hibernate.show_sql=true}
18:13:48,100 DEBUG Configuration:998 - Preparing to build session factory with filters : {}
18:13:48,100 INFO Configuration:875 - processing extends queue
18:13:48,100 INFO Configuration:879 - processing collection mappings
18:13:48,100 INFO Configuration:888 - processing association property references
18:13:48,100 INFO Configuration:917 - processing foreign key constraints
18:13:48,318 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for production use!)
18:13:48,318 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
18:13:48,318 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
18:13:48,334 INFO DriverManagerConnectionProvider:80 - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/userdaten
18:13:48,334 INFO DriverManagerConnectionProvider:83 - connection properties: {user=borkert, password=passwort}
18:13:48,334 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
18:13:48,334 DEBUG DriverManagerConnectionProvider:109 - opening new JDBC connection
18:13:48,740 DEBUG DriverManagerConnectionProvider:115 - created connection to: jdbc:mysql://localhost/userdaten, Isolation Level: 4
18:13:48,740 INFO SettingsFactory:77 - RDBMS: MySQL, version: 5.0.15-nt
18:13:48,740 INFO SettingsFactory:78 - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-3.1.11 ( $Date: 2005-09-21 18:20:03 +0000 (Wed, 21 Sep 2005) $, $Revision: 4287 $ )
18:13:48,740 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
18:13:48,834 INFO Dialect:92 - Using dialect: org.hibernate.dialect.MySQLDialect
18:13:48,850 INFO TransactionFactoryFactory:31 - Using default transaction strategy (direct JDBC transactions)
18:13:48,865 INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
18:13:48,865 INFO SettingsFactory:125 - Automatic flush during beforeCompletion(): disabled
18:13:48,865 INFO SettingsFactory:129 - Automatic session close at end of transaction: disabled
18:13:48,865 INFO SettingsFactory:136 - JDBC batch size: 15
18:13:48,865 INFO SettingsFactory:139 - JDBC batch updates for versioned data: disabled
18:13:48,881 INFO SettingsFactory:144 - Scrollable result sets: enabled
18:13:48,881 DEBUG SettingsFactory:148 - Wrap result sets: disabled
18:13:48,881 INFO SettingsFactory:152 - JDBC3 getGeneratedKeys(): enabled
18:13:48,881 INFO SettingsFactory:160 - Connection release mode: null
18:13:48,881 INFO SettingsFactory:184 - Maximum outer join fetch depth: 2
18:13:48,881 INFO SettingsFactory:187 - Default batch fetch size: 1
18:13:48,881 INFO SettingsFactory:191 - Generate SQL with comments: disabled
18:13:48,896 INFO SettingsFactory:195 - Order SQL updates by primary key: disabled
18:13:48,896 INFO SettingsFactory:334 - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
18:13:48,912 INFO ASTQueryTranslatorFactory:21 - Using ASTQueryTranslatorFactory
18:13:48,912 INFO SettingsFactory:203 - Query language substitutions: {}
18:13:48,912 INFO SettingsFactory:209 - Second-level cache: enabled
18:13:48,912 INFO SettingsFactory:213 - Query cache: disabled
18:13:48,912 INFO SettingsFactory:321 - Cache provider: org.hibernate.cache.EhCacheProvider
18:13:48,943 INFO SettingsFactory:228 - Optimize cache for minimal puts: disabled
18:13:48,943 INFO SettingsFactory:237 - Structured second-level cache entries: disabled
18:13:48,943 DEBUG SQLExceptionConverterFactory:52 - Using dialect defined converter
18:13:49,006 INFO SettingsFactory:257 - Echoing all SQL to stdout
18:13:49,006 INFO SettingsFactory:261 - Statistics: disabled
18:13:49,006 INFO SettingsFactory:265 - Deleted entity synthetic identifier rollback: disabled
18:13:49,021 INFO SettingsFactory:279 - Default entity-mode: pojo
18:13:49,318 INFO SessionFactoryImpl:152 - building session factory
18:13:49,318 DEBUG SessionFactoryImpl:161 - Session factory constructed with filter configurations : {}
18:13:49,318 DEBUG SessionFactoryImpl:164 - instantiating session factory with properties: {show_sql=true, java.vendor=Sun Microsystems Inc., catalina.base=C:\Programme\Apache Software Foundation\Tomcat 5.5, hibernate.connection.url=jdbc:mysql://localhost/userdaten, sun.management.compiler=HotSpot Client Compiler, catalina.useNaming=true, os.name=Windows XP, sun.boot.class.path=C:\Programme\Java\jdk1.5.0_04\jre\lib\rt.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\i18n.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\sunrsasign.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\jsse.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\jce.jar;C:\Programme\Java\jdk1.5.0_04\jre\lib\charsets.jar;C:\Programme\Java\jdk1.5.0_04\jre\classes, sun.desktop=windows, java.vm.specification.vendor=Sun Microsystems Inc., java.runtime.version=1.5.0_04-b05, user.name=Sven, shared.loader=${catalina.base}/shared/classes,${catalina.base}/shared/lib/*.jar, tomcat.util.buf.StringCache.byte.enabled=true, connection.driver_class=com.mysql.jdbc.Driver, user.language=de, java.naming.factory.initial=org.apache.naming.java.javaURLContextFactory, sun.boot.library.path=C:\Programme\Java\jdk1.5.0_04\jre\bin, dialect=org.hibernate.dialect.MySQLDialect, sun.io.useCanonCaches=false, java.version=1.5.0_04, user.timezone=Europe/Berlin, sun.arch.data.model=32, java.endorsed.dirs=C:\Programme\Apache Software Foundation\Tomcat 5.5/common/endorsed, sun.cpu.isalist=, sun.jnu.encoding=Cp1252, file.encoding.pkg=sun.io, package.access=sun.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper.,sun.beans., file.separator=\, java.specification.name=Java Platform API Specification, hibernate.cglib.use_reflection_optimizer=true, java.class.version=49.0, user.country=DE, connection.url=jdbc:mysql://localhost/userdaten, java.home=C:\Programme\Java\jdk1.5.0_04\jre, java.vm.info=mixed mode, os.version=5.1, path.separator=;, connection.password=passwort, java.vm.version=1.5.0_04-b05, hibernate.connection.password=passwort, user.variant=, java.awt.printerjob=sun.awt.windows.WPrinterJob, sun.io.unicode.encoding=UnicodeLittle, awt.toolkit=sun.awt.windows.WToolkit, hibernate.connection.username=borkert, package.definition=sun.,java.,org.apache.catalina.,org.apache.coyote.,org.apache.tomcat.,org.apache.jasper., java.naming.factory.url.pkgs=org.apache.naming, user.home=C:\Dokumente und Einstellungen\Sven, java.specification.vendor=Sun Microsystems Inc., java.library.path=C:\Programme\Java\jdk1.5.0_04\bin;C:\Programme\Apache Software Foundation\Tomcat 5.5\bin, java.vendor.url=http://java.sun.com/, hibernate.connection.driver_class=com.mysql.jdbc.Driver, connection.username=borkert, java.vm.vendor=Sun Microsystems Inc., hibernate.dialect=org.hibernate.dialect.MySQLDialect, common.loader=${catalina.home}/common/classes,${catalina.home}/common/i18n/*.jar,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, java.class.path=C:\Programme\Apache Software Foundation\Tomcat 5.5/bin/bootstrap.jar;C:\Programme\Java\jdk1.5.0_04/lib/tools.jar, java.vm.specification.name=Java Virtual Machine Specification, java.vm.specification.version=1.0, catalina.home=C:\Programme\Apache Software Foundation\Tomcat 5.5, sun.cpu.endian=little, sun.os.patch.level=Service Pack 2, java.io.tmpdir=C:\Programme\Apache Software Foundation\Tomcat 5.5\temp, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, server.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar, os.arch=x86, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, myeclipse.connection.profile=mylocal, java.ext.dirs=C:\Programme\Java\jdk1.5.0_04\jre\lib\ext, user.dir=C:\Programme\Apache Software Foundation\Tomcat 5.5\bin, line.separator=
, java.vm.name=Java HotSpot(TM) Client VM, hibernate.myeclipse.connection.profile=mylocal, file.encoding=Cp1252, java.specification.version=1.5, hibernate.show_sql=true}
18:13:49,365 WARN Configurator:126 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Programme/Apache%20Software%20Foundation/Tomcat%205.5/webapps/Userdaten/WEB-INF/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
18:13:50,334 DEBUG BasicEntityPersister:2220 - Static SQL for entity: com.borkert.Hibernate.Users
18:13:50,334 DEBUG BasicEntityPersister:2222 - Version select: select id from users where id =?
18:13:50,334 DEBUG BasicEntityPersister:2223 - Snapshot select: select users_.id, users_.username as username0_, users_.password as password0_ from users users_ where users_.id=?
18:13:50,350 DEBUG BasicEntityPersister:2225 - Insert 0: insert into users (username, password, id) values (?, ?, ?)
18:13:50,350 DEBUG BasicEntityPersister:2226 - Update 0: update users set username=?, password=? where id=?
18:13:50,350 DEBUG BasicEntityPersister:2227 - Delete 0: delete from users where id=?
18:13:50,365 DEBUG BasicEntityPersister:2230 - Identity insert: insert into users (username, password) values (?, ?)
18:13:50,412 DEBUG EntityLoader:95 - Static select for entity com.borkert.Hibernate.Users: select users0_.id as id0_, users0_.username as username0_0_, users0_.password as password0_0_ from users users0_ where users0_.id=?
18:13:50,412 DEBUG EntityLoader:95 - Static select for entity com.borkert.Hibernate.Users: select users0_.id as id0_, users0_.username as username0_0_, users0_.password as password0_0_ from users users0_ where users0_.id=?
18:13:50,412 DEBUG EntityLoader:95 - Static select for entity com.borkert.Hibernate.Users: select users0_.id as id0_, users0_.username as username0_0_, users0_.password as password0_0_ from users users0_ where users0_.id=? for update
18:13:50,428 DEBUG EntityLoader:95 - Static select for entity com.borkert.Hibernate.Users: select users0_.id as id0_, users0_.username as username0_0_, users0_.password as password0_0_ from users users0_ where users0_.id=? for update
18:13:50,428 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
18:13:50,443 DEBUG SessionFactoryObjectFactory:76 - registered: 40288020074cd1fc01074cd2025c0000 (unnamed)
18:13:50,443 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
18:13:50,443 DEBUG SessionFactoryImpl:262 - instantiated session factory
18:13:50,443 INFO SessionFactoryImpl:379 - Checking 0 named queries
18:13:50,537 DEBUG SessionImpl:250 - opened session at timestamp: 4632023983894528
18:13:50,553 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
18:13:50,553 DEBUG AbstractSaveEventListener:133 - saving [com.borkert.Hibernate.Users#<null>]
18:13:50,553 DEBUG AbstractSaveEventListener:195 - executing insertions
18:13:50,600 DEBUG BasicEntityPersister:1732 - Inserting entity: com.borkert.Hibernate.Users (native id)
18:13:50,600 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
18:13:50,600 DEBUG ConnectionManager:296 - opening JDBC connection
18:13:50,631 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
18:13:50,631 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
18:13:50,631 DEBUG SQL:324 - insert into users (username, password) values (?, ?)
Hibernate: insert into users (username, password) values (?, ?)
18:13:50,631 DEBUG AbstractBatcher:378 - preparing statement
18:13:50,662 DEBUG BasicEntityPersister:1612 - Dehydrating entity: [com.borkert.Hibernate.Users#<null>]
18:13:50,662 DEBUG StringType:59 - binding 'Borkert' to parameter: 1
18:13:50,662 DEBUG StringType:59 - binding 'passwort1234' to parameter: 2
18:13:50,709 DEBUG IdentifierGeneratorFactory:37 - Natively generated identity: 11
18:13:50,709 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
18:13:50,709 DEBUG AbstractBatcher:416 - closing statement
18:13:50,725 DEBUG AbstractFlushingEventListener:52 - flushing session
18:13:50,740 DEBUG AbstractFlushingEventListener:102 - processing flush-time cascades
18:13:50,740 DEBUG AbstractFlushingEventListener:150 - dirty checking collections
18:13:50,740 DEBUG AbstractFlushingEventListener:167 - Flushing entities and processing referenced collections
18:13:50,740 DEBUG AbstractFlushingEventListener:203 - Processing unreferenced collections
18:13:50,740 DEBUG AbstractFlushingEventListener:217 - Scheduling collection removes/(re)creates/updates
18:13:50,740 DEBUG AbstractFlushingEventListener:79 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
18:13:50,756 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
18:13:50,756 DEBUG Printer:83 - listing entities:
18:13:50,756 DEBUG Printer:90 - com.borkert.Hibernate.Users{password=passwort1234, username=Borkert, id=11}
18:13:50,756 DEBUG AbstractFlushingEventListener:267 - executing flush
18:13:50,756 DEBUG AbstractFlushingEventListener:294 - post flush
18:13:50,756 DEBUG SessionImpl:269 - closing session
18:13:50,756 DEBUG ConnectionManager:317 - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
18:13:50,771 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
18:13:50,771 DEBUG JDBCContext:283 - after transaction completion
18:13:50,771 DEBUG SessionImpl:403 - after transaction completion






18:15:35,896 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
18:15:35,896 DEBUG AbstractSaveEventListener:133 - saving [com.borkert.Hibernate.Users#<null>]
18:15:35,896 DEBUG AbstractSaveEventListener:195 - executing insertions
18:15:35,896 DEBUG BasicEntityPersister:1732 - Inserting entity: com.borkert.Hibernate.Users (native id)
18:15:35,896 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
Hibernate ExceptionNot able to obtain connection
18:15:35,912 DEBUG SessionImpl:269 - closing session
18:15:35,928 WARN RequestProcessor:538 - Unhandled Exception thrown: class java.lang.RuntimeException
18:15:35,943 ERROR [action]:253 - Servlet.service() for servlet action threw exception
java.lang.RuntimeException: org.hibernate.HibernateException: Not able to obtain connection
at com.borkert.Hibernate.UserService.addUserdata(UserService.java:260)
at com.borkert.struts.action.AdduserAction.execute(AdduserAction.java:51)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
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.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: org.hibernate.HibernateException: Not able to obtain connection
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:113)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:76)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1739)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2178)
at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:34)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:240)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:95)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
at com.borkert.Hibernate.UserService.addUserdata(UserService.java:254)
... 21 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:41 am 
Regular
Regular

Joined: Mon Oct 06, 2003 7:17 am
Posts: 58
Location: Switzerland
Du musst noch eine Transaktion öffnen (session.beginTransaction()) und nach dem flush eine Transaktion committen (session.commitTransaction).

Reto


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:15 am 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Danke, das hat schonmal teilweise geholfen.

Ich habs jetzt so modifiziert:

Code:
      try
      {
         session = SessionFactory.currentSession();
         Transaction tx = session.beginTransaction();
         
         session.save(data);
         session.flush();
         
         tx.commit();
      }


Leider krig ich damit aber nur 1 oder 2 Datensätze in die Datenbank, danach krige ich folgende Exception. Irgendwie erzeugt er wohl keine neue Session.

Code:
exception

javax.servlet.ServletException: org.hibernate.SessionException: Session is closed
   org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:545)
   org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:486)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.RuntimeException: org.hibernate.SessionException: Session is closed
   com.knorz.Hibernate.UsersService.addUser(UsersService.java:75)
   com.knorz.struts.action.LoginAction.execute(LoginAction.java:51)
   org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)
   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)
   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Ist vielleicht die SessionFactory nicht ok? Ich hab einfach mal auf gut Glück von MyEclipse eine erzeugen lassen:

Code:
public class SessionFactory {



    /**

     * Location of hibernate.cfg.xml file.

     * NOTICE: Location should be on the classpath as Hibernate uses

     * #resourceAsStream style lookup for its configuration file. That

     * is place the config file in a Java package - the default location

     * is the default Java package.<br><br>

     * Examples: <br>

     * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".

     * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>

     */

    private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";



    /** Holds a single instance of Session */

    private static final ThreadLocal threadLocal = new ThreadLocal();



    /** The single instance of hibernate configuration */

    private static final Configuration cfg = new Configuration();



    /** The single instance of hibernate SessionFactory */

    private static org.hibernate.SessionFactory sessionFactory;



    /**

     * Returns the ThreadLocal Session instance.  Lazy initialize

     * the <code>SessionFactory</code> if needed.

     *

     *  @return Session

     *  @throws HibernateException

     */

    public static Session currentSession() throws HibernateException {

        Session session = (Session) threadLocal.get();



        if (session == null) {

            if (sessionFactory == null) {

                try {

                    cfg.configure(CONFIG_FILE_LOCATION);

                    sessionFactory = cfg.buildSessionFactory();

                }

                catch (Exception e) {

                    System.err.println("%%%% Error Creating SessionFactory %%%%");

                    e.printStackTrace();

                }

            }

            session = sessionFactory.openSession();

            threadLocal.set(session);

        }

       

        return session;

    }



    /**

     *  Close the single hibernate session instance.

     *

     *  @throws HibernateException

     */

    public static void closeSession() throws HibernateException {

        Session session = (Session) threadLocal.get();

        threadLocal.set(null);



        if (session != null) {

            session.close();

        }

    }



    /**

     * Default constructor.

     */

    private SessionFactory() {

    }



}



Für mich sieht es aber so aus als würde er da eine neue Session erzeugen wenn die alte Weg ist. Verstehe den Fehler also leider überhaupt nicht.

Grüsse,

Sven Borkert


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 9:32 am 
Newbie

Joined: Tue Nov 01, 2005 12:38 pm
Posts: 12
Das Problem hat sich gerade erledigt, zu dem Fehler gibts was im MyEclipse Forum.

http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-4305.html

session.close() hinterlässt eine geschlossene Session die noch nicht = null ist. Die SessionFactory die MyEclipse erzeugt erzeugt aber nur eine neue Session wenn session == null ist.

Trotzdem vielen Dank nochmal.

Grüsse,

Sven Borkert


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.