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.  [ 4 posts ] 
Author Message
 Post subject: Simple OneToMany not working
PostPosted: Wed Aug 20, 2008 3:55 pm 
Newbie

Joined: Mon Aug 11, 2008 2:59 pm
Posts: 11
Hibernate version: Hibernate Annotations 3.3.1.GA, Hibernate 3.2.6, Hibernate EntityManager 3.3.2.GA

Hi, all.

I have a one-to-many that appears to be by-the-book according to the hibernate documentation, but the collection is always empty. If anyone has any ideas, I'd sure appreciate them.

The two classes:

Code:
package com.foo.client.dataobject;

import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

/**
* Data object that contains information about one of our clients.
*/
@Entity
@Table(name = "client")
public class Client {

  @Id
  @Column(name = "id")
  @Type(type = "com.foo.dbspecific.UUIDType")
  @GeneratedValue(generator = "inf-uuid")
  @GenericGenerator(name = "inf-uuid", strategy = "com.foo.dbspecific.UUIDGenerator")
  protected UUID mId;

  @OneToMany(mappedBy = "mClient")
  private final Set<UserLogin> mUsers = new HashSet<UserLogin>();

  // Some other columns....

  /**
   * Default constructor for JPA.
   */
  Client() {
  }

  // Other methods...

}

@Entity
@Table(name = "user_login")
public class UserLogin {

  @Id
  @Column(name = "id")
  @Type(type = "com.foo.dbspecific.UUIDType")
  @GeneratedValue(generator = "inf-uuid")
  @GenericGenerator(name = "inf-uuid", strategy = "com.foo.dbspecific.UUIDGenerator")
  protected UUID mId;

  @ManyToOne
  @JoinColumn(name = "client")
  private Client mClient;

  public UserLogin(String login, String name, String unencryptedPassword, Client client) {
    mClient = client;
    // ... Other setters
  }

  // ... other columns, methods, etc.


The user_login table has a "client" column that is a FK to the client id column.

The test:

Code:
public class UserLoginDaoTest extends AbstractTransactionalTestNGSpringContextTests {
  @PersistenceContext
  private EntityManager em;

  @Test(groups = { "functional" })
  public void createSaveFindBug() {
    Client c = (Client)em.createQuery("from Client c where c.mName=:name").setParameter("name", "test1").getSingleResult();
    System.out.println("Size 1: " + c.getUserLogins().size());
    UserLogin ul = (UserLogin)em.createQuery("from UserLogin u where u.mClient.mId=:id").setParameter("id", c.getId()).getSingleResult();
    System.out.println("UserLogin is " + ul);
    UserLogin u2 = new UserLogin("login 2", "login 2 name", "mypassword2", c);
    em.persist(u2);
    em.flush();

    // Refresh client, so that its user logins get repopulated.
    em.refresh(c);
    System.out.println("Size 2: " + c.getUserLogins().size());
  }
}


The output:

Code:
14:12:40.836 [1] DEBUG o.s.o.j.JpaTransactionManager: Opened new EntityManager [org.hibernate.ejb.EntityManagerImpl@6b51d8] for JPA transaction
Size 1: 0
UserLogin is com.foo.client.dataobject.UserLogin@a1c582
Size 2: 0


So, the test looks up an existing client that should have one UserLogin associated with it. However, when it prints out the size of the set, it's empty. The UserLogin exists correctly b/c the following hibernate query looks up the UserLogin whose mClient is equal to the client read in, and finds it. Then, just to add more surety to it, a new UserLogin for that Client is created and saved to the db, then the Client refreshed, and still its collection size is 0. As evidenced by the log below, which is from the same test, but with TRACE level logging for hibernate binding, it appears that Hibernate is actually finding the right UserLogin(s) from the db, but it just fails to put them in the collection appropriately:

Code:
14:46:11.057 [1] DEBUG o.h.SQL: select client0_.id as id0_, client0_.database_user as database2_0_, client0_.insert_tm as insert3_0_, client0_.last_update_tm as last4_0_, client0_.name as name0_, client0_.status as status0_ from client client0_ where client0_.name=?
14:46:11.057 [1] TRACE o.h.t.StringType: binding 'test1' to parameter: 1
14:46:11.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_
14:46:11.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_
14:46:11.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_
14:46:11.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_
14:46:11.260 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_
14:46:11.494 [1] DEBUG o.h.SQL: select musers0_.client as client1_, musers0_.id as id1_, musers0_.id as id2_0_, musers0_.client as client2_0_, musers0_.encrypted_password as encrypted2_2_0_, musers0_.insert_tm as insert3_2_0_, musers0_.last_update_tm as last4_2_0_, musers0_.login as login2_0_, musers0_.name as name2_0_, musers0_.status as status2_0_ from user_login musers0_ where musers0_.client=?
14:46:11.713 [1] TRACE o.h.t.StringType: returning 'asdf' as column: encrypted2_2_0_
14:46:11.713 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_2_0_
14:46:11.713 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_2_0_
14:46:11.713 [1] TRACE o.h.t.StringType: returning 'greg login' as column: login2_0_
14:46:11.713 [1] TRACE o.h.t.StringType: returning 'greg' as column: name2_0_
14:46:11.713 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_0_
14:46:11.713 [1] DEBUG o.h.SQL: select userlogin0_.id as id2_1_, userlogin0_.client as client2_1_, userlogin0_.encrypted_password as encrypted2_2_1_, userlogin0_.insert_tm as insert3_2_1_, userlogin0_.last_update_tm as last4_2_1_, userlogin0_.login as login2_1_, userlogin0_.name as name2_1_, userlogin0_.status as status2_1_, client1_.id as id0_0_, client1_.database_user as database2_0_0_, client1_.insert_tm as insert3_0_0_, client1_.last_update_tm as last4_0_0_, client1_.name as name0_0_, client1_.status as status0_0_ from user_login userlogin0_ left outer join client client1_ on userlogin0_.client=client1_.id where userlogin0_.id=?
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:11.729 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'asdf' as column: encrypted2_2_1_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_2_1_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_2_1_
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'greg login' as column: login2_1_
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'greg' as column: name2_1_
14:46:11.729 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_1_
14:46:11.729 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:11.729 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:11.729 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:11.729 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:11.729 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:11.744 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:11.744 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:11.744 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:11.744 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:11.744 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
Size 1: 0
14:46:11.901 [1] DEBUG o.h.SQL: select userlogin0_.id as id2_, userlogin0_.client as client2_, userlogin0_.encrypted_password as encrypted2_2_, userlogin0_.insert_tm as insert3_2_, userlogin0_.last_update_tm as last4_2_, userlogin0_.login as login2_, userlogin0_.name as name2_, userlogin0_.status as status2_ from user_login userlogin0_ where userlogin0_.client=?
14:46:11.901 [1] TRACE o.h.t.StringType: returning 'asdf' as column: encrypted2_2_
14:46:11.901 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_2_
14:46:11.901 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_2_
14:46:11.901 [1] TRACE o.h.t.StringType: returning 'greg login' as column: login2_
14:46:11.901 [1] TRACE o.h.t.StringType: returning 'greg' as column: name2_
14:46:11.901 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_
14:46:11.901 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:11.916 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:11.916 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:11.916 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:11.916 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:11.916 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
UserLogin is com.foo.client.dataobject.UserLogin@749436
14:46:12.073 [1] DEBUG o.h.SQL: insert into user_login (client, encrypted_password, insert_tm, last_update_tm, login, name, status, id) values (?, ?, ?, ?, ?, ?, ?, ?)
14:46:12.073 [1] TRACE o.h.t.StringType: binding 'h2en0xataMtgfHyAW4Wf+ngnfdoTt6Pi6LU8rTyrvG4=' to parameter: 2
14:46:12.073 [1] TRACE o.h.t.TimestampType: binding '2008-08-20 14:46:11' to parameter: 3
14:46:12.073 [1] TRACE o.h.t.TimestampType: binding '2008-08-20 14:46:11' to parameter: 4
14:46:12.073 [1] TRACE o.h.t.StringType: binding 'login 2' to parameter: 5
14:46:12.073 [1] TRACE o.h.t.StringType: binding 'login 2 name' to parameter: 6
14:46:12.073 [1] DEBUG o.h.t.EnumType: Binding '0' to parameter: 7
14:46:12.104 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.119 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.119 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.119 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.119 [1] DEBUG o.h.SQL: select musers0_.client as client1_, musers0_.id as id1_, musers0_.id as id2_0_, musers0_.client as client2_0_, musers0_.encrypted_password as encrypted2_2_0_, musers0_.insert_tm as insert3_2_0_, musers0_.last_update_tm as last4_2_0_, musers0_.login as login2_0_, musers0_.name as name2_0_, musers0_.status as status2_0_ from user_login musers0_ where musers0_.client=?
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'h2en0xataMtgfHyAW4Wf+ngnfdoTt6Pi6LU8rTyrvG4=' as column: encrypted2_2_0_
14:46:12.119 [1] TRACE o.h.t.TimestampType: returning '2008-08-20 14:46:11' as column: insert3_2_0_
14:46:12.119 [1] TRACE o.h.t.TimestampType: returning '2008-08-20 14:46:11' as column: last4_2_0_
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'login 2' as column: login2_0_
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'login 2 name' as column: name2_0_
14:46:12.119 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_0_
14:46:12.119 [1] DEBUG o.h.SQL: select userlogin0_.id as id2_1_, userlogin0_.client as client2_1_, userlogin0_.encrypted_password as encrypted2_2_1_, userlogin0_.insert_tm as insert3_2_1_, userlogin0_.last_update_tm as last4_2_1_, userlogin0_.login as login2_1_, userlogin0_.name as name2_1_, userlogin0_.status as status2_1_, client1_.id as id0_0_, client1_.database_user as database2_0_0_, client1_.insert_tm as insert3_0_0_, client1_.last_update_tm as last4_0_0_, client1_.name as name0_0_, client1_.status as status0_0_ from user_login userlogin0_ left outer join client client1_ on userlogin0_.client=client1_.id where userlogin0_.id=?
14:46:12.119 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.119 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.151 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.151 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.151 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.151 [1] TRACE o.h.t.StringType: returning 'h2en0xataMtgfHyAW4Wf+ngnfdoTt6Pi6LU8rTyrvG4=' as column: encrypted2_2_1_
14:46:12.166 [1] TRACE o.h.t.TimestampType: returning '2008-08-20 14:46:11' as column: insert3_2_1_
14:46:12.166 [1] TRACE o.h.t.TimestampType: returning '2008-08-20 14:46:11' as column: last4_2_1_
14:46:12.166 [1] TRACE o.h.t.StringType: returning 'login 2' as column: login2_1_
14:46:12.166 [1] TRACE o.h.t.StringType: returning 'login 2 name' as column: name2_1_
14:46:12.166 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_1_
14:46:12.166 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:12.166 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.166 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.166 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.166 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.166 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.182 [1] TRACE o.h.t.StringType: returning 'asdf' as column: encrypted2_2_0_
14:46:12.229 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_2_0_
14:46:12.229 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_2_0_
14:46:12.229 [1] TRACE o.h.t.StringType: returning 'greg login' as column: login2_0_
14:46:12.229 [1] TRACE o.h.t.StringType: returning 'greg' as column: name2_0_
14:46:12.229 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_0_
14:46:12.229 [1] DEBUG o.h.SQL: select userlogin0_.id as id2_1_, userlogin0_.client as client2_1_, userlogin0_.encrypted_password as encrypted2_2_1_, userlogin0_.insert_tm as insert3_2_1_, userlogin0_.last_update_tm as last4_2_1_, userlogin0_.login as login2_1_, userlogin0_.name as name2_1_, userlogin0_.status as status2_1_, client1_.id as id0_0_, client1_.database_user as database2_0_0_, client1_.insert_tm as insert3_0_0_, client1_.last_update_tm as last4_0_0_, client1_.name as name0_0_, client1_.status as status0_0_ from user_login userlogin0_ left outer join client client1_ on userlogin0_.client=client1_.id where userlogin0_.id=?
14:46:12.244 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.244 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.244 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.244 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.244 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.244 [1] TRACE o.h.t.StringType: returning 'asdf' as column: encrypted2_2_1_
14:46:12.244 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_2_1_
14:46:12.244 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_2_1_
14:46:12.244 [1] TRACE o.h.t.StringType: returning 'greg login' as column: login2_1_
14:46:12.244 [1] TRACE o.h.t.StringType: returning 'greg' as column: name2_1_
14:46:12.244 [1] DEBUG o.h.t.EnumType: Returning '0' as column status2_1_
14:46:12.244 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:12.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.260 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.260 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:12.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.260 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.260 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.260 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
14:46:12.260 [1] DEBUG o.h.SQL: select client0_.id as id0_0_, client0_.database_user as database2_0_0_, client0_.insert_tm as insert3_0_0_, client0_.last_update_tm as last4_0_0_, client0_.name as name0_0_, client0_.status as status0_0_ from client client0_ where client0_.id=?
14:46:12.276 [1] TRACE o.h.t.StringType: returning 'test1' as column: database2_0_0_
14:46:12.276 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: insert3_0_0_
14:46:12.276 [1] TRACE o.h.t.TimestampType: returning '2008-07-30 15:28:53' as column: last4_0_0_
14:46:12.276 [1] TRACE o.h.t.StringType: returning 'test1' as column: name0_0_
14:46:12.276 [1] DEBUG o.h.t.EnumType: Returning '0' as column status0_0_
Size 2: 0


I'd appreciate it greatly if anyone can see if I'm doing something wrong -- otherwise, I assume it's a hibernate bug, but it seems like such a simple thing that it's hard to imagine the bug hasn't been found previously....

Thanks much in advance,
Greg


Last edited by gregthoen on Fri Aug 22, 2008 5:41 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 5:08 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Code:
private final Set<UserLogin> mUsers = new HashSet<UserLogin>();


I think the problem may be that you have made it final. Hibernate doesn't use the HashSet you have created, but wants to replace it by a special implementation. The reason for that is to support lazy loading, tracking of additions and removals, etc.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 20, 2008 5:41 pm 
Newbie

Joined: Mon Aug 11, 2008 2:59 pm
Posts: 11
Thanks for looking at it, nordborg. The "final" part is definitely a mistake -- unfortunately due to our company having eclipse set up to automatically mark all member variables that don't have a setter outside of a/the constructor as final when the file is saved...

However, I modified my eclipse settings such that it would not automatically put final on the field, and removed the final part of the declaration, and it's exactly the same output (i.e. still doesn't work).

