打印

[Java] hibernate3+ejb3SessionBean 报异常 [Hibernate]

hibernate3+ejb3SessionBean 报异常 [Hibernate]

程序如下:
public   class   HibernateBase   {
private   static   SessionFactory   sf   =   null;
public   Session   session   =   null;
public   void   Begin(){
//在这里可以根据配置文件来使用,如果是使用JDBC-》openSession(),如果使用JTA使用getCurrentSession();
if(sf==null)   Init();
session   =   sf.openSession();
}
public   void     Init(){
try{
InitialContext   ctx   =   new   InitialContext();
Object   obj   =   ctx.lookup( "hibernateJNDI ");
System.out.println( "hibernateJNDI=============== "+obj);
if(sf==null)   sf   =   (SessionFactory)obj;
}catch(Exception   e){
e.printStackTrace();
}
}
public   void   Close(){
if(session!=null&&session.isOpen())   session.close();
}
}
public   class   ArticleEJB   extends   HibernateBase   implements   InfoArticleUtil,   ArticleEJBLocal,
ArticleEJBRemote   {

public   List   getAllArticle()   {
List   list   =   null;
try{
Begin();
list   =   session.createQuery( "from   InfoArticle ").list();
if(list==null)   list   =   new   ArrayList();
session.flush();
}catch(Exception   e){
e.printStackTrace();
}finally{
Close();
}
return   null;
}

}
public   class   HibernateUtil   {
public   static   SessionFactory   sf   =   null;
public   void   Init(){
if(sf   ==   null){
  sf   =   new   Configuration().configure().buildSessionFactory();
}
}

}public   class   StartUpListener   implements   ServletContextListener{

public   void   contextDestroyed(ServletContextEvent   arg0)   {

}
public   void   contextInitialized(ServletContextEvent   arg0)   {
try   {
InitialContext   ctx   =   new   InitialContext();
HibernateUtil   h   =   new   HibernateUtil();
h.Init();
SessionFactory   newsf   =   h.sf;
SessionFactory   oldsf   =   (SessionFactory)ctx.lookup( "hibernateJNDI ");
System.out.println( "bind   hibernateJNDI~~~~~~~~~~~~~~~~~~~~~~~` ");
if(oldsf!=null)   ctx.rebind( "hibernateJNDI ",   newsf);
else   ctx.bind( "hibernateJNDI ",   newsf);

}   catch   (NamingException   e)   {
e.printStackTrace();
}
}
} <?xml   version= "1.0 "   encoding= "UTF-8 "?>
<web-app   version= "2.5 "   
xmlns= "http://java.sun.com/xml/ns/javaee "   
xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "   
xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee   
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">

<listener>
<listener-class> sysListener.StartUpListener </listener-class>
</listener>
</web-app>

TOP

