How to create a separate hibernation request

I browsed the website and cannot find a clear answer to this question.

I have two tables A and B. B is a child of A. I need to get a list of individual attributes from B based on some restrictions of A.

For instance:

SQL:

select distinct sirm.attribute
from store_item_received_material sirm
where sirm.store_item_id in (select si.id from store_item si where si.program_id = 9 and si.customer_id = 1 and si.date_processed is not null);

Of course, SQL works fine.

Now I need to run this in my project.

I start sleep mode 3.3.1. I tried the following:

@NamedNativeQueries ({
    @NamedNativeQuery (name = "select.distinct.sirm.for.customer.program", query = "select distinct(sirm.attribute) as attribute from store_item_received_material as sirm where sirm.store_item_id in (select si.id from store_item as si where si.customer_id = ? and si.program_id = ? and si.date_processed is not null)")
})

But this failed with the following error:

Nested exception - org.hibernate.cfg.NotYetImplementedException: pure native scalar queries are not yet supported

So, I tried the following:

@NamedNativeQueries ({
    @NamedNativeQuery (name = "select.distinct.sirm.for.customer.program", query = "select distinct(sirm.attribute) as attribute from store_item_received_material as sirm where sirm.store_item_id in (select si.id from store_item as si where si.customer_id = ? and si.program_id = ? and si.date_processed is not null)", resultClass=StoreItemReceivedMaterial.class)
})
@SqlResultSetMapping(name = "select.distinct.sirm.for.customer.program", entities=@EntityResult(entityClass = StoreItemReceivedMaterial.class))

But this does not work, because the object is an entity object and does not have an identifier column.

So any help on how to do this

+3
source share
1

@ColumnResult:

@NamedNativeQueries ({
    @NamedNativeQuery (name = "select.distinct.sirm.for.customer.program",
        query = "select distinct(sirm.attribute) as attribute from store_item_received_material as sirm where sirm.store_item_id in (select si.id from store_item as si where si.customer_id = ? and si.program_id = ? and si.date_processed is not null)", resultSetMapping = "select.distinct.sirm.for.customer.program" }) 

@SqlResultSetMapping(name = "select.distinct.sirm.for.customer.program",
    columns = @ColumnResult(name = "attribute"))
0

Source: https://habr.com/ru/post/1792139/


All Articles