《JdonFramework 5.1发布》中案例错误的改正

文章《JdonFramework 5.1发布》中案例 http://www.jdon.com/jdonframework/download/samples_hibernate.zip
有错误,错误是这个案例中的 /WEB-INF/web.xml 有些错误的代码:


<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>sample.MyServlet</servlet-class>
</servlet>


<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/mys</url-pattern>
</servlet-mapping>

这里提供的 servlet 在案例中并不存在,我想可能是测试时的代码。删除后案例可以运行。但配置的log仍然会出错。
[该贴被lqixv于2008-02-29 10:00修改过]

可以运行了,但却无法插入数据。错误如下:


14:00:09,453 INFO [STDOUT] 14:00:09,453 INFO [ContainerDirector] <======== Jdon Framework started successfully! =========>
14:00:09,656 INFO [Version] Hibernate Annotations 3.2.1.GA
14:00:09,734 INFO [Environment] Hibernate 3.2.5
14:00:09,765 INFO [Environment] hibernate.properties not found
14:00:09,781 INFO [Environment] Bytecode provider name : javassist
14:00:09,796 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
14:00:10,265 INFO [Configuration] configuring from resource: /hibernate.cfg.xml
14:00:10,265 INFO [Configuration] Configuration resource: /hibernate.cfg.xml
14:00:10,546 INFO [Configuration] Reading mappings from resource : sample/model/User.hbm.xml
14:00:10,656 INFO [Configuration] Reading mappings from resource : sample/model/Dept.hbm.xml
14:00:10,671 INFO [Configuration] Reading mappings from resource : sample/model/Address.hbm.xml
14:00:10,718 INFO [Configuration] Reading mappings from resource : sample/model/Property.hbm.xml
14:00:10,718 INFO [Configuration] Configured SessionFactory: null
14:00:11,078 INFO [HbmBinder] Mapping class: sample.model.User -> nec_userb
14:00:11,562 INFO [HbmBinder] Mapping class: sample.model.Dept -> nec_dept
14:00:11,578 INFO [HbmBinder] Mapping class: sample.model.Address -> nec_address
14:00:11,593 INFO [HbmBinder] Mapping class: sample.model.Property -> nec_property
14:00:11,625 INFO [HbmBinder] Mapping collection: sample.model.User.properties -> nec_property
14:00:13,093 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
14:00:13,093 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
14:00:13,093 INFO [DriverManagerConnectionProvider] autocommit mode: false
14:00:13,109 INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/test
14:00:13,109 INFO [DriverManagerConnectionProvider] connection properties: {user=test, password=test}
14:00:14,078 INFO [SettingsFactory] RDBMS: MySQL, version: 5.1.20-beta-community-nt-debug
14:00:14,078 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.7 ( $Date: 2007-03-09 22:13:57 +0100 (Fri, 09 Mar 2007) $, $Revision: 6341 $ )
14:00:14,171 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
14:00:14,218 INFO [TransactionFactoryFactory] Using default transaction strategy (direct JDBC transactions)
14:00:14,234 INFO [TransactionManagerLookupFactory] No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
14:00:14,234 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
14:00:14,234 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
14:00:14,234 INFO [SettingsFactory] JDBC batch size: 15



