简体   繁体   English

从Dropwizard中的抽象扩展时未填充类

[英]Class is not populated when extends from an abstract in Dropwizard

HI I have two classes in java, I'm using dropwizard framework. 嗨,我在Java中有两个类,我正在使用dropwizard框架。

My class is extending from an abstract class, but the properties that are in the abstract class are not being populated. 我的类是从抽象类扩展的,但是没有填充抽象类中的属性。

     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;
       }
    }

And Here is my class 这是我的课

    @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;
      }
    }

When I try to populate the class only populate the properties that are contained in User class the properties of Person are null. 当我尝试填充类时,仅填充User类中包含的属性, Person的属性为null。

This is my DAO 这是我的DAO

    public class UsersDao extends AbstractDAO<User>{
           @Inject
            public UsersDao(SessionFactory sessionFactory){
             super(sessionFactory);
            }

            public List<User> fetchUsers(){
              return list(criteria());
            }
       }

Any suggestion? 有什么建议吗?

您的类用括号扩展Person () ,但实际上它不应该带有括号,您应该使用@MappedSuperClass注释父类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM