How to use “size” as a field name in a hibernate/jpa entity?

后端 未结 2 855
暗喜
暗喜 2021-01-23 00:17

I have two JPA entities : VirtualLot and VirtualFiles. VirtualFiles extends VirtualInode. There is a ManyToMany relation betw

相关标签:
2条回答
  • 2021-01-23 00:51

    size is a reserved keyword like default or for in Java. Therefore either change your name for your variable in perhabs nodeSize or use the @Column(name = "nodeSize") Annotation with the name attribute to give a basic column a special name.

    0 讨论(0)
  • 2021-01-23 01:04

    I'm not sure about this solution, but have a try:

    Just change your @Query using the following:

    @Query(value = "select sum(f.size) from VirtualLot l join l.files f where l.id = ?1", nativeQuery = true)
    

    The nativeQuery parameter is supposed to change your query into a Oracle native query.

    See this stackoverflow topic and the links provided there as reference.

    Hope this will fix your problem.

    0 讨论(0)
提交回复
热议问题