问题描述
后台使用hibernate的findByCriteria方法进行查询@RequestMapping(value="/list")@ResponseBodypublic DataResponse<User> list(@RequestParam("page") String page,@RequestParam("rows") String rows,@RequestParam("sidx") String sidx,@RequestParam("sord") String sord){try {DataRequest request = new DataRequest();request.setPage(StringUtils.isEmpty(page) ? 1 : Integer.valueOf(page));request.setRows(StringUtils.isEmpty(rows) ? 20 : Integer.valueOf(rows));request.setSidx(sidx);request.setSord(sord);return customSearchUtil.search(request, User.class);} catch (Exception e) {e.printStackTrace();}return null;}customSearchUtil.search方法只是调用findByCriteria然后把数据返回.User类我已将一个多对多的属性针对JSON进行屏蔽代码执行到return 语句都只打印了一句sql查询语句但是方法结束到前台显示就会打印出查询role信息的sql语句请问这是jqgrid的问题吗?实体类如下@Entity@Table(name="SYS_USER")@JsonIgnoreProperties(value={"hibernateLazyInitializer", "roles"})public class User implements Serializable, UserDetails {@Id @SequenceGenerator(name = "SEQ_USER", sequenceName = "SEQ_USER")@GeneratedValue(strategy = GenerationType.SEQUENCE,generator = "SEQ_USER")private Integer id;@Column(name = "USERNAME", length = 100, nullable = false)private String username;@Column(name = "FULLNAME", length = 255)private String fullname;@Column(name = "PASSWORD", nullable = false)private String password;@Column(name = "ENABLED")private Integer isEnabled;@Column(name = "IS_ADMIN")private Integer isAdmin;@Column(name = "VERSION")private Integer version;@Cascade(value={CascadeType.SAVE_UPDATE})@ManyToMany(fetch = FetchType.LAZY)@JoinTable(schema = "TRAIN", name = "SYS_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID", referencedColumnName = "ID", nullable = false) })Set<Role> roles; 问题补充:asyty 写道
解决方案
引用@ManyToMany(fetch = FetchType.LAZY) 我不知道用criteria会不会无视这个配置,不过criteria是可以设置fetchMode的,criteria.setFetchMode("roles", FetchMode.LAZY)
解决方案二:
或者你前台哪儿用到了role里面的值