简体   繁体   English

带有SqlResultSetMapping的JPA Sql NativeQuery抛出java.sql.SQLException:找不到列'formula3_0_'

[英]JPA Sql NativeQuery with SqlResultSetMapping throwing java.sql.SQLException: Column 'formula3_0_' not found

Following is the snapshot of my @SqlResultSetMapping which includes two entities and two more columns from native query. 以下是我的@SqlResultSetMapping的快照,其中包括两个实体和本机查询中的另外两列。

@SqlResultSetMapping(
    name = "EventLogMarketingInfoMapping",
    entities = {
            @EntityResult(
                    entityClass = MarketingInfo.class,
                    fields = {
                            @FieldResult(name = "id", column = "id"),

                            @FieldResult(name = "remoteAddr", column = "remote_addr"),

                            @FieldResult(name = "user_email", column = "user_email"),

                    }
            ),
            @EntityResult(
                    entityClass = EventLog.class,
                    fields = {
                            @FieldResult(name = "log_id", column = "log_id"),

                            @FieldResult(name = "comment", column = "comment"),

                            @FieldResult(name = "client", column = "client_id"),
                            @FieldResult(name = "game", column = "game_id")
                    }
            )

    },
    columns = {
        @ColumnResult(
            name = "user_namex",
            type = String.class
        ),
        @ColumnResult(
            name = "ip",
            type = String.class
        ),
    })

Above SqlResultSetMapping is called with the following native query 上面的SqlResultSetMapping用以下本机查询调用

   Query query = entityManager.createNativeQuery(sql, "EventLogMarketingInfoMapping");
   return query.getResultList();

MarketingInfo @Entity also has some @Forumlas which is Not mentioned in @EntityResult. MarketingInfo @Entity也有一些@Forumlas,在@EntityResult中未提及。

Whereas query.getResultList() is throwing following exception. 而query.getResultList()引发以下异常。

java.sql.SQLException: Column 'formula3_0_' not found.

Can anyone define what is happening here? 任何人都可以定义这里发生的事情吗? I would also like to add that sql itself is executing fine and has no syntax error or formula column within it. 我还想补充一点,sql本身执行良好,并且其中没有语法错误或公式列。

Thanks in advance. 提前致谢。

Please add the corresponding sql statement which is getting triggered, As per the @EntityResult annotation, the select statement should retrieve all the properties part of the entity and should get mapped. 请添加要触发的相应sql语句。根据@EntityResult批注,select语句应检索实体的所有属性部分并应进行映射。 partial column selection will create the mentioned exception. 选择部分列将创建上述异常。 One alternative would be to use @ConstructorResult which allows partial column retrieval for the parent also for all the associated entity objects. 一种替代方法是使用@ConstructorResult,它允许对父级以及所有关联的实体对象进行部分列检索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM