我有一個非常簡單的用戶實體,它填充(h2)數據庫中的用戶名和密碼字段。Dropwizard休眠字段不填充
我似乎無法添加更多的字段,雖然爲boolean isAdmin
- 我試過原始和對象布爾值。 SQL休眠執行會被記錄下來,當我運行它時,會返回給定用戶的用戶表中的所有字段,包括boolean
值(true
)。然而Boolean
仍然是null
。
任何想法如何讓這個領域填充?
@Entity
@Table(name = "users")
@NamedQueries({
@NamedQuery(
name = "eu.wansdyke.smaash.core.User.findAll",
query = "SELECT u FROM User u"
),
@NamedQuery(
name = "eu.wansdyke.smaash.core.User.deleteByUsername",
query = "DELETE FROM User WHERE username = :username"
),
@NamedQuery(
name = "eu.wansdyke.smaash.core.User.findByUsername",
query = "SELECT u FROM User u WHERE u.username = :username"
)
})
@NamedNativeQueries({
@NamedNativeQuery(
name = "eu.wansdyke.smaash.core.User.setPassword",
query = "merge into users (username, password) key(username) values (:username, :password)"
)
})
public class User {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "username", nullable = false)
private String username;
@Column(name = "password", nullable = false)
private String password;
@Column(name = "isadmin", nullable = false)
private Boolean isAdmin;
public User() {
}
public User(String username) {
this.username = username;
}
public long getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public Boolean isAdmin() {
return isAdmin;
}
}
該字段值位於數據庫中,它正在讀取它未填充的值。 – rich 2014-09-02 11:20:18
它應該由此構造函數填充。 – 2014-09-02 11:23:19