1.2.3 Need help with error: org.hibernate.type.SerializationException: could not serialize

2,009 views
Skip to first unread message

Arlo Duff

unread,
Apr 27, 2012, 4:43:49 PM4/27/12
to play-framework
Based on advice I've gotten here, I'm trying to implement a Play app
which lets the users follow other users by storing each relation in
the MySQL database. This is the code I'm using:

@Entity
public class followerRelation extends Model {

public User follower;
public User followee;

public followerRelation(Long followerId, Long followeeId) {
this.follower = User.findById(followerId);
this.followee = User.findById(followeeId);
}

public followerRelation(User follower, User followee) {
this.follower = follower;
this.followee = followee;
}

}

When a user chooses to follow another user, the code creates a new
followerRelation object and invokes its save() function.

But for some reason, trying to search the MySQL database is giving me
a "could not serialize" error. For example, code like this triggers
the error:

followerRelation friendship = followerRelation.find("select f from
followerRelation f where f.follower = ?1 and f.followee = ?2",
follower, followee).first();

where follower and followee are both User objects.

This is all that's going on. I've cleared the MySQL database and
started Play fresh, and it's giving me this error, without ever having
added any data to the followerRelation table. Does anyone know how to
handle this? I have no idea what to do when Play starts giving me
Hibernate errors.

unkx80

unread,
Apr 27, 2012, 5:37:29 PM4/27/12
to play-fr...@googlegroups.com
I didn't check your query, but I think your followerRelation class needs the following:

1. @ManyToOne annotation on the follower and followee fields.

@ManyToOne public User follower;
@ManyToOne public User followee;

2. Default constructor.

public followerRelation() {
}

Don't ask me why though, I don't really know these things really work, although I strongly suspect reflection magic behind the scenes.

Regards,
Yee Fan

Arlo Duff

unread,
Apr 27, 2012, 5:49:18 PM4/27/12
to play-framework
You were right, the ManyToOne relation did it. Thanks!
Reply all
Reply to author
Forward
0 new messages