Hi,
I'm using two class, example Person and Client, Client class extends Person. I want do a search at the class Client, but the parameter that I want uses how the filter is inside Person client, at this moment the Hibernate returns any error that is cannot possible search the parameter (parameter name inside the class Person, for example.).
org.hibernate.PropertyAccessException: could not get a field value by reflection getter of com.model.Person.name
How can I do to use the parameters of super class how parameters of search? The table is the same table for the classes.
Look my classes:
@Entity
@Table(name = "tb_person")
@SequenceGenerator(name = "tb_person_id_seq", sequenceName = "tb_person_id_seq")
public class Person {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "tb_person_id_seq")
private Long id;
@Basic
@Column(name = "name")
private String name;
.
.
.//Gets and sets
}
@Entity
@Table(name="tb_person")
class Client extends Person {
@Basic
@Column(name="good")
private boolean goodClient;
}
The DAO criteria methody:
public List<Client> getClients() {
List<Client> clients = null;
try {
Criteria criteria = session.createCriteria(Client.class);
criteria.setCacheable(true);
criteria.addOrder(Order.asc("name"));
criteria.add(Restrictions.eq("name", "some name"));
clients = (List<Client>) criteria.list();
} catch(Exception e) {
e.printStackTrace();
}
return clients;
}
When I remove the line "criteria.add(Restrictions.eq("name", "some name"));" the Hibernate return all the clients registred at database, I can normaly get the attributes of Client class and the attributes of the super class Person.
|