title: Can not set java.lang.String field to java.lang.String
body: <p>I am currently developing a small MMO application with a socket server. The database i am using is PostgreSQL and i am using the Hibernate ORM. 
  I stumbled on to a exeption when requesting all the avatars an single user owns. </p>
  
  <p>I got 3 classes involed, those are :</p>
  
  <ul>
  <li>GameServerClient</li>
  <li>Database</li>
  <li>Database.Queries</li>
  </ul>
  
  <p>When the user (client application) sends a request to the server via the sockets, a method is called which should return a JsonString of the all the Avatars.</p>
  
  <p>How ever, using the HQL query <code>from UserOwnsAvatar where user = :username</code> and puting the result in an ArrayList of the UserOwnsAvatar object it returns an <code>Can not set java.lang.String field nl.marcusink.mmo.server.database.table.User.username to java.lang.String</code></p>
  
  <p>the full stackTrace is :</p>
  
  <pre><code>org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String nl.marcusink.mmo.server.database.table.User.username] by reflection for persistent property [nl.marcusink.mmo.server.database.table.User#username] : Mjollnir94
      at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:43)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:223)
      at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:4594)
      at org.hibernate.type.EntityType.toLoggableString(EntityType.java:505)
      at org.hibernate.internal.util.EntityPrinter.toString(EntityPrinter.java:87)
      at org.hibernate.engine.spi.QueryParameters.traceParameters(QueryParameters.java:281)
      at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:194)
      at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1268)
      at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)
      at nl.marcusink.mmo.server.database.Database$Queries.avatarsRequest(Database.java:134)
      at nl.marcusink.mmo.server.connection.GameServerClient.run(GameServerClient.java:91)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field nl.marcusink.mmo.server.database.table.User.username to java.lang.String
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
      at sun.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
      at sun.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
      at sun.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
      at java.lang.reflect.Field.get(Field.java:393)
      at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:39)
      ... 11 more
  </code></pre>
  
  <p>the query code is :</p>
  
  <pre><code>Query query = session.createQuery("from UserOwnsAvatar where user = :username");
  query.setParameter("username", username);
  ArrayList&lt;UserOwnsAvatar&gt; ownedAvatars = (ArrayList&lt;UserOwnsAvatar&gt;) query.list();
  </code></pre>
  
  <p>The last line is the cause of the error, any ideas?</p>
  
  <p>EDIT</p>
  
  <pre><code>@Id
  @ManyToOne(targetEntity = User.class)
  @JoinColumn(name = "username", nullable = false)
  private User user;
  
  @Id
  @OneToOne(targetEntity = Avatar.class)
  @JoinColumn(name = "avatar", nullable = false, unique = true)
  private Avatar avatar;
  </code></pre>
  
  <p>The username here is equal to the username of the User object, which is :</p>
  
  <pre><code>@Id
  @Column(name = "username", unique = true, nullable = false)
  private String username;
  </code></pre>