jpa - How to use @Where in Hibernate -
searched few hours, i'm stuck in learning curve playframework jpa. i'm building sample website posts can made. these posts can have states:
- postdraft (post draft, not publish)
- postpublished (post can published)
these states stored in seperate table. obviously, draft state posts should not visible yet.
so have these classes:
- page class (getting page information table, 1 page can have multiple posts)
- posts class (posts can in draft , published)
in page class have:
@column(name="posts_ref") @where(clause="postpublished") private list<posts> userposts;
but not working! so, how can specifify clause, load posts in published state without using jpql??
thanks!
update: 2011-10-11
table: posts columns: - id - title - state_ref (reference id of states table) - content
table: states columns: - id - statename
so want like:
select * posts inner join states on posts.state_ref = states.id states.statename = 'postpublished'
update 2011-10-13
this current modification, in page class: not work either.
/** link states */ @joincolumn(name = "states_ref") @onetoone @where(clause = "states.statename = 'postpublished'") public mystate state;
update 2012-02-13 emt's answer worked me after all.
try like:
@column(name="posts_ref") @where(clause="state='postpublished'") private list<posts> userposts;
or
@column(name="posts_ref") @where(clause="postpublished=true") private list<posts> userposts;
depending on status field type on post
entity.
Comments
Post a Comment