我在java中有两个类,我使用dropwizard框架。
我的类是从一个抽象类扩展,但是没有填充抽象类中的属性。
public abstract class Person(){
@Column( name = "name" )
protected String name;
@Column( name = "lastname" )
protected String lastName;
public void setName(String name){
this.name = name
}
public String getName(){
return this.name;
}
public void setLastName( String lastName ){
this.lastName = lastName;
}
public String getLastName(){
return this.lastName;
}
}
这是我的班级
@Entity
@Table(name = "users" )
public class User extends Person(){
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
@Column( name = "idUser" )
protected Long Id;
@Column( name = "username" )
protected String userName;
@Column( name = "password" )
protected String password;
public void setUserName( String userName){
this.userName = userName;
}
public String getUserName(){
return this.userName;
}
public void setPassword(String password){
this.password = password;
}
public String getPassword(){
return this.password;
}
}
当我尝试填充类时,只填充User
类中包含的属性,Person
的属性为空。
这是我的DAO
public class UsersDao extends AbstractDAO<User>{
@Inject
public UsersDao(SessionFactory sessionFactory){
super(sessionFactory);
}
public List<User> fetchUsers(){
return list(criteria());
}
}
有什么建议吗?
答案 0 :(得分:0)
你的类用括号扩展Person (),实际上它不应该有括号,你应该用 @MappedSuperClass
注释你的父类