还是用代码说事吧
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;
- /**
- * TODO 这种单例模式的写法在多个虚拟机的情况下还是不安全的,但是一般情况下是可以的。
- * @author PHeH
- * Created On 2007-7-7 15:47:22
- */
- 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;
- }
- /**
- * 根据bean的id取得bean的实例的方法
- * @param beanid
- * @return
- */
- 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"/>
- ......