I am using spring framework and hibernate as an ORM tool.
My parent class is like:
@Entity
public class Category {
@Id
@GeneratedValue
@NotNull
private int cid;
private String cname;
@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name = "cid")
List<Ad> ads;
//getter and setter, constructor }
And my child class is like:
@Entity
public class Ad {
private int adid;
private String adName;
//getter and setter, constructor
}
My category controller is :
@Controller
public class CategoryController {
@Autowired
SessionFactory sessionFactory;
Session session;
@Transactional
@RequestMapping(value = "categories",method = RequestMethod.GET)
@ResponseBody
public List<Category> getAllCategory()throws SQLException{
session=sessionFactory.getCurrentSession();
return session.createCriteria(Category.class).list();
}
}
When i hit url localhost:8080/categories .I get json data like:
{"cid":"1",cname":"category","ads":[{"adid":"1","adName":"ad"}]}
Here I am getting datas of both parent and the related child table.But how can I get only datas of parent table.Here in this example, I need data like:
{"cid":"1",cname":"category"}
How can I do this