I do not know if this is a bug or whether it should work this way, but I have the following issue:
I have Entity classes which define my Business Logic.
To do stuff I have created Manager classes which are more or less the same as Stateless beans (For legacy reasons we need to use Tomcat, so no true EE stuff).
In one of the Manager classes I want to use a native query which returns scalar types.
So I created a @SqlResultSetMapping annotation for the manager and created the code to execute the native query.
However when I try to execute the code it complains that no @SqlResultSetMapping exists with the given name.
See snippet below:
Code:
@SqlResultSetMappings( {
@SqlResultSetMapping( name = "StockInfo", columns = { @ColumnResult( name = "product_id" ), @ColumnResult( name = "product_value" ), @ColumnResult( name = "product_name" ),
@ColumnResult( name = "vendor_id" ), @ColumnResult( name = "totalminimumstock" ), @ColumnResult( name = "qtyonhand" ), } ) })
public class StockManager
I then moved the @SqlResultSetMappings to one of the @Entity annotated classes (pure randon because it has no real meaning for the Entity) and suddenly the code works.
Code:
@Entity
@SqlResultSetMappings( {
@SqlResultSetMapping( name = "ProductProposalStockInfo", columns = { @ColumnResult( name = "product_id" ), @ColumnResult( name = "product_value" ), @ColumnResult( name = "product_name" ),
@ColumnResult( name = "vendor_id" ), @ColumnResult( name = "totalminimumstock" ), @ColumnResult( name = "totalQtyOnHand" ), } ) })
public class Address
So it seams that the @SqlResultSetMappings annotation is only detected by Hibernate when in combination with an @Entity annotation. Is this a correct conclusion?
Shouldn't the detection also look for this @SqlResultSetMapping(s) annotation separately form the @Entity annotation when parsing the class files?
Is there another way to use the @SqlResultSetMappings annotation without putting it in a unrelated @Entity class. I think this is strange because you want to keep that definition in a logical place where it is also used and currently I am unable to do that.
Thanks for your thoughts on this