1

when i use this query then always show error why? am using MappedSuperclass in audit class.

@Query("select new  com.brite.domain.CurrencyConversion(ins.id,ins.contractType,ins.symbol,ins.exchange,ins.currency,ap.allocationQty,ap.createdDate,ca.baseCurrency,hd.close) from ActualPortfolio as ap JOIN  Instrument as ins on ins.id=ap.instrument.id JOIN  HistoricalData as hd on hd.instrumentId = ins.id   Join ClientAccount as ca on ca.accountId = ap.clientAccount.accountId  where ap.clientAccount.accountId =:accountId and ap.createdDate = (select MAX(pf.createdDate) as date from ActualPortfolio pf where  ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate) and hd.dateTime = (select to_char(MAX(pf.createdDate), 'YYYY-MM-DD 00:00:00') as date from ActualPortfolio pf where  ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate)")

Pojo class looks

        @Entity
        @EntityListeners(AuditingEntityListener.class)
        public class Transaction extends Audit {    
            private Long Id;     

        }

and audit class is

        @MappedSuperclass
        public class Audit {

            @Column(name = "createdDate", columnDefinition = "TIMESTAMP WITH TIME ZONE")
            @CreatedDate
            @JsonSerialize(using = CustomDateSerializer.class)
            private LocalDateTime createdDate;

        }

Caused by: java.lang.IllegalStateException: Using named parameters for method public abstract java.util.List com.brite.repository.InstrumentRepository.getInstrumentForCurrencyConverstion(java.lang.String,java.time.LocalDateTime) but parameter 'Optional[createdDate]' not found in annotated query 'select new com.brite.domain.CurrencyConversion(ins.id,ins.contractType,ins.symbol,ins.exchange,ins.currency,ap.allocationQty,ap.createdDate,ca.baseCurrency,hd.close) from ActualPortfolio as ap JOIN Instrument as ins on ins.id=ap.instrument.id JOIN HistoricalData as hd on hd.instrumentId = ins.id Join ClientAccount as ca on ca.accountId = ap.clientAccount.accountId where ap.clientAccount.accountId =:accountId and ap.createdDate = (select MAX(pf.createdDate) as date from ActualPortfolio pf where ap.clientAccount.accountId =:accountId andenter code here pf.createdDate =: createdDenter code hereate) and hd.dateTime =enter code here (select to_char(MAX(pf.createdDate), 'YYYY-MM-DD 00:00:00') as date from ActualPortfolio pf where ap.clientAccount.accountId =:accountId and pf.createdDate =: createdDate)'!

6
  • Please post the annotated method signature. Commented Jul 19, 2019 at 9:58
  • Maybe your repository parameter createdDate does not have annotation @Param("createdDate") or parameter name differ from name in hql Commented Jul 19, 2019 at 10:19
  • As mentioned in below answer, you are using optional created date as parameter. Change it to allow the unwrapped date object. But yiu haven't posted your java part of code. So please correct your question for people to help you. Commented Jul 19, 2019 at 10:46
  • You should add repository method signature after @Query Commented Jul 19, 2019 at 12:43
  • You 'd better remove constructions like "from ActualPortfolio as ap JOIN Instrument as ins on ins.id=ap.instrument.id". You can use "from ActualPortfolio ap JOIN ap.instrument ins" or "from ActualPortfolio ap, Instrument ins where ins.id=ap.instrument.id" instead Commented Jul 19, 2019 at 13:28

4 Answers 4

4

thanx, something was wrong with my query. we don't need to put space after colon ':' in query

Sign up to request clarification or add additional context in comments.

Comments

2

It seems to me you are passing Optional Argument to method. That might be causing problems.

Comments

0

verify Method parameter names with Query dynamic parameter names. if both are same it will work.

EX:

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

This problem can occur when the parameter name has a mismatch with the variable name.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.