-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate not retrieving data correctly
PostPosted: Fri Jul 02, 2010 11:05 pm 
Newbie

Joined: Fri Jul 02, 2010 10:50 pm
Posts: 2
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?


Top
 Profile  
 
 Post subject: Re: Hibernate not retrieving data correctly
PostPosted: Thu Jul 08, 2010 10:32 pm 
Newbie

Joined: Fri Jul 02, 2010 10:50 pm
Posts: 2
I found the problem; one of my datasources pointed to a test database which had almost the same data, but not quite. Everything makes sense now, and there's nothing to see here.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.