Hibernate Criteria API - adding a criterion: string should be in collection

后端 未结 7 1747
北恋
北恋 2020-12-16 06:05

I have to following entity object


@Entity
public class Foobar {
    ...
    private List uuids;
    ...
}

Now I\'d like to

7条回答
  •  太阳男子
    2020-12-16 06:09

    The solution with the sqlRestriction from jira http://opensource.atlassian.com/projects/hibernate/browse/HHH-869 seemed the best way to go for me since i heavily use criteria api. I had to edit Thierry's code so it worked in my case

    Model:

    @Entity
    public class PlatformData
    {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long iID;
    
      private List iPlatformAbilities = new ArrayList();
    }
    

    Criteria call:

    tCriteria.add(Restrictions.sqlRestriction(
            "{alias}.id in (select e.id from platformData e, platformdata_platformabilities v"
              + " where e.id = v.platformdata_id and v.element = ? )", aPlatformAbility.toString(),
            Hibernate.STRING));
    

提交回复
热议问题