java – Hibernate @Formula不包含Schema

weixin_38052602 2019-09-12 02:01:15
我有一个带有@Formula属性的实体,如下所示: @Entity @Table(name = "areasAuxiliar") public final class AreaAuxiliar implements Serializable { @Id @Column(name = "idArea") private Integer idArea; @Formula("RUTAAREA(idArea)") private String ruta; 当我配置我的hibernate指向Oracle DB我没有问题,但是,当我切换到SQLServer时,hibernate不包括shema并且查询失败, 为hibernate生成的查询如下所示: select areaauxili4_.idArea as idArea1_6_4_, rutaArea(areaauxili4_.idArea) as formula2_4_ from SIGAP.areasAuxiliar areaauxili4_ param hibernate.default_schema =正在读取SIGAP并将其包含在表中但不包含在函数中, 是否有一个选项/注释来强制shema进入该函数? 我尝试过hibernate 5.1和5.2,结果相同:(
...全文
57 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38067813 2019-09-12
  • 打赏
  • 举报
回复
您可以使用mysql-orm.xml文件覆盖您的公式,然后在数据库为mysql时将您的构建配置为对文件进行考虑. 在这里覆盖公式: <entity-mappings xmlns="http://xmlns.jcp.org/xml/ns/persistence/orm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence/orm orm_2_1.xsd" version="2.1"> <package>com.acme.persistence</package> <entity class="AreaAuxiliar" access="FIELD"> <attributes> <property name="ruta" formula="schemaName.RUTAAREA(idarea)"/> </attributes> </entity> </entity-mappings> 然后在特定的persistence.xml中添加引用.然后,在构建中或运行时使用这个覆盖默认的persistence.xml(参见下面的链接). <persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd" version="2.1"> <persistence-unit name="persistenceUnit"> <provider> org.hibernate.jpa.HibernatePersistenceProvider </provider> <mapping-file> mappings/identifier/global/mysql-orm.xml </mapping-file> <class> com.acme.persistence.AreaAuxiliar </class> </persistence-unit> 注意:重重的灵感来自How to change Hibernate GenerationType identifier depending on the underlying database 注意(2):在blog post和here中,作者在运行时生成PersistenceUnitInfo.

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