Question

In my case I have a SQL query which looks like:

select * from event_instance where (object_id, object_type) in 
    (<LIST OF TUPLES RETRIEVED FROM SUBQUERY>);

I want to map this on Hibernate Entities and I have a problem with this query. My mapping looks like that:

     @Entity
     @Table(name="event_instance")
     public class AuditEvent {
         <OTHER_FIELDS>

         @Column( name = "object_type", nullable = false)
         private String objectType;

         @Column( name ="object_id" , nullable = false)
         private Integer objectId;
     }

and second entity:

    @Entity
    @Table(schema = "els" ,name = "acg_objects")
    public class AcgObject implements Serializable{

        @Id
        @Column(name = "acg_id")
        private String acgId;

        @Id
        @Column(name="object_type")
        private String objectType;

        @Id
        @Column(name="object_id")
        private Integer objectId;

        <OTHER FIELDS>

}

I already run query for getting AcgObjects and for my DAO I'm getting List only thing I want to do is query a touple using criteria like:

      crit.add(Restrictions.in("objectType,objectId",<List of tuples>);

Is it possible? I was trying to use @Embedded object but don't know how exactly construct a query for it. Please help

Was it helpful?

Solution

You can do that not in standard SQL nor using criteria; you have to split in two distinct restrictions or using a Session.SQLQuery() if you want to use specific RDBMS (look at SQL WHERE.. IN clause multiple columns for an explanation)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top