users@glassfish.java.net

Re: Entity reference to another entity creates BLOB column in mysql table..why?

From: <glassfish_at_javadesktop.org>
Date: Fri, 03 Sep 2010 22:53:54 PDT

Basically it's like this:

@Entity
@Table(name="groups")
public class Groups implements Serializable {
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  @Basic(optional = false)
  @Column(name = "id")
  private Long id;

  private String name;

  @JoinColumn(name = "userId", referencedColumnName = "id", updatable = false, insertable = false)
  @OneToMany(cascade = CascadeType.PERSIST)
  private User user;
}


I left out the getter/setter methods for brevity, but that is the gist of it. The User entity is the same sort of deal.. @Id, String name, that is it. Very simple entities.

The annotations I use, I assumed were ok. I have a book, EJB 3 in Action, and from the examples and the sql output that they show, it seems to me that my groups table should basically be an ID column, a VARCHAR for the name, and a long/integer column that contains the ID from the users table... and the join between the groups.userId column tot he users.id column should be fine.

So it does strike me odd that complete bytes of data for each User object are stored in the groups table for each row, in a BLOB column. I can't fathom why that would be done that way short of some form of serialization for speed... but then if you change the actual user in the users table that any number of rows in the groups table references, does it go back and update all those values in the groups table where the user data is? That seems it would crush performance the more rows you have with the same user data in it.
[Message sent by forum member 'andjarnic']

http://forums.java.net/jive/thread.jspa?messageID=481866