-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria and search data with specialization class
PostPosted: Fri Jun 22, 2007 10:39 am 
Newbie

Joined: Fri Jun 22, 2007 10:07 am
Posts: 1
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 10:14 pm 
Newbie

Joined: Tue Jun 19, 2007 3:47 am
Posts: 4
Hi,

I am pretty sure that you need to specify at the root of your class hierarchy (ie. at your Person class) that you are using single table inheritence strategy:

@Entity
@Table(name = "tb_person")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@SequenceGenerator(name = "tb_person_id_seq", sequenceName = "tb_person_id_seq")
public class Person {


Please rate if this helped.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.