简体   繁体   中英

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(
    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

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

MarketingInfo @Entity also has some @Forumlas which is Not mentioned in @EntityResult.

Whereas query.getResultList() is throwing following exception.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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