记hibernate一次坑

在使用hibernate反转工程时有一个坑放在这里,避免大家跳进去。本人用的是myeclipse2017ci,在使用hibernate反转工程生成原始dao方法时碰到的bug。在方法public Account findById(Long id)中有一段代码及其坑爹

log.debug("getting Account instance with id: " + id);
		try {
			Account instance = (Account) getSession().get("Account", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}

改为原始的session.get(***.class,id)

public Account findById(Long id) {
		log.debug("getting Account instance with id: " + id);
		try {
			Account instance = (Account) getSession().get(Account.class, id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

不然经常报错Exception in thread "main" org.hibernate.UnknownEntityTypeException: Unable to locate persister: Account并非是自己配置文件写错了,而是传入的参数不准确,导致自己查了几天bug。

猜你喜欢

转载自blog.csdn.net/weixin_40657079/article/details/84729917