Terry.Li-彬

虚其心,可解天下之问;专其心,可治天下之学;静其心,可悟天下之理;恒其心,可成天下之业。

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  143 随笔 :: 344 文章 :: 130 评论 :: 0 Trackbacks

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/transaction/TransactionManager
Caused by: java.lang.NoClassDefFoundError: javax/transaction/TransactionManager

解决:

需要包jta.jar

 

--------------------------------------------------------------------------------------------------------------------------------

 

Exception in thread "main" java.lang.ClassCastException: $Proxy0
 at com.ambow.sh.test.Test.main(Test.java:16)
2009-2-10 15:30:32 net.sf.ehcache.CacheManager$1 run
信息: VM shutting down with the CacheManager still active. Calling shutdown.

 

下面是我的代码

 

public   class  Test {

    
public   static   void
 main(String[] args) {

        BeanFactory fac 
=   new   ClassPathXmlApplicationContext( " applicationContext.xml "
);
        
        LoginDAO ex 
=  (LoginDAO) fac.getBean( " LoginDAO "
);
        
        Login login 
=   new
 Login();
        
        login.setUsername(
" zhangsan "
);
        login.setPassword(
" 123456 "
);
        ex.save(login);
    
    }

}

 

 

 

其中LoginDao 是继承LoginInter 接口的

 

所以我们的解决方法 就是用接口来接受获得的bean

 

 

public   class  Test {

    
public   static   void
 main(String[] args) {

        BeanFactory fac 
=   new   ClassPathXmlApplicationContext( " applicationContext.xml "
);
        
// 改成接口接受

        LoginInter ex  =  (LoginInter) fac.getBean( " LoginDAO " );
        
        Login login 
=   new
 Login();
        
        login.setUsername(
" zhangsan "
);
        login.setPassword(
" 123456 "
);
        ex.save(login);
    
    }

}

 
-------------------------------------------------------------------------------------------------------------------------------
一对一
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fac' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.hibernate.MappingException: must specify an identifier type:
请设定参照属性的名字
 
--------------------------------------------------------------------------------------------------------------------------------

严重: Servlet.service() for servlet default threw exception
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
 at org.springframework.orm.hibernate3.HibernateTemplate.checkWriteOperationAllowed(HibernateTemplate.java:1182)
 at org.springframework.orm.hibernate3.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:692)
 at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:419)
 at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
 at org.springframework.orm.hibernate3.HibernateTemplate.save(HibernateTemplate.java:690)
 at com.ambow.ExamOnlineSystem.dao.ExamDaoImpl.add(ExamDaoImpl.java:18)
 at com.ambow.ExamOnlineSystem.entity.question.service.QuestionServiceImpl.save(QuestionServiceImpl.java:22)
 at com.ambow.ExamOnlineSystem.entity.question.action.QuestionAddAction.save(QuestionAddAction.java:39)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

 

解决:

修改web.xml中的] <param-value>false </param-value>为false试试!

< filter >  
< filter-name > hibernateFilter  </ filter-name >  
< filter-class >  
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter 
</ filter-class >  
< init-param >  
< param-name > singleSession  </ param-name >  
< param-value > false  </ param-value >   </ init-param >  
</ filter >
 
--------------------------------------------------------------------------------------------------------------------------------
 


java.lang.IllegalArgumentException: node to traverse cannot be null!
 at org.hibernate.hql.ast.util.NodeTraverser.traverseDepthFirst(NodeTraverser.java:31)
 at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:254)
 at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:157)
 at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
 at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
 at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
 at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
 at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
 at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)

问题解决:

出现这种问题是因为HQL语句出现问题,引起内部查询对象为空,无法处理为空值引起的。解决方法,检查HQL语句(尤其是关键字)。

posted on 2011-01-18 08:55 礼物 阅读(959) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。

网站导航: