单向多对一,只从用户查角色,不查角色对应的用户user的配置信息:<many-to-one name="role" class="com.xqkj.ht.role.entity.Role" cascade="save-update" fetch="select"> <column name="role_id" not-null="true" ></column> </many-to-one>测试类:@Test public void saveUser() { ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml"); //RoleService roleService = (RoleService) ac.getBean("roleService"); UserService userService = (UserService) ac.getBean("userService"); User user = userService.findById("8a02303c5f14f56a015f14f56cce0000"); System.out.println(user.getRole().getName()); System.out.println(user.getAccount()); }报错信息:org.hibernate.LazyInitializationException: could not initialize proxy - no Session
添加回答
举报
0/150
提交
取消