Hibernate version: 3.3.1
Code:
@Entity
public class Book extends BaseModel {
@NotNull
private String title;
private String description;
@OneToMany(mappedBy = "book", cascade = CascadeType.ALL)
private List<Chapter> chapters;
@CollectionOfElements
@JoinTable(name = "book_user", joinColumns = @JoinColumn(name = "book_id"))
private List<BookUser> bookUsers;
// getters and setters
}
Code:
@Entity
public class User extends BaseModel {
@NotNull
private String password;
@NotNull
private String firstName;
@NotNull
private String lastName;
@NotNull
private String emailAddress;
// getters and setters
}
Code:
@Embeddable
public class BookUser {
@Parent
private Book book;
@ManyToOne
@JoinColumn(name = "user_id", nullable = false, updatable = false)
private User user;
@ManyToOne
@JoinColumn(name = "role_id", nullable = true)
private Role role;
// getters and setters
}
I'm trying to find all books with a specific User ID. I am running the following query:
Code:
.createQuery("SELECT b from Book b JOIN b.bookUsers u where u.user.id=:userId")
I am getting the following exception:
Quote:
Caused by: org.hibernate.QueryException: could not resolve property: user.id of: com.publishgeek.dataAccess.model.Book [SELECT b from com.publishgeek.dataAccess.model.Book b left JOIN b.bookUsers u where u.user.id=:userId]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:44)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1362)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:279)
at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:386)
at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:566)
at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:241)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:188)
I'm using HSQLDB 1.8.0
Quote:
2008-11-23 22:38:30,959 QueryTranslatorImpl.java 266 DEBUG --- HQL AST ---
\-[QUERY] 'query'
+-[SELECT_FROM] 'SELECT_FROM'
| +-[FROM] 'from'
| | +-[RANGE] 'RANGE'
| | | +-[DOT] '.'
| | | | +-[DOT] '.'
| | | | | +-[DOT] '.'
| | | | | | +-[DOT] '.'
| | | | | | | +-[IDENT] 'com'
| | | | | | | \-[IDENT] 'publishgeek'
| | | | | | \-[IDENT] 'dataAccess'
| | | | | \-[IDENT] 'model'
| | | | \-[IDENT] 'Book'
| | | \-[ALIAS] 'b'
| | \-[JOIN] 'JOIN'
| | +-[LEFT] 'left'
| | +-[DOT] '.'
| | | +-[IDENT] 'b'
| | | \-[IDENT] 'bookUsers'
| | \-[ALIAS] 'u'
| \-[SELECT] 'SELECT'
| \-[IDENT] 'b'
\-[WHERE] 'where'
\-[EQ] '='
+-[DOT] '.'
| +-[DOT] '.'
| | +-[IDENT] 'u'
| | \-[IDENT] 'user'
| \-[IDENT] 'id'
\-[COLON] ':'
\-[IDENT] 'userId'
2008-11-23 22:38:30,959 ErrorCounter.java 68 DEBUG throwQueryException() : no errors
Thanks for any tips