Hibernate EJB IllegalArgument
I have this mysterious hibernate ql exception. It involves three classes:
package com.systemspecs.Entity;
import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
/**
*
* @
* @author-Admin
*/
@Entity
@Table(name = "echequeupload")
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
public class EchequeUpload implements Serializable {
private Long id;
private String bank_acronym = "";
private String accountHolderId = "";
private String accountNumber = "";
private Double trasanctionAmount = 0.0;
private String shortDesc = "";
private String longDesc = "";
private String filePath = "";
private Long batchNo = new Long(System.currentTimeMillis());
private Date transactionDate = new Date();
private String status = "OK";
private String idNumber = "";
private String surname = "";
private String firstname = "";
private String othernames = "";
private String switch_id = "";
private String accountType = "";
private String payPeriod = "";
private String company_id = "";
private String mobile = "";
private String email = "";
private String uploadType = "";
private String processed = "OK";
private Account account = null;
private String variance = null;
private String rejected = "N";
private Double grossAmount = 0.0;
private Double withholdingTax = 0.0;
private String taxOffice = "";
private Double whtRate = 0.0;
private String taxFlag = "OK";
private String bankBranch;
private String taxState;
private String bankName;
private Long dividendId;
private String customerNumber="";
/** Creates a new instance of PensionSalary */
public EchequeUpload() {
}
public EchequeUpload(String bank_acronym, String accountNumber, String accountType, Double trasanctionAmount,
String shortDesc, String longDesc, String surname, String mobile, String email, Double whtRate, String taxOffice,
Long batchNo, String company_id, Long dividendId,String customerNumber) {
this.bank_acronym = bank_acronym;
this.accountNumber = accountNumber;
this.accountType = accountType;
this.trasanctionAmount = trasanctionAmount;
this.shortDesc = shortDesc;
this.longDesc = longDesc;
this.surname = surname;
this.mobile = mobile;
this.email = email;
this.whtRate = whtRate;
this.taxOffice = taxOffice;
this.batchNo = batchNo;
this.company_id = company_id;
this.dividendId=dividendId;
this.customerNumber=customerNumber;
}
public EchequeUpload(String bank_acronym, String accountNumber, String accountType, Double trasanctionAmount,
String shortDesc, String longDesc, String surname, String mobile, String email, Double whtRate, String taxOffice,
Long batchNo, String company_id, Long dividendId) {
this.bank_acronym = bank_acronym;
this.accountNumber = accountNumber;
this.accountType = accountType;
this.trasanctionAmount = trasanctionAmount;
this.shortDesc = shortDesc;
this.longDesc = longDesc;
this.surname = surname;
this.mobile = mobile;
this.email = email;
this.whtRate = whtRate;
this.taxOffice = taxOffice;
this.batchNo = batchNo;
this.company_id = company_id;
this.dividendId=dividendId;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getBank_acronym() {
return bank_acronym;
}
public void setBank_acronym(String bank_acronym) {
if (bank_acronym != null) {
this.bank_acronym = bank_acronym.trim();
}
}
public String getAccountHolderId() {
return accountHolderId;
}
public void setAccountHolderId(String accountHolderId) {
if (accountHolderId != null) {
this.accountHolderId = accountHolderId.trim();
}
}
public Double getTrasanctionAmount() {
return trasanctionAmount;
}
public void setTrasanctionAmount(Double trasanctionAmount) {
if (trasanctionAmount != null)
this.trasanctionAmount = trasanctionAmount;
}
public String getShortDesc() {
return shortDesc;
}
public void setShortDesc(String shortDesc) {
if (shortDesc != null) {
this.shortDesc = shortDesc.trim();
}
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
if (accountNumber != null) {
this.accountNumber = accountNumber.trim();
}
}
public String getLongDesc() {
return longDesc;
}
public void setLongDesc(String longDesc) {
if (longDesc != null) {
this.longDesc = longDesc.trim();
}
}
public String getFilePath() {
return filePath;
}
public void setFilePath(String filePath) {
if (filePath != null) {
this.filePath = filePath.trim();
}
}
public Date getTransactionDate() {
return transactionDate;
}
public void setTransactionDate(Date transactionDate) {
this.transactionDate = transactionDate;
}
public Long getBatchNo() {
return batchNo;
}
public void setBatchNo(Long batchNo) {
this.batchNo = batchNo;
}
public String getStatus() {
return status;
}
public String getCustomerNumber() {
return customerNumber;
}
public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}
public void setStatus(String status) {
if (status != null) {
this.status = status.trim();
}
}
public String getAccountType() {
return accountType;
}
public void setAccountType(String accountType) {
if (accountType != null) {
this.accountType = accountType.trim();
}
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
if (email != null) {
this.email = email.trim();
}
}
public String getCompany_id() {
return company_id;
}
public void setCompany_id(String company_id) {
if (company_id != null) {
this.company_id = company_id.trim();
}
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
if (firstname != null) {
this.firstname = firstname.trim();
}
}
public String getIdNumber() {
return idNumber;
}
public void setIdNumber(String idNumber) {
if (idNumber != null) {
this.idNumber = idNumber.trim();
}
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
开发者_如何学运维 if (mobile != null) {
this.mobile = mobile.trim();
}
}
public String getPayPeriod() {
return payPeriod;
}
public void setPayPeriod(String payPeriod) {
if (payPeriod != null) {
this.payPeriod = payPeriod.trim();
}
}
public String getProcessed() {
return processed;
}
public void setProcessed(String processed) {
if (processed != null) {
this.processed = processed.trim();
}
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
if (surname != null) {
this.surname = surname.trim();
}
}
public String getSwitch_id() {
return switch_id;
}
public void setSwitch_id(String switch_id) {
if (switch_id != null) {
this.switch_id = switch_id.trim();
}
}
public String getUploadType() {
return uploadType;
}
public void setUploadType(String uploadType) {
if (uploadType != null) {
this.uploadType = uploadType.trim();
}
}
public String getOthernames() {
return othernames;
}
public void setOthernames(String othernames) {
if (othernames != null) {
this.othernames = othernames.trim();
}
}
@ManyToOne
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
@Column
public String getVariance() {
return variance;
}
public void setVariance(String variance) {
this.variance = variance;
}
@Column
public String getRejected() {
return rejected;
}
public void setRejected(String rejected) {
this.rejected = rejected;
}
public Double getGrossAmount() {
return grossAmount;
}
public void setGrossAmount(Double grossAmount) {
if (grossAmount != null) {
this.grossAmount = grossAmount;
}
}
public String getTaxOffice() {
return taxOffice;
}
public void setTaxOffice(String taxOffice) {
this.taxOffice = taxOffice;
}
public Double getWithholdingTax() {
return withholdingTax;
}
public void setWithholdingTax(Double withholdingTax) {
if (withholdingTax != null) {
this.withholdingTax = withholdingTax;
}
}
public Double getWhtRate() {
return whtRate;
}
public void setWhtRate(Double whtRate) {
if (whtRate != null) {
this.whtRate = whtRate;
}
}
@Column(length = 4)
public String getTaxFlag() {
return taxFlag;
}
public void setTaxFlag(String taxFlag) {
if (taxFlag != null) {
this.taxFlag = taxFlag;
}
}
/**
* @return the bankBranch
*/
public String getBankBranch() {
return bankBranch;
}
/**
* @param bankBranch the bankBranch to set
*/
public void setBankBranch(String bankBranch) {
this.bankBranch = bankBranch;
}
/**
* @return the taxState
*/
public String getTaxState() {
return taxState;
}
/**
* @param taxState the taxState to set
*/
public void setTaxState(String taxState) {
this.taxState = taxState;
}
/**
* @return the bankName
*/
public String getBankName() {
return bankName;
}
/**
* @param bankName the bankName to set
*/
public void setBankName(String bankName) {
this.bankName = bankName;
}
/**
* @return the dividendId
*/
public Long getDividendId() {
return dividendId;
}
/**
* @param dividendId the dividendId to set
*/
public void setDividendId(Long dividendId) {
this.dividendId = dividendId;
}
}
The other two classes are NOT related. I join the two unrelated classes CustomerLimits and DividendUpload via a common field customerNumber
:
public List<EchequeUpload> findUploadedAllByTransactionIDAndCustomerNumber(
Long transaction_id) {
String ql = "select new EchequeUpload(c.account.switch.switchId, c.account.accountnumber, c.account.accountType, nvl(d.amount,0), ";
ql += "d.shortDescription, d.longDescription, c.accountHolder.name, c.accountHolder.mobile, c.accountHolder.email, nvl(d.tax,0), d.taxState, ";
ql += "d.batchNo, d.company_id, d.id,d.customerNumber) from DividendUpload d , CustomerLimits c where d.customerNumber=c.customerNumber and d.transaction_id=?1";
return this.entityManager.createQuery(ql).setParameter(1,
transaction_id).setHint("org.hibernate.cacheable",
new Boolean(true)).setHint("org.hibernate.readOnly",
new Boolean(true)).getResultList();
}
Now the problem is that it keeps giving me this error. The IllegalArgumentException would naturally indicate that my constructor is not correct but it is. In fact it's very correct, so I'm at a loss here.
2011-02-25 15:37:34,968 ERROR [org.hibernate.hql.PARSER] Unable to locate appropriate constructor on class [com.systemspecs.Entity.EchequeUpload]
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: com.systemspecs.Entity.EchequeUpload]
2011-02-25 15:37:35,015 INFO [STDOUT] In error================================:
2011-02-25 15:37:35,015 ERROR [STDERR] java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Unable to locate appropriate constructor on class [com.systemspecs.Entity.EchequeUpload] [select new EchequeUpload(c.account.switch.switchId, c.account.accountnumber, c.account.accountType, nvl(d.amount,0), d.shortDescription, d.longDescription, c.accountHolder.name, c.accountHolder.mobile, c.accountHolder.email, nvl(d.tax,0), d.taxState, d.batchNo, d.company_id, d.id,d.customerNumber) from com.systemspecs.Entity.DividendUpload d , com.systemspecs.Entity.CustomerLimits c where d.customerNumber=c.customerNumber and d.transaction_id=?1]
2011-02-25 15:37:35,031 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:616)
2011-02-25 15:37:35,031 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:95)
2011-02-25 15:37:35,046 ERROR [STDERR] at org.jboss.ejb3.entity.TransactionScopedEntityManager.createQuery(TransactionScopedEntityManager.java:134)
2011-02-25 15:37:35,046 ERROR [STDERR] at com.systemspecs.dao.EchequeUploadDAO.findUploadedAllByTransactionIDAndCustomerNumber(EchequeUploadDAO.java:103)
2011-02-25 15:37:35,046 ERROR [STDERR] at com.systemspecs.businessobjects.EchequeUploadService2.saveEchequeUpload(EchequeUploadService2.java:705)
2011-02-25 15:37:35,046 ERROR [STDERR] at com.systemspecs.businessobjects.EchequeUploadService2$$FastClassByCGLIB$$c253fe58.invoke(<generated>)
2011-02-25 15:37:35,046 ERROR [STDERR] at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
2011-02-25 15:37:35,046 ERROR [STDERR] at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
I'd say - drop that huge constructor from the query. You don't have compile-time safety in the query, so you'd have to verify manually each argument's type, and the correct order, etc - it's a maintenance hell.
Instead, select the entities from which you are getting the fields and construct the object in pure Java. Preferably use a Builder, rather than a constructor with so many parameters - that's a "code smell"
your 2 constructors each take 15 arguments (!!!!!!!!!!!!!! HEAD EXPLODES!!!!!!!!!!!!!!!!)
in your hql constructor you are passing 14.
the exception means what it means. Something aint write with the constructors you have and the constructor you think you have....also, as a comment points out it is also very possible some of the types are incorrect.
精彩评论