spring中的no session问题

还是用代码说事吧

java 代码
  1. this.control = (TableOption) BeanFactory.getInstance().getBean("tableoption");      
  2. this.scheduler.setId(schedulerId);      
  3. this.scheduler = (TScheduler)this.control.getInfo(scheduler);    
  4. System.out.println(this.scheduler.getNode().getAuthor().getName());  

执行第四行时报错

 
  1. 严重: could not initialize proxy - no Session   
  2. org.hibernate.LazyInitializationException: could not initialize proxy - no Session   
  3.     at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)   
  4.     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)   
  5.     at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)   
  6.     at com.actmaps.rights.user.TableUserInfo$$EnhancerByCGLIB$$b4dd839.getName(<generated></generated>)   
  7.     at com.actmaps.scheduler.mail.SendMail.initParams(SendMail.java:44)   
  8.     at com.actmaps.scheduler.ReminderManage.execute(ReminderManage.java:53)   
  9.     at com.actmaps.scheduler.ReminderManage.executeInternal(ReminderManage.java:26)   
  10.     at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)   
  11.     at org.quartz.core.JobRunShell.run(JobRunShell.java:203)   
  12.     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)   
  13. org.hibernate.LazyInitializationException: could not initialize proxy - no Session   
  14.     at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)   
  15.     at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)   
  16.     at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)   
  17.     at com.actmaps.rights.user.TableUserInfo$$EnhancerByCGLIB$$b4dd839.getName(<generated></generated>)   
  18.     at com.actmaps.scheduler.mail.SendMail.initParams(SendMail.java:44)   
  19.     at com.actmaps.scheduler.ReminderManage.execute(ReminderManage.java:53)   
  20.     at com.actmaps.scheduler.ReminderManage.executeInternal(ReminderManage.java:26)   
  21.     at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)   
  22.     at org.quartz.core.JobRunShell.run(JobRunShell.java:203)   
  23.     at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)   
  24. 2007-8-30 19:12:36 com.actmaps.scheduler.ReminderManage execute   
  25. 严重: 执行定时提醒时发生异常:could not initialize proxy - no Session  

对于BeanFactory

java 代码2
  1. public class BeanFactory {   
  2.     protected static final Log log = LogFactory.getLog(BeanFactory.class);   
  3.     private static String[] contextFile = new String[]{"applicationContext.xml"};   
  4.     private static ApplicationContext ac;   
  5.     private SessionFactory sessionFactory;   
  6.     private Session session;   
  7.        
  8.     /**  
  9.      * TODO 这种单例模式的写法在多个虚拟机的情况下还是不安全的,但是一般情况下是可以的。  
  10.      * @author PHeH
     
  11.      * Created On 2007-7-7 15:47:22  
  12.      */  
  13.     static class SingletonHolder{   
  14.         static BeanFactory instance = new BeanFactory();   
  15.     }   
  16.        
  17.     private BeanFactory(){   
  18.         log.info("*************开始加载Spring*************");   
  19.         ac = new ClassPathXmlApplicationContext(contextFile);   
  20.         sessionFactory = (SessionFactory) ac.getBean("sessionFactory");   
  21.         session = SessionFactoryUtils.getSession(sessionFactory, true);   
  22.         TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));   
  23.         log.info("*************完成加载Spring*************");   
  24.     }   
  25.        
  26.     public static final BeanFactory getInstance(){   
  27.         return SingletonHolder.instance;   
  28.     }   
  29.        
  30.     /**  
  31.      * 根据bean的id取得bean的实例的方法  
  32.      * @param beanid  
  33.      * @return  
  34.      */  
  35.     public Object getBean(String beanid){   
  36.         return ac.getBean(beanid);   
  37.     }   
  38. }  

 

scheduler的配置文件
  1. <class name="TScheduler" table="Scheduler_Scheduler">  
  2.         <id name="id" type="integer" column="id">  
  3.             <generator class="foreign">  
  4.                 <param name="property">nodeparam>  
  5.             generator>  
  6.         id>  
  7.         <one-to-one name="node" class="com.actmaps.common.TNode" constrained="true" fetch="select"/>  
  8.            
  9.         <property name="valid" column="valid" type="boolean" not-null="false"/>  
  10.         <property name="startDate" column="startDate" type="java.util.Date" not-null="false"/>  
  11.         <property name="endDate" column="endDate" type="timestamp" not-null="false"/>  
  12.         <property name="repeatNum" column="repeatNum" type="integer" not-null="false"/>  
  13.         <property name="repeatInterval" column="repeatInterval" type="long" not-null="false"/>  
  14.      .......

 

node的配置文件
  1. <class name="com.actmaps.common.TTreeNode" table="Common_Node" dynamic-update="true" polymorphism="explicit">  
  2.         <id name="id" type="integer" column="id">  
  3.             <generator class="native"/>  
  4.         id>  
  5.         <discriminator column="NODE_TYPE" type="string"/>  
  6.         <property name="name" column="name" type="string" not-null="false"/>  
  7.         <many-to-one name="author" column="authorId" class="com.actmaps.rights.user.TableUserInfo" not-null="false"/>
  8. ......   
  9.           
在BeanFactory中已经将session绑定了,怎么还会报no session的异常,他在eclipse中运行正常,只是在tomcat中会出现该异常,还请大家,到底为什么会这样
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值