异常如下:22:21:46,485 INFO  [STDOUT] 22:21:46,485 INFO  [Environment] Hibernate 3.1.3
22:21:46,515 INFO  [STDOUT] 22:21:46,515 INFO  [Environment] hibernate.properties not found
22:21:46,525 INFO  [STDOUT] 22:21:46,525 INFO  [Environment] using CGLIB reflection optimizer
22:21:46,525 INFO  [STDOUT] 22:21:46,525 INFO  [Environment] using JDK 1.4 java.sql.Timestamp handling
22:21:46,755 INFO  [STDOUT] 22:21:46,755 INFO  [Configuration] configuring from resource: /hibernate.cfg.xml
22:21:46,755 INFO  [STDOUT] 22:21:46,755 INFO  [Configuration] Configuration resource: /hibernate.cfg.xml
22:21:46,966 INFO  [STDOUT] 22:21:46,966 INFO  [Configuration] Reading mappings from resource: domain/InfoArti
cle.hbm.xml
22:21:48,508 INFO  [STDOUT] 22:21:48,498 INFO  [HbmBinder] Mapping class: domain.InfoArticle -> info_article
22:21:48,578 INFO  [STDOUT] 22:21:48,578 INFO  [Configuration] Reading mappings from resource: domain/ChanArti
Relation.hbm.xml
22:21:48,918 INFO  [STDOUT] 22:21:48,918 INFO  [HbmBinder] Mapping class: domain.ChanArtiRelation -> chan_arti
_relation
22:21:50,180 INFO  [STDOUT] 22:21:50,180 INFO  [Configuration] Reading mappings from resource: domain/InfoChan
nel.hbm.xml
22:21:50,711 INFO  [STDOUT] 22:21:50,711 INFO  [HbmBinder] Mapping class: domain.InfoChannel -> info_channel
22:21:50,711 INFO  [STDOUT] 22:21:50,711 INFO  [Configuration] Configured SessionFactory: null
22:21:50,721 INFO  [STDOUT] 22:21:50,721 INFO  [HbmBinder] Mapping collection: domain.InfoArticle.chanArtiRela
tions -> chan_arti_relation
22:21:50,731 INFO  [STDOUT] 22:21:50,731 INFO  [HbmBinder] Mapping collection: domain.InfoChannel.chanArtiRela
tions -> chan_arti_relation
22:21:50,801 INFO  [STDOUT] 22:21:50,801 INFO  [NamingHelper] JNDI InitialContext properties:{}
22:21:50,801 INFO  [STDOUT] 22:21:50,801 INFO  [DatasourceConnectionProvider] Using datasource: java:/moreflur
ish
22:21:51,412 INFO  [STDOUT] 22:21:51,412 INFO  [SettingsFactory] RDBMS: MySQL, version: 5.0.15-nt
22:21:51,412 INFO  [STDOUT] 22:21:51,412 INFO  [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: m
ysql-connector-java-5.0.8 ( Revision: ${svn.Revision} )
22:21:51,532 INFO  [STDOUT] 22:21:51,492 INFO  [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
22:21:51,552 INFO  [STDOUT] 22:21:51,552 INFO  [TransactionFactoryFactory] Transaction strategy: org.hibernate
.transaction.JTATransactionFactory
22:21:51,552 INFO  [STDOUT] 22:21:51,552 INFO  [NamingHelper] JNDI InitialContext properties:{}
22:21:51,562 INFO  [STDOUT] 22:21:51,562 INFO  [TransactionManagerLookupFactory] instantiating TransactionMana
gerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
22:21:51,572 INFO  [STDOUT] 22:21:51,572 INFO  [TransactionManagerLookupFactory] instantiated TransactionManag
erLookup
22:21:51,572 INFO  [STDOUT] 22:21:51,572 INFO  [TransactionManagerLookupFactory] instantiating TransactionMana
gerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
22:21:51,572 INFO  [STDOUT] 22:21:51,572 INFO  [TransactionManagerLookupFactory] instantiated TransactionManag
erLookup
22:21:51,572 INFO  [STDOUT] 22:21:51,572 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): di
sabled
22:21:51,572 INFO  [STDOUT] 22:21:51,572 INFO  [SettingsFactory] Automatic session close at end of transaction
: disabled
22:21:51,582 INFO  [STDOUT] 22:21:51,582 INFO  [SettingsFactory] JDBC batch size: 15
22:21:51,582 INFO  [STDOUT] 22:21:51,582 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabl
ed
22:21:51,582 INFO  [STDOUT] 22:21:51,582 INFO  [SettingsFactory] Scrollable result sets: enabled
22:21:51,582 INFO  [STDOUT] 22:21:51,582 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
22:21:51,582 INFO  [STDOUT] 22:21:51,582 INFO  [SettingsFactory] Connection release mode: auto
22:21:51,592 INFO  [STDOUT] 22:21:51,592 INFO  [SettingsFactory] Maximum outer join fetch depth: 2
22:21:51,592 INFO  [STDOUT] 22:21:51,592 INFO  [SettingsFactory] Default batch fetch size: 1
22:21:51,592 INFO  [STDOUT] 22:21:51,592 INFO  [SettingsFactory] Generate SQL with comments: disabled
22:21:51,602 INFO  [STDOUT] 22:21:51,602 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
22:21:51,612 INFO  [STDOUT] 22:21:51,612 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQu
eryTranslatorFactory
22:21:51,632 INFO  [STDOUT] 22:21:51,632 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
22:21:51,632 INFO  [STDOUT] 22:21:51,632 INFO  [SettingsFactory] Query language substitutions: {}
22:21:51,632 INFO  [STDOUT] 22:21:51,632 INFO  [SettingsFactory] Second-level cache: enabled
22:21:51,632 INFO  [STDOUT] 22:21:51,632 INFO  [SettingsFactory] Query cache: disabled
22:21:51,632 INFO  [STDOUT] 22:21:51,632 INFO  [SettingsFactory] Cache provider: org.hibernate.cache.Hashtable
CacheProvider
22:21:51,642 INFO  [STDOUT] 22:21:51,642 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
22:21:51,642 INFO  [STDOUT] 22:21:51,642 INFO  [SettingsFactory] Structured second-level cache entries: disabl
ed
22:21:51,672 INFO  [STDOUT] 22:21:51,672 INFO  [SettingsFactory] Echoing all SQL to stdout
22:21:51,682 INFO  [STDOUT] 22:21:51,682 INFO  [SettingsFactory] Statistics: disabled
22:21:51,682 INFO  [STDOUT] 22:21:51,682 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback:
disabled
22:21:51,682 INFO  [STDOUT] 22:21:51,682 INFO  [SettingsFactory] Default entity-mode: pojo
22:21:51,823 INFO  [STDOUT] 22:21:51,813 INFO  [SessionFactoryImpl] building session factory
22:21:54,226 INFO  [STDOUT] 22:21:54,226 INFO  [SessionFactoryObjectFactory] Factory name: hibernateJNDI
22:21:54,226 INFO  [STDOUT] 22:21:54,226 INFO  [NamingHelper] JNDI InitialContext properties:{}
22:21:54,226 INFO  [STDOUT] 22:21:54,226 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: hiber
nateJNDI
22:21:54,226 INFO  [STDOUT] 22:21:54,226 WARN  [SessionFactoryObjectFactory] InitialContext did not implement
EventContext
22:21:54,226 INFO  [STDOUT] 22:21:54,226 INFO  [NamingHelper] JNDI InitialContext properties:{}
22:21:54,236 INFO  [STDOUT] bind hibernateJNDI~~~~~~~~~~~~~~~~~~~~~~~`
22:21:54,476 INFO  [TomcatDeployer] deploy, ctxPath=/jmx-console, warUrl=.../deploy/jmx-console.war/
22:21:55,147 INFO  [Http11Protocol] Starting Coyote HTTP/1.1 on http-127.0.0.1-8080
22:21:56,039 INFO  [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
22:21:56,129 INFO  [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)]
Started in 1m:34s:857ms
22:22:12,102 INFO  [STDOUT] hibernateJNDI===============org.hibernate.impl.SessionFactoryImpl@db598
22:22:12,102 ERROR [STDERR] java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl
22:22:12,102 ERROR [STDERR]    at hibernate.HibernateBase.Init(HibernateBase.java:21)

TOP

22:22:12,102 ERROR [STDERR] java.lang.ClassCastException: org.hibernate.impl.SessionFactoryImpl
22:22:12,102 ERROR [STDERR]    at hibernate.HibernateBase.Init(HibernateBase.java:21)
22:22:12,112 ERROR [STDERR]    at hibernate.HibernateBase.Begin(HibernateBase.java:13)
22:22:12,112 ERROR [STDERR]    at ejb3.services.Article.ArticleEJB.getAllArticle(ArticleEJB.java:18)
22:22:12,112 ERROR [STDERR]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
22:22:12,112 ERROR [STDERR]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
9)
22:22:12,112 ERROR [STDERR]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
l.java:25)
22:22:12,112 ERROR [STDERR]    at java.lang.reflect.Method.invoke(Method.java:585)
22:22:12,112 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
12)
22:22:12,112 ERROR [STDERR]    at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextI
mpl.java:166)
22:22:12,112 ERROR [STDERR]    at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3Intercept
orsInterceptor.java:63)
22:22:12,112 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,112 ERROR [STDERR]    at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(Tran
sactionScopedEntityManagerInterceptor.java:54)
22:22:12,112 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,112 ERROR [STDERR]    at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterce
ptor.java:47)
22:22:12,122 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,122 ERROR [STDERR]    at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:79)
22:22:12,132 ERROR [STDERR]    at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
22:22:12,132 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,142 ERROR [STDERR]    at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationIntercept
or.java:95)
22:22:12,142 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,152 ERROR [STDERR]    at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInsta
nceInterceptor.java:62)
22:22:12,162 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,162 ERROR [STDERR]    at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationI
nterceptor.java:77)
22:22:12,172 ERROR [STDERR]    at org.jboss.ejb3.security.Ejb3AuthenticationInterceptor.invoke(Ejb3Authentica
tionInterceptor.java:110)
22:22:12,172 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,182 ERROR [STDERR]    at org.jboss.ejb3.ENCPropagationInterceptor.invoke(ENCPropagationInterceptor.j
ava:46)
22:22:12,192 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,202 ERROR [STDERR]    at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInte
rceptor.java:106)
22:22:12,202 ERROR [STDERR]    at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:1
01)
22:22:12,212 ERROR [STDERR]    at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.
java:240)
22:22:12,212 ERROR [STDERR]    at org.jboss.ejb3.stateless.StatelessContainer.localInvoke(StatelessContainer.
java:210)
22:22:12,272 ERROR [STDERR]    at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.jav
a:84)
22:22:12,272 ERROR [STDERR]    at $Proxy66.getAllArticle(Unknown Source)
22:22:12,272 ERROR [STDERR]    at EJBClient.ClientTest.getAllArticle(ClientTest.java:18)
22:22:12,282 ERROR [STDERR]    at org.apache.jsp.index_jsp._jspService(index_jsp.java:88)
22:22:12,282 ERROR [STDERR]    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
22:22:12,282 ERROR [STDERR]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
22:22:12,282 ERROR [STDERR]    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:
373)
22:22:12,282 ERROR [STDERR]    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
22:22:12,282 ERROR [STDERR]    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
22:22:12,282 ERROR [STDERR]    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
22:22:12,282 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicatio
nFilterChain.java:290)
22:22:12,292 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterC
hain.java:206)
22:22:12,292 ERROR [STDERR]    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.j
ava:96)
22:22:12,302 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applicatio
nFilterChain.java:235)
22:22:12,312 ERROR [STDERR]    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterC
hain.java:206)
22:22:12,312 ERROR [STDERR]    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.j
ava:230)
22:22:12,322 ERROR [STDERR]    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.j
ava:175)
22:22:12,322 ERROR [STDERR]    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssoc
iationValve.java:179)

TOP

代码太乱

没有心情看下去!楼主应该拣主要的问题

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-12-3 08:43 京ICP证060528 号

Designed By 17DST