I looked around for answers on this and it looks like it's something to do with reflections but since I haven't dealt with them I'm not sure how to proceed. I'm trying to build a HQL query that returns only rows from a table that match a column that is a FK to a PK in another table.
Here's what my code looks like:
Entity Book:
@Entity
@Table(name="book")
public class Book {
@Id
private String bookNumber;
private String bookName;
private String bookDescription;
private double bookPrice;
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="shelfnumber")
Shelf shelf;
Entity Shelf:
@Entity
@Table(name="shelf")
public class Shelf {
@Id
private String shelfNumber;
@OneToMany(mappedBy="shelf",cascade=CascadeType.ALL)
Set<Book> shelfBooks;
Note: both entity classes have getters/setters
ActionClass:
DynaActionForm searchForm =((DynaActionForm)form);
String shelfNum = searchForm.getString("shelfNum");
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
try{
session.getEntityMode();
Query query = session.createQuery("FROM Book B WHERE B.shelf = :shelfNum"); //here is where the error happens: B.shelf is the problem but don't know why
query.setParameter("shelfNum", shelfNum);
List books = query.list();
request.setAttribute("books", books);
} finally{
session.close();
}
Error message I'm getting:
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.library.entity.Shelf.shelfNumber
and further down I see:
Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.library.entity.Shelf.shelfNumber to java.lang.String
Thank you for any help!