zoukankan      html  css  js  c++  java
  • jpa could not initialize proxy [com.modelname#1]

    jpa测试Dao.getOne的时候报错could not initialize proxy [com.modelname#1] - no Session

    测试代如下

        @Test
        public void findOne_getOne() {
            System.out.println("=============== findPage ================" );
            SysUser entity=new SysUser();
            entity.setUserId(1);
           SysUser enitityNew=sysUserDao.getOne(entity.getUserId());
            if(enitityNew!=null){
                System.out.println("enitityNew ok:" );
                System.out.println("name:"+ enitityNew.getUserName());
            }else {
                System.out.println("enitityNew is null:" );
            }
        }

    解决办法:给方法添加 @Transactional 注解就搞定了,如下

    @Test
        @Transactional //不加这个会报错 could not initialize proxy [com.model#1] - no Session
        public void findOne_getOne() {
            System.out.println("=============== findPage ================" );
            SysUser entity=new SysUser();
            entity.setUserId(1);
           SysUser enitityNew=sysUserDao.getOne(entity.getUserId());
            if(enitityNew!=null){
                System.out.println("enitityNew ok:" );
                System.out.println("name:"+ enitityNew.getUserName());
            }else {
                System.out.println("enitityNew is null:" );
            }
        }
  • 相关阅读:
    Qt环境搭建(Visual Studio)
    HTML基础
    关于Qt
    I am back
    Node Security
    Mobile Assistant
    Home Server
    抉择-什么最重要
    在一个JSP页面中包含另一个JSP页面的三种方式
    JS控制DIV隐藏显示
  • 原文地址:https://www.cnblogs.com/q149072205/p/12881736.html
Copyright © 2011-2022 走看看