14:00:14,234 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
14:00:14,234 INFO [SettingsFactory] Scrollable result sets: enabled
14:00:14,234 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
14:00:14,234 INFO [SettingsFactory] Connection release mode: auto
14:00:14,250 INFO [SettingsFactory] Maximum outer join fetch depth: 2
14:00:14,250 INFO [SettingsFactory] Default batch fetch size: 1
14:00:14,250 INFO [SettingsFactory] Generate SQL with comments: disabled
14:00:14,250 INFO [SettingsFactory] Order SQL updates by primary key: disabled
14:00:14,250 INFO [SettingsFactory] Order SQL inserts for batching: disabled
14:00:14,250 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
14:00:14,265 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
14:00:14,265 INFO [SettingsFactory] Query language substitutions: {}
14:00:14,265 INFO [SettingsFactory] JPA-QL strict compliance: disabled
14:00:14,265 INFO [SettingsFactory] Second-level cache: enabled
14:00:14,265 INFO [SettingsFactory] Query cache: enabled
14:00:14,265 INFO [SettingsFactory] Cache provider: org.hibernate.cache.EhCacheProvider
14:00:14,281 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
14:00:14,281 INFO [SettingsFactory] Structured second-level cache entries: disabled
14:00:14,281 INFO [SettingsFactory] Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
14:00:14,328 INFO [SettingsFactory] Echoing all SQL to stdout
14:00:14,328 INFO [SettingsFactory] Statistics: disabled
14:00:14,328 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
14:00:14,328 INFO [SettingsFactory] Default entity-mode: pojo
14:00:14,328 INFO [SettingsFactory] Named query checking : enabled
14:00:14,484 INFO [SessionFactoryImpl] building session factory
14:00:14,546 WARN [ConfigurationFactory] No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/jboss-4.0.4.GA/server/default/tmp/deploy/tmp62334msweb-exp.war/WEB-INF/lib/ehcache-1.2.3.jar!/ehcache-failsafe.xml
14:00:16,265 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
14:00:16,281 INFO [SchemaUpdate] Running hbm2ddl schema update
14:00:16,281 INFO [SchemaUpdate] fetching database metadata
14:00:16,296 INFO [SchemaUpdate] updating schema
14:00:16,421 INFO [TableMetadata] table found: test.nec_address
14:00:16,421 INFO [TableMetadata] columns: [name, id]
14:00:16,421 INFO [TableMetadata] foreign keys: []
14:00:16,421 INFO [TableMetadata] indexes: [primary]
14:00:16,468 INFO [TableMetadata] table found: test.nec_dept
14:00:16,468 INFO [TableMetadata] columns: [name, id]
14:00:16,468 INFO [TableMetadata] foreign keys: []
14:00:16,468 INFO [TableMetadata] indexes: [primary]
14:00:16,531 INFO [TableMetadata] table found: test.nec_property
14:00:16,531 INFO [TableMetadata] columns: [userid, value, name, id]
14:00:16,531 INFO [TableMetadata] foreign keys: [fk4f2963287a60bc7a]
14:00:16,531 INFO [TableMetadata] indexes: [fk4f2963287a60bc7a, primary]
14:00:16,593 INFO [TableMetadata] table found: test.nec_userb
14:00:16,593 INFO [TableMetadata] columns: [deptid, name, id, addressid]
14:00:16,593 INFO [TableMetadata] foreign keys: [fkcf0a4184230b00da, fkcf0a41845c962aee]
14:00:16,593 INFO [TableMetadata] indexes: [fkcf0a4184230b00da, primary, fkcf0a41845c962aee, addressid]
14:00:16,593 INFO [SchemaUpdate] schema update complete


