Hi I have a namedquery defined as below but when I execute it it retunrns me the whole object rather than just the fields that I have requested. Is there something that I am missing when I only want to return just a column of that object. Thanks in advance

@NamedQueries ({
@NamedQuery(
          name="findSubmissionForSubmissionRowUniqueBankId",
          query="SELECT o.submission FROM SubmissionRow o WHERE     o.uniqueBankId = :uniqueBankId",
          hints={@QueryHint(name=QueryHints.CACHE_USAGE, value=CacheUsage.CheckCacheThenDatabase),
                 @QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="1000"),
                 @QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_EXPIRY, value="18000")
          })

})

The sql that it excecutes for this query is

EJBQueryImpl(ReadObjectQuery(name="findSubmissionForSubmissionRowUniqueBankId" referenceClass=SubmissionRow sql="SELECT ID, ARCHIVE_BANK_ID, EXTERNAL_SOURCE_DETAILS,UNIQUE_BANK_ID, SUBMISSION_ID FROM FE_TEST.SUBMISSION_ROW WHERE (UNIQUE_BANK_ID = ?)"))

I have defined the join as folllows

@ManyToOne
@JoinColumn(name = "SUBMISSION_ID", referencedColumnName = "ID")
private Submission submission;
有帮助吗?

解决方案

Your hints do not make sense,

@QueryHint(name=QueryHints.CACHE_USAGE, value=CacheUsage.CheckCacheThenDatabase),
@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_SIZE, value="1000"),
@QueryHint(name=QueryHints.QUERY_RESULTS_CACHE_EXPIRY, value="18000")

You seem to think you are using query caching, but are not. CACHE_USAGE does not enable query caching, but in-memory querying (searches the entire cache for the object).

To enable the query cache use, QueryHints.QUERY_RESULTS_CACHE = true.

Remove CACHE_USAGE. CACHE_USAGE in-memory querying is only supported with the whole objects, it does not support selecting parts. If you want to use in-memory querying, just query the whole object, and then access the part you want.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top