- pheh
- 等级: 初级会员
- 性别:
- 文章: 18
- 积分: 90
- 来自: 天津
|
还是用代码说事吧
java 代码
- this.control = (TableOption) BeanFactory.getInstance().getBean("tableoption");
- this.scheduler.setId(schedulerId);
- this.scheduler = (TScheduler)this.control.getInfo(scheduler);
- System.out.println(this.scheduler.getNode().getAuthor().getName());
执行第四行时报错
- 严重: could not initialize proxy - no Session
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
- at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
- at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
- at com.actmaps.rights.user.TableUserInfo$$EnhancerByCGLIB$$b4dd839.getName(<generated></generated>)
- at com.actmaps.scheduler.mail.SendMail.initParams(SendMail.java:44)
- at com.actmaps.scheduler.ReminderManage.execute(ReminderManage.java:53)
- at com.actmaps.scheduler.ReminderManage.executeInternal(ReminderManage.java:26)
- at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
- at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
- at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
- org.hibernate.LazyInitializationException: could not initialize proxy - no Session
- at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:57)
- at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:111)
- at org.hibernate.proxy.pojo.cglib.CGLIBLazyInitializer.invoke(CGLIBLazyInitializer.java:150)
- at com.actmaps.rights.user.TableUserInfo$$EnhancerByCGLIB$$b4dd839.getName(<generated></generated>)
- at com.actmaps.scheduler.mail.SendMail.initParams(SendMail.java:44)
- at com.actmaps.scheduler.ReminderManage.execute(ReminderManage.java:53)
- at com.actmaps.scheduler.ReminderManage.executeInternal(ReminderManage.java:26)
- at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:86)
- at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
- at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
- 2007-8-30 19:12:36 com.actmaps.scheduler.ReminderManage execute
- 严重: 执行定时提醒时发生异常:could not initialize proxy - no Session
对于BeanFactory
java 代码2
- public class BeanFactory {
- protected static final Log log = LogFactory.getLog(BeanFactory.class);
- private static String[] contextFile = new String[]{"applicationContext.xml"};
- private static ApplicationContext ac;
- private SessionFactory sessionFactory;
- private Session session;
-
-
-
-
-
-
- static class SingletonHolder{
- static BeanFactory instance = new BeanFactory();
- }
-
- private BeanFactory(){
- log.info("*************开始加载Spring*************");
- ac = new ClassPathXmlApplicationContext(contextFile);
- sessionFactory = (SessionFactory) ac.getBean("sessionFactory");
- session = SessionFactoryUtils.getSession(sessionFactory, true);
- TransactionSynchronizationManager.bindResource(sessionFactory, new SessionHolder(session));
- log.info("*************完成加载Spring*************");
- }
-
- public static final BeanFactory getInstance(){
- return SingletonHolder.instance;
- }
-
-
-
-
-
-
- public Object getBean(String beanid){
- return ac.getBean(beanid);
- }
- }
scheduler的配置文件
- <class name="TScheduler" table="Scheduler_Scheduler">
- <id name="id" type="integer" column="id">
- <generator class="foreign">
- <param name="property">nodeparam>
- generator>
- id>
- <one-to-one name="node" class="com.actmaps.common.TNode" constrained="true" fetch="select"/>
-
- <property name="valid" column="valid" type="boolean" not-null="false"/>
- <property name="startDate" column="startDate" type="java.util.Date" not-null="false"/>
- <property name="endDate" column="endDate" type="timestamp" not-null="false"/>
- <property name="repeatNum" column="repeatNum" type="integer" not-null="false"/>
- <property name="repeatInterval" column="repeatInterval" type="long" not-null="false"/>
- .......
node的配置文件
- <class name="com.actmaps.common.TTreeNode" table="Common_Node" dynamic-update="true" polymorphism="explicit">
- <id name="id" type="integer" column="id">
- <generator class="native"/>
- id>
- <discriminator column="NODE_TYPE" type="string"/>
- <property name="name" column="name" type="string" not-null="false"/>
- <many-to-one name="author" column="authorId" class="com.actmaps.rights.user.TableUserInfo" not-null="false"/>
- ......
-
在BeanFactory中已经将session绑定了,怎么还会报no session的异常,他在eclipse中运行正常,只是在tomcat中会出现该异常,还请大家,到底为什么会这样
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
|
返回顶楼 |
|
|
- djhyoo
- 等级: 初级会员
- 性别:
- 文章: 41
- 积分: 40
- 来自: 北京
|
把config拿来看看
|
返回顶楼 |
|
|
- lkl_1981
- 等级: 初级会员
- 性别:
- 文章: 7
- 积分: 30
- 来自: 北京
|
我也出现这个问题了!不知道为什么?
|
返回顶楼 |
|
|
- 21ca
- 等级: 初级会员
- 性别:
- 文章: 19
- 积分: 90
- 来自: 西安
|
在集合上面加上fetch = FetchType.EAGER。
|
返回顶楼 |
|
|