14:00:16,625 INFO [UpdateTimestampsCache] starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
14:00:16,625 WARN [EhCacheProvider] Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
14:00:16,687 INFO [StandardQueryCache] starting query cache at region: org.hibernate.cache.StandardQueryCache
14:00:16,687 WARN [EhCacheProvider] Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
14:00:18,484 INFO [STDOUT] Hibernate: select count(user0_.id) as col_0_0_ from nec_userb user0_
14:00:18,625 INFO [STDOUT] Hibernate: select user0_.id as col_0_0_ from nec_userb user0_ order by user0_.id limit ?
14:01:08,109 INFO [STDOUT] Hibernate: select dept0_.id as id1_, dept0_.name as name1_ from nec_dept dept0_
14:01:33,156 INFO [STDOUT] 14:01:33,140 ERROR [HibernateTemplate] exception while execute
java.lang.IllegalArgumentException: id to load is required for loading
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:51)
at org.hibernate.event.LoadEvent.<init>(LoadEvent.java:33)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:792)
at org.hibernate.impl.SessionImpl.load(SessionImpl.java:788)
at com.jdon.persistence.hibernate.HibernateTemplate$3.execute(HibernateTemplate.java:151)
at com.jdon.persistence.hibernate.HibernateTemplate.doHibernate(HibernateTemplate.java:74)
at com.jdon.persistence.hibernate.HibernateTemplate.load(HibernateTemplate.java:145)
at com.jdon.persistence.hibernate.HibernateTemplate.load(HibernateTemplate.java:139)
at com.jdon.persistence.hibernate.HibernateCRUDTemplate.loadById(HibernateCRUDTemplate.java:98)
at com.jdon.persistence.DaoCRUDTemplate.loadModelById(DaoCRUDTemplate.java:69)
at sample.service.UserServiceImp.create(UserServiceImp.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.jdon.aop.reflection.MethodInvokerUtil.execute(MethodInvokerUtil.java:54)
at com.jdon.aop.reflection.ProxyMethodInvocation.methodInvoke(ProxyMethodInvocation.java:108)
at com.jdon.aop.reflection.ProxyMethodInvocation.proceed(ProxyMethodInvocation.java:76)
at com.jdon.aop.interceptor.SessionContextInterceptor.invoke(SessionContextInterceptor.java:76)
at com.jdon.aop.reflection.ProxyMethodInvocation.proceed(ProxyMethodInvocation.java:84)
at com.jdon.aop.interceptor.StatefulInterceptor.invoke(StatefulInterceptor.java:82)
at com.jdon.aop.reflection.ProxyMethodInvocation.proceed(ProxyMethodInvocation.java:84)
at com.jdon.aop.interceptor.PoolInterceptor.invoke(PoolInterceptor.java:91)
at com.jdon.aop.reflection.ProxyMethodInvocation.proceed(ProxyMethodInvocation.java:84)
at com.jdon.aop.interceptor.CacheInterceptor.invoke(CacheInterceptor.java:58)
at com.jdon.aop.reflection.ProxyMethodInvocation.proceed(ProxyMethodInvocation.java:84)
at com.jdon.aop.AopClient.invoke(AopClient.java:73)
at com.jdon.container.access.ServiceAccessorImp.executeService(ServiceAccessorImp.java:50)
at com.jdon.controller.service.WebServiceDecorator.execute(WebServiceDecorator.java:87)
at com.jdon.controller.service.WebServiceImp.execute(WebServiceImp.java:73)
at com.jdon.controller.service.WebServiceImp.execute(WebServiceImp.java:58)
at com.jdon.model.handler.XmlModelHandler.serviceAction(XmlModelHandler.java:132)
at com.jdon.strutsutil.ModelSaveAction.execute(ModelSaveAction.java:88)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:226)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.jdon.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:92)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at com.jdon.persistence.hibernate.CloseSessionInViewFilter.doFilter(CloseSessionInViewFilter.java:43)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
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.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
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:869)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)
14:01:33,156 INFO [STDOUT] 14:01:33,156 ERROR [UserServiceImp] java.lang.Exception: java.lang.IllegalArgumentException: id to load is required for loading
14:01:37,031 INFO [STDOUT] Hibernate: select user0_.id as col_0_0_ from nec_userb user0_ order by user0_.id limit ?

各位,帮个忙,这是怎么回事?
我尝试运行这个包中的 junit 测试案例 HibernateTemplateTest,也出错,错误如下:


