最近的项目中有几种用户,用户的字段差别极大,只有id、username、password、userType、name等几个相同的字段,现想做单点登录,采用视图方式,现在针对上面几个字段创建了一个普通视图,命名为View_User,没有主键。然后用MyEclipse的反射工程生成Annotation配置的实体类,共生成两个实体类,如下:ViewUser类package com.ninemax.cul.user.entity;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* ViewUser entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "VIEW_USER")
public class ViewUser implements java.io.Serializable {
// Fields
private ViewUserId id;
// Constructors
/** default constructor */
public ViewUser() {
}
/** full constructor */
public ViewUser(ViewUserId id) {
this.id = id;
} 另外一个类是ViewUserId类: package com.ninemax.cul.user.entity;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
* ViewUserId entity. @author MyEclipse Persistence Tools
*/
@Embeddable
public class ViewUserId implements java.io.Serializable {
// Fields
private String id;
private String username;
private String password;
private Integer userType;
private String name;
private Boolean isWorkFlag;
// Constructors
/** default constructor */
public ViewUserId() {
}
/** full constructor */
public ViewUserId(String id, String username, String password,
Integer userType, String name, Boolean isWorkFlag) {
this.id = id;
this.username = username;
this.password = password;
this.userType = userType;
this.name = name;
this.isWorkFlag = isWorkFlag;
} 其实这样程序是可以运行的,问题在于视图中的name是可以为空的,在name为空时Hibernate加载不上来数据(为null),请问怎样才能让Hibernate将含有null字段值的记录也加载上来?网上有人介绍XML配置的解决方式,但我经验不足,没有参照着将Annotation下的解决办法找到,请各位指点一下,谢谢!
1 回答
侃侃无极
TA贡献2051条经验 获得超10个赞
是为null的显示为“”吗? 还是?
如果是为null的显示为“”,可以:
用公式 @Formula(value="case username is null then '' else username end")
删掉 @Column
添加回答
举报
0/150
提交
取消