I'm using Hibernate via JPA on JBoss 5.1.0 (database is postgreSQL 8.3). Recently, I noticed that some of my data was being returned as null instead of the actual values. It appears to be random which records are affected, but the same record is repeatably retrieved incorrectly, even if I completely restart JBoss and my application.
The entity definition is:
Code:
@NamedQuery(name = "SystemUser.getUsingEmail",
query = "SELECT usr from SystemUser usr "
+ " WHERE usr.email = :email")
@Entity
@Table(name = "users")
public final class SystemUser implements Serializable {
private static final long serialVersionUID = - 7158015665952122001L;
@Id
@SequenceGenerator(name = "SystemUserIdGenerator",
sequenceName = "users_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "SystemUserIdGenerator")
@Column(name = "user_id")
private int id;
@Column(name = "email", length = 320, nullable = false)
private String email;
@Column(name = "password_sha256", length = 43)
private String passwordSha256;
public SystemUser() {}
public int getId() {
return this.id;
}
public String getEmail() {
return this.email;
}
public String getPasswordSha256() {
return this.passwordSha256;
}
}
And it's being accessed with:
Code:
final Query userQuery = this.manager
.createNamedQuery("SystemUser.getUsingEmail")
.setParameter("email", aEmail)
.setMaxResults(2);
List<SystemUser> users = userQuery.getResultList();
Most of the time this works. But for some email addresses, the passwordSha256 string is null. If I take the SQL generated by show_sql and paste it into psql, it returns the correct data.
Any ideas why Hibernate is returning null in some cases, even if the generated SQL works?