Hibernate query by example (from Spring 3)

I've made my entity classes `Adress`, `Road` and `County`. A `Road` is in a `County` and an `Adress` in on a `Road`. I would like to list all the `Adresses` in a `County`. Therefore, in my `AdressService` I say: public List AllAdresses(County county) { Adress adress = new Adress(); Road road = new Road(); road.setCounty(county); adress.setRoad(road); Example example = Example.create(adress); return (List) adressDAO.query(Adress.class, example); } In my `AdressDAO` I have query(): public List query(Class c, Example example) { return getSession().createCriteria(c).add(example).setMaxResults(100).list(); } This executes the following query on my database server: select this_.AdressId as AdressId2_0_, this_.Description as Descript3_2_0_, this_.DescriptionShort as Descript4_2_0_, this_.HouseLetter as HouseLetter2_0_, this_.HouseNr as HouseNr2_0_, this_.RoadId as RoadId2_0_ from tblAdress this_ where (this_.HouseNr=0) limit 100 I had expected it to at least include SOME information about my entity `County`, and an inner join with `tblRoad`. `tblRoad` has a primary key `roadId`, so I expected `this_.roadId` to be joined with `tblRoad.roadId`, and I expected `tblRoad.countyId` to be set to the primary key of `County`, that is `countyId`. Why is the query in this example not built correctly when I use my own entity types? If I only use integers and strings, they work fine, but not entities. How do I make joins like this work with my own entities?

以上就是Hibernate query by example (from Spring 3)的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