...
2008-02-29 14:12:07,500 [main] DEBUG org.hibernate.SQL - insert into nec_dept (name, id) values (?, ?)
Hibernate: insert into nec_dept (name, id) values (?, ?)
2008-02-29 14:12:07,500 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Dehydrating entity: [sample.model.Dept#402881d31863d198011863d19fc30002]
2008-02-29 14:12:07,500 [main] DEBUG org.hibernate.type.StringType - binding 'deptb' to parameter: 1
2008-02-29 14:12:07,500 [main] DEBUG org.hibernate.type.StringType - binding '402881d31863d198011863d19fc30002' to parameter: 2
2008-02-29 14:12:07,500 [main] DEBUG org.hibernate.cache.UpdateTimestampsCache - Pre-invalidating space [nec_address]
2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.persister.entity.AbstractEntityPersister - Inserting entity: [sample.model.Address#402881d31863d198011863d19fc30003]
2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - Executing batch size: 2
2008-02-29 14:12:07,515 [main] ERROR org.hibernate.jdbc.AbstractBatcher - Exception executing batch:



org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 7810893; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.jdon.persistence.hibernate.util.ThreadLocalSessionProvider.closeSession(ThreadLocalSessionProvider.java:103)
at sample.dao.HibernateTemplateTest.testGetUserforNoLazy(HibernateTemplateTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2008-02-29 14:12:07,515 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.jdbc.BatchedTooManyRowsAffectedException: Batch update returned unexpected row count from update [0]; actual row count: 7810893; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:71)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:46)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:68)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:222)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2224)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.jdon.persistence.hibernate.util.ThreadLocalSessionProvider.closeSession(ThreadLocalSessionProvider.java:103)
at sample.dao.HibernateTemplateTest.testGetUserforNoLazy(HibernateTemplateTest.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.jdbc.ConnectionManager - registering flush end
2008-02-29 14:12:07,515 [main] DEBUG org.hibernate.impl.SessionImpl - closing session



...
2008-02-29 14:12:08,578 [main] DEBUG org.hibernate.SQL - select user0_.id as id24_0_, user0_.name as name24_0_, user0_.deptid as deptid24_0_, user0_.addressid as addressid24_0_ from nec_userb user0_ where user0_.id=?
Hibernate: select user0_.id as id24_0_, user0_.name as name24_0_, user0_.deptid as deptid24_0_, user0_.addressid as addressid24_0_ from nec_userb user0_ where user0_.id=?
2008-02-29 14:12:08,578 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - preparing statement
2008-02-29 14:12:08,578 [main] DEBUG org.hibernate.type.IntegerType - binding '1' to parameter: 1
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to open ResultSet (open ResultSets: 0, globally: 0)
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.loader.Loader - processing result set
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.loader.Loader - done processing result set (0 rows)
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close ResultSet (open ResultSets: 1, globally: 1)
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.jdbc.AbstractBatcher - closing statement
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.loader.Loader - total objects hydrated: 0
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.engine.StatefulPersistenceContext - initializing non-lazy collections
2008-02-29 14:12:08,593 [main] DEBUG org.hibernate.loader.Loader - done entity load
org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [sample.model.User#1]
at org.hibernate.impl.SessionFactoryImpl$1.handleEntityNotFound(SessionFactoryImpl.java:377)
at org.hibernate.proxy.AbstractLazyInitializer.checkTargetState(AbstractLazyInitializer.java:79)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:68)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
at sample.model.User$$EnhancerByCGLIB$$18835a29.getProperties(<generated>)
at sample.dao.HibernateTemplateTest.testUpdate(HibernateTemplateTest.java:132)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

步骤是对的,具体错误,可检查数据库连接参数等是否正确。

检查数据库连接参数等是没有问题的,因为数据库里的表都是程序运行时生成的。
但我为了保险,我又单独用授权语句把这个数据库的权限全部赋给了这个用户,但错误还是一样。
我用 mysql 客户端使用这个用户名、密码登录到数据库中,所有操作都没有问题。只是里面没有任何数据。
我看了一下 hibernate.cfg.xml 里面的主键生成方式,发现是“increment”,我把生成方式改为“native”后重新测试了所有程序,错误还是一样。

清除原来的数据表,清0重新开始试验一下,或者使用网站上推荐下载JBoss/Tomcat包,因为Java是组件世界,过段时间有个组件更新一下,有可能影响整体效果。

好的,谢谢 banq !
我现在发现我的 hibernate 版本是 3.1 的版本,不知是否与这个有关。先测试下。
我在运行测试案例的时候发现是读不到记录。我估计是因为写的时候没有写进去。我先把 hibernate 更新到 3.2 再试一下。

log4j 问题改正办法:

删除jboss deploy下面相应的war的WEB-INF/lib中log4j*.jar和common-logging.jar就可以了

运行junit类HibernateTemplateTest时,当执行到方法public void testGetUser()时,junit测试通不过,错误是:org.hibernate.TypeMismatchException: Provided id of the wrong type. Expected: class java.lang.Integer, got class java.lang.String
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:86)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:878)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:808)
at sample.dao.HibernateTemplateTest.testGetUser(HibernateTemplateTest.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

错误对应方法中的语句是:User user = (User)session.get(User.class, "402881e614ed5dbd0114ed5dbf660004");
当我把语句改为:
User user = (User)session.get(User.class, 1);
后,junit测试顺利通过。
banq,这条语句中后面引号里面的字符串是怎么来的?