0

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;
user1107753
  • 1,566
  • 4
  • 24
  • 36
  • 2
    I understand that `o.submission` is a bean and not a primitive/String/Date, is that right? In that case, you will get the `Submission` object, as requested (later you can get the id from its attributes). Maybe you can try `o.submission.id`, if that is what you want. – SJuan76 May 07 '13 at 10:42
  • Yes submission is a bean however even if i try to get a non bean property it still returns the whole submissionrow object and not just that porperty – user1107753 May 07 '13 at 11:22
  • Have you tried `SELECT o.submission.theProperty ...`? – SJuan76 May 07 '13 at 11:36
  • Offhand, what about `SELECT s FROM SubmissionRow o JOIN o.submission s WHERE ...` – Charlie May 07 '13 at 12:26

1 Answers1

1

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.

James
  • 17,965
  • 11
  • 91
  • 146