当使用没有存储库的注释时,有一种方法可以外部化查询?
@Entity
@Table(name = "MY_TABLE", schema = "MY_SCHEMA")
@NamedNativeQueries({ @NamedNativeQuery(name = "myNamed1", query = "{ ? = call my.function(:a,:b,:c) }", hints = { @javax.persistence.QueryHint(name = "org.hibernate.callable", value = "true") }, resultSetMapping = "entityMapping"),
...
@SqlResultSetMappings({ //
@SqlResultSetMapping(name = "entityMapping", entities = { @EntityResult(entityClass = MyEntity.class) }), //
@SqlResultSetMapping(name = "beanMapping", classes = { @ConstructorResult(targetClass = AppBean.class, columns = { @ColumnResult(name = "field_1", type = String.class), @ColumnResult(name = "field_2", type = Long.class) }) }),
})
@NamedQuery(name = "MyEntity.findAll", query = "SELECT v FROM VProposteAppPlanet v")
public class MyEntity implements Serializable {
...
...
我称之为:
Query procedure = getEntityManager().createNamedQuery("myNamed1");
procedure.setParameter("a", a);
procedure.setParameter("b", b);
procedure.setParameter("c", c);
MyEntity ent= (MyEntity ) procedure.getSingleResult();
我会写{ =在jpa-named-queries.properties中调用my.function(:a,:b,:c)}。
我已经在仓库中使用jpa-named-queries.properties作为方法,但是没有上面使用的显式sqlMapping。
谢谢