我想在orm.xml中放入命名本机查询,并将此博客文章作为参考:
虽然我跑的时候有一个
HibernateException:命名查询中的错误:Advertisement.xmlNativeQuery
无法理解为什么它不起作用?
这里是orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<named-native-query name="Advertisement.xmlNativeQuery"
result-class="java.lang.String">
<query>SELECT NATIVE_ID FROM ADVERTISEMENT</query>
</named-native-query>
</entity-mappings>
存储库中的方法调用:
@Repository
public interface AdvertisementRepository extends CrudRepository<Advertisement, Long> {
@Query(nativeQuery = true)
public Set<String> xmlNativeQuery();
...
}
广告类
@Entity
@Table(name = "advertisement")
public class Advertisement {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
Long id;
...
@NotNull
/* The web catalog have Advertisement number */
@Column(name="native_id", length=31)
String nativeId;
...
}