久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

java - eclipse 自動(dòng)生成的hibernateDAO出現(xiàn)錯(cuò)誤

瀏覽:164日期:2023-12-31 08:52:43

問(wèn)題描述

java - eclipse 自動(dòng)生成的hibernateDAO出現(xiàn)錯(cuò)誤

DAO自動(dòng)生成代碼

public class UserinfoHome { private static final Log log = LogFactory.getLog(UserinfoHome.class); private final SessionFactory sessionFactory = getSessionFactory(); protected SessionFactory getSessionFactory() {try { return (SessionFactory) new InitialContext().lookup('SessionFactory');} catch (Exception e) { log.error('Could not locate SessionFactory in JNDI', e); throw new IllegalStateException('Could not locate SessionFactory in JNDI');} } public void persist(Userinfo transientInstance) {log.debug('persisting Userinfo instance');try { sessionFactory.getCurrentSession().persist(transientInstance); log.debug('persist successful');} catch (RuntimeException re) { log.error('persist failed', re); throw re;} } public void attachDirty(Userinfo instance) {log.debug('attaching dirty Userinfo instance');try { sessionFactory.getCurrentSession().saveOrUpdate(instance); log.debug('attach successful');} catch (RuntimeException re) { log.error('attach failed', re); throw re;} } public void attachClean(Userinfo instance) {log.debug('attaching clean Userinfo instance');try { sessionFactory.getCurrentSession().lock(instance, LockMode.NONE); log.debug('attach successful');} catch (RuntimeException re) { log.error('attach failed', re); throw re;} } public void delete(Userinfo persistentInstance) {log.debug('deleting Userinfo instance');try { sessionFactory.getCurrentSession().delete(persistentInstance); log.debug('delete successful');} catch (RuntimeException re) { log.error('delete failed', re); throw re;} } public Userinfo merge(Userinfo detachedInstance) {log.debug('merging Userinfo instance');try { Userinfo result = (Userinfo) sessionFactory.getCurrentSession().merge(detachedInstance); log.debug('merge successful'); return result;} catch (RuntimeException re) { log.error('merge failed', re); throw re;} } public Userinfo findById(java.lang.Integer id) {log.debug('getting Userinfo instance with id: ' + id);try { Userinfo instance = (Userinfo) sessionFactory.getCurrentSession().get('com.po.Userinfo', id); if (instance == null) {log.debug('get successful, no instance found'); } else {log.debug('get successful, instance found'); } return instance;} catch (RuntimeException re) { log.error('get failed', re); throw re;} } public List findByExample(Userinfo instance) {log.debug('finding Userinfo instance by example');try { List results = sessionFactory.getCurrentSession().createCriteria('com.po.Userinfo') .add(Example.create(instance)).list(); log.debug('find by example successful, result size: ' + results.size()); return results;} catch (RuntimeException re) { log.error('find by example failed', re); throw re;} }}

hibernate.cfg.xml代碼

<hibernate-configuration> <session-factory ><property name='hibernate.connection.driver_class'>com.mysql.jdbc.Driver</property><property name='hibernate.connection.password'>lcy2350738</property><property name='hibernate.connection.url'>jdbc:mysql://localhost:3306/userdb</property><property name='hibernate.connection.username'>root</property><property name='hibernate.dialect'>org.hibernate.dialect.MySQLDialect</property><property name='hibernate.search.autoregister_listeners'>true</property><property name='hibernate.validator.apply_to_ddl'>false</property><mapping resource='com/po/Userinfo.hbm.xml' /> </session-factory></hibernate-configuration>

問(wèn)題解答

回答1:

(SessionFactory) new InitialContext().lookup('SessionFactory')改為(SessionFactory)new Configuration().configure().buildSessionFactory()試試

標(biāo)簽: java
相關(guān)文章:
主站蜘蛛池模板: 林州市| 丹寨县| 筠连县| 天门市| 宣恩县| 济阳县| 巴青县| 应城市| 阜康市| 罗定市| 钦州市| 营山县| 竹溪县| 霸州市| 南丰县| 岱山县| 莱芜市| 美姑县| 武鸣县| 成都市| 阳山县| 石阡县| 蓬溪县| 台南县| 石楼县| 冀州市| 盐城市| 锡林浩特市| 宝清县| 上蔡县| 穆棱市| 乌兰察布市| 商水县| 长泰县| 遂溪县| 大竹县| 夏津县| 德令哈市| 康定县| 原平市| 和静县|