As an aside, FYI, I modified the test to print out the classname of mUsers on the Client object instance, and even when it's declared as a private final variable, it's instantiated as an org.hibernate.collection.PersistentSet rather than a java.util.HashSet. In fact, I found out that that's the case whether it's private, protected, or package protected. However, if I make the variable public, a org.hibernate.PropertyAccessException gets thrown when it tries to set the collection, due to an IllegalAccessException from Java when trying to set it. I would think that exception would get thrown regardless of variable visibility if the member variable is final, but.... Not important, but interesting. ;)

Anyway, I appreciate your looking at the posting -- do you have any other ideas?

Thanks a lot,
Greg


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 21, 2008 6:37 pm 
Newbie

Joined: Mon Aug 11, 2008 2:59 pm
Posts: 11
*sigh* Never mind. I figured out finally that our problem was with our ids (UUIDs) by changing the ids of the objects from a UUID to an int, and noticed that then the test worked fine. Looking at the UserType for UUID's that we wrote here (UUIDType), it appears that the guy who wrote the UserType had this in it:

Code:
@Override
  public boolean equals(Object x, Object y) {
    return x == y;
  }


rather than:

Code:
  @Override
  public boolean equals(Object x, Object y) {
    return x.equals(y);
  }


I think he just copied/pasted a UserType implementation he found somewhere on the web (that must have been for a primitive type), and didn't know to change the .equals(). Turns out that this root problem caused a number of apparent hibernate bugs, including this one. Sorry for wasting your time...

Greg


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.