ERROR: Unknown column 'user0_.id' in 'field list'

I had similar problem though I don't think it would solve your problem. I had to rename the database column to the unknown column name. My error said something along the lines of "Unknown column 'category_id' in field list". The column name in the database was categoryId. When I change it to category_id everything work fine.


Your mapping is indeed incorrect.

@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="id")
private List<Post> posts;

That makes no sense. You're saying that a post refers to user by using the post.id column. That can't be correct, since id if the primary key of post.

It'a also incorrect because you want a bidirectional OneToMany association, and the one-side must thus be the inverse side of the association.

Here's the correct mapping:

@OneToMany(mappedBy="user", cascade={CascadeType.ALL})
private List<Post> posts;

and in Post:

@ManyToOne
@JoinColumn(name="userId", nullable=false)
private User user;