I couldn't find why I am getting this exception. Please help me to find it.
I am using the IBM DB2/AS400 DB engine. I have checked the column names in the database with the names I declared in the java class. They are the same. After this exception, the app is not stopping but it's continued further. somewhere in the app, I am trying to save using the repository (repository.save(dailyErrorVO);) and there it's waiting for a long time and going into some deadlock.
public interface DailyErrorRepository
extends JpaRepository<DailyErrorVO, String>, CrudRepository<DailyErrorVO, String> {
}
#Entity
#Table(name = "T_DAILY_ERROR")
public class DailyErrorVO implements Comparable<DailyErrorVO>, Cloneable, Serializable{
private static final long serialVersionUID = 4917078316183458138L;
private Date EFF_DATE;
private String ERRCODE;
private String ERROR_MESSAGE;
private String EXCEPTION_MESSAGE;
private String EXTRNL_POI;
private String IMPACT_AREA;
#Column(name="LAST_MOD_TIME_DT", nullable = false)
private Timestamp LAST_MOD_TIME_DT;
#Id
#Column(nullable = true)
private String MEMBER_ID;
private String PAY_SEQ;
private String PROG_ID;
#Column(name="PROGRAM", nullable = false)
private String PROGRAM = CommonProperties.PROGRAM_NAME;
#Column(name="RUN_DATE", nullable = false)
private Date RUN_DATE;
private String SQLCODE;
private String SSN;
private String TABLE_NM;
public Date getEFF_DATE() {
return EFF_DATE;
}
public void setEFF_DATE(Date eFF_DATE) {
EFF_DATE = eFF_DATE;
}
public String getERRCODE() {
return ERRCODE;
}
public void setERRCODE(String eRRCODE) {
ERRCODE = eRRCODE;
}
public String getERROR_MESSAGE() {
return ERROR_MESSAGE;
}
public void setERROR_MESSAGE(String eRROR_MESSAGE) {
ERROR_MESSAGE = eRROR_MESSAGE;
}
public String getEXCEPTION_MESSAGE() {
return EXCEPTION_MESSAGE;
}
public void setEXCEPTION_MESSAGE(String eXCEPTION_MESSAGE) {
EXCEPTION_MESSAGE = eXCEPTION_MESSAGE;
}
public String getEXTRNL_POI() {
return EXTRNL_POI;
}
public void setEXTRNL_POI(String eXTRNL_POI) {
EXTRNL_POI = eXTRNL_POI;
}
public String getIMPACT_AREA() {
return IMPACT_AREA;
}
public void setIMPACT_AREA(String iMPACT_AREA) {
IMPACT_AREA = iMPACT_AREA;
}
public Timestamp getLAST_MOD_TIME_DT() {
return LAST_MOD_TIME_DT;
}
public void setLAST_MOD_TIME_DT(Timestamp lAST_MOD_TIME_DT) {
LAST_MOD_TIME_DT = lAST_MOD_TIME_DT;
}
public String getMEMBER_ID() {
return MEMBER_ID;
}
public void setMEMBER_ID(String mEMBER_ID) {
MEMBER_ID = mEMBER_ID;
}
public String getPAY_SEQ() {
return PAY_SEQ;
}
public void setPAY_SEQ(String pAY_SEQ) {
PAY_SEQ = pAY_SEQ;
}
public String getPROG_ID() {
return PROG_ID;
}
public void setPROG_ID(String pROG_ID) {
PROG_ID = pROG_ID;
}
public String getPROGRAM() {
return PROGRAM;
}
public void setPROGRAM(String pROGRAM) {
PROGRAM = pROGRAM;
}
public Date getRUN_DATE() {
return RUN_DATE;
}
public void setRUN_DATE(Date rUN_DATE) {
RUN_DATE = rUN_DATE;
}
public String getSQLCODE() {
return SQLCODE;
}
public void setSQLCODE(String sQLCODE) {
SQLCODE = sQLCODE;
}
public String getSSN() {
return SSN;
}
public void setSSN(String sSN) {
SSN = sSN;
}
public String getTABLE_NM() {
return TABLE_NM;
}
public void setTABLE_NM(String tABLE_NM) {
TABLE_NM = tABLE_NM;
}
#Override
public String toString() {
return "TDailyErrorVO [EFF_DATE=" + EFF_DATE + ", ERRCODE=" + ERRCODE + ", ERROR_MESSAGE=" + ERROR_MESSAGE
+ ", EXCEPTION_MESSAGE=" + EXCEPTION_MESSAGE + ", EXTRNL_POI=" + EXTRNL_POI + ", IMPACT_AREA="
+ IMPACT_AREA + ", LAST_MOD_TIME_DT=" + LAST_MOD_TIME_DT + ", MEMBER_ID=" + MEMBER_ID + ", PAY_SEQ="
+ PAY_SEQ + ", PROG_ID=" + PROG_ID + ", PROGRAM=" + PROGRAM + ", RUN_DATE=" + RUN_DATE + ", SQLCODE="
+ SQLCODE + ", SSN=" + SSN + ", TABLE_NM=" + TABLE_NM + "]";
}
#Override
public int compareTo(DailyErrorVO o) {
return 0;
}
}
com.ibm.as400.access.AS400JDBCSQLSyntaxErrorException: An undefined column name was detected.
at com.ibm.as400.access.JDError.createSQLExceptionSubClass(JDError.java:897) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:421) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.ibm.as400.access.JDError.throwSQLException(JDError.java:397) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.ibm.as400.access.JDServerRow.findField(JDServerRow.java:519) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.ibm.as400.access.AS400JDBCResultSet.findColumn(AS400JDBCResultSet.java:575) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.ibm.as400.access.AS400JDBCResultSet.getString(AS400JDBCResultSet.java:3424) ~[jt400-jdk8-9.5.jar:JTOpen 9.5]
at com.zaxxer.hikari.pool.HikariProxyResultSet.getString(HikariProxyResultSet.java) ~[HikariCP-3.4.5.jar:?]
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.resultSetSchemaName(SequenceInformationExtractorLegacyImpl.java:124) ~[hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.tool.schema.extract.internal.SequenceInformationExtractorLegacyImpl.extractMetadata(SequenceInformationExtractorLegacyImpl.java:53) ~[hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.sequenceInformationList(JdbcEnvironmentImpl.java:403) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentImpl.<init>(JdbcEnvironmentImpl.java:268) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:114) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.id.factory.internal.DefaultIdentifierGeneratorFactory.injectServices(DefaultIdentifierGeneratorFactory.java:152) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.injectDependencies(AbstractServiceRegistryImpl.java:286) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:243) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.<init>(InFlightMetadataCollectorImpl.java:176) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:127) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1224) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1255) [hibernate-core-5.4.25.Final.jar:5.4.25.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:58) [spring-orm-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) [spring-orm-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:391) [spring-orm-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:378) [spring-orm-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) [spring-orm-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1853) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1790) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:324) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$$Lambda$148/0000000000000000.getObject(Unknown Source) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) [spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1109) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) [spring-context-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:405) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) [spring-boot-2.3.7.RELEASE.jar:2.3.7.RELEASE]
at com.benefeds.batch.ABWReversalFileValidationStarter.main(ABWReversalFileValidationStarter.java:9) [classes/:?]
According to the stack trace that you posted, Hibernate is unable to determine the current value of some sequence which happens at boot time. Maybe you configured the wrong dialect or the dialect has a bug. Please share the dialect that you use and the Hibernate version, as well as the exact database name and version. Chances are, you can simply subclass a dialect and fix the bug yourself.
Related
I have some api with content-type: form-data.
Every request have some common field in the body
Here is my code
package com.example.demo.request;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.math.BigDecimal;
public class CreateNhanhProductRequest {
private String nuctk;
private Long storeId;
private String name;
private Integer typeId;
private String parentIdName;
private Long parentId;
private String code;
private String barcode;
private BigDecimal importPrice;
private BigDecimal vat;
private BigDecimal price;
private BigDecimal wholesalePrice;
private BigDecimal oldPrice;
private Integer status;
private Object multiUnitItems;
private Object comboItems;
private Long categoryId;
private Long internalCategoryId;
private Long brandId;
private Double shippingWeight;
private String unit;
private Integer length;
private Integer width;
private Integer height;
private Long countryId;
private Long warrantyAddress;
private String warrantyPhone;
private Long warranty;
private String warrantyContent;
private Integer firstRemain;
private Integer importType;
private Long depotId;
private String supplierName;
private Long supplierId;
private Integer checkcopyImg;
private Integer attributeCombinated;
private String metaTitle;
private String metaDescription;
private Object metaKeywords;
private Object tags;
#JsonProperty("tag-suggest")
private Object tagSuggest;
public String getNuctk() {
return nuctk;
}
public void setNuctk(String nuctk) {
this.nuctk = nuctk;
}
public Long getStoreId() {
return storeId;
}
public void setStoreId(Long storeId) {
this.storeId = storeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getTypeId() {
return typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public String getParentIdName() {
return parentIdName;
}
public void setParentIdName(String parentIdName) {
this.parentIdName = parentIdName;
}
public Long getParentId() {
return parentId;
}
public void setParentId(Long parentId) {
this.parentId = parentId;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getBarcode() {
return barcode;
}
public void setBarcode(String barcode) {
this.barcode = barcode;
}
public BigDecimal getImportPrice() {
return importPrice;
}
public void setImportPrice(BigDecimal importPrice) {
this.importPrice = importPrice;
}
public BigDecimal getVat() {
return vat;
}
public void setVat(BigDecimal vat) {
this.vat = vat;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public BigDecimal getWholesalePrice() {
return wholesalePrice;
}
public void setWholesalePrice(BigDecimal wholesalePrice) {
this.wholesalePrice = wholesalePrice;
}
public BigDecimal getOldPrice() {
return oldPrice;
}
public void setOldPrice(BigDecimal oldPrice) {
this.oldPrice = oldPrice;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Object getMultiUnitItems() {
return multiUnitItems;
}
public void setMultiUnitItems(Object multiUnitItems) {
this.multiUnitItems = multiUnitItems;
}
public Object getComboItems() {
return comboItems;
}
public void setComboItems(Object comboItems) {
this.comboItems = comboItems;
}
public Long getCategoryId() {
return categoryId;
}
public void setCategoryId(Long categoryId) {
this.categoryId = categoryId;
}
public Long getInternalCategoryId() {
return internalCategoryId;
}
public void setInternalCategoryId(Long internalCategoryId) {
this.internalCategoryId = internalCategoryId;
}
public Long getBrandId() {
return brandId;
}
public void setBrandId(Long brandId) {
this.brandId = brandId;
}
public Double getShippingWeight() {
return shippingWeight;
}
public void setShippingWeight(Double shippingWeight) {
this.shippingWeight = shippingWeight;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public Integer getLength() {
return length;
}
public void setLength(Integer length) {
this.length = length;
}
public Integer getWidth() {
return width;
}
public void setWidth(Integer width) {
this.width = width;
}
public Integer getHeight() {
return height;
}
public void setHeight(Integer height) {
this.height = height;
}
public Long getCountryId() {
return countryId;
}
public void setCountryId(Long countryId) {
this.countryId = countryId;
}
public Long getWarrantyAddress() {
return warrantyAddress;
}
public void setWarrantyAddress(Long warrantyAddress) {
this.warrantyAddress = warrantyAddress;
}
public String getWarrantyPhone() {
return warrantyPhone;
}
public void setWarrantyPhone(String warrantyPhone) {
this.warrantyPhone = warrantyPhone;
}
public Long getWarranty() {
return warranty;
}
public void setWarranty(Long warranty) {
this.warranty = warranty;
}
public String getWarrantyContent() {
return warrantyContent;
}
public void setWarrantyContent(String warrantyContent) {
this.warrantyContent = warrantyContent;
}
public Integer getFirstRemain() {
return firstRemain;
}
public void setFirstRemain(Integer firstRemain) {
this.firstRemain = firstRemain;
}
public Integer getImportType() {
return importType;
}
public void setImportType(Integer importType) {
this.importType = importType;
}
public Long getDepotId() {
return depotId;
}
public void setDepotId(Long depotId) {
this.depotId = depotId;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public Long getSupplierId() {
return supplierId;
}
public void setSupplierId(Long supplierId) {
this.supplierId = supplierId;
}
public Integer getCheckcopyImg() {
return checkcopyImg;
}
public void setCheckcopyImg(Integer checkcopyImg) {
this.checkcopyImg = checkcopyImg;
}
public Integer getAttributeCombinated() {
return attributeCombinated;
}
public void setAttributeCombinated(Integer attributeCombinated) {
this.attributeCombinated = attributeCombinated;
}
public String getMetaTitle() {
return metaTitle;
}
public void setMetaTitle(String metaTitle) {
this.metaTitle = metaTitle;
}
public String getMetaDescription() {
return metaDescription;
}
public void setMetaDescription(String metaDescription) {
this.metaDescription = metaDescription;
}
public Object getMetaKeywords() {
return metaKeywords;
}
public void setMetaKeywords(Object metaKeywords) {
this.metaKeywords = metaKeywords;
}
public Object getTags() {
return tags;
}
public void setTags(Object tags) {
this.tags = tags;
}
public Object getTagSuggest() {
return tagSuggest;
}
public void setTagSuggest(Object tagSuggest) {
this.tagSuggest = tagSuggest;
}
#Override
public String toString() {
return "CreateNhanhProductRequest{" +
"nuctk='" + nuctk + '\'' +
", storeId=" + storeId +
", name='" + name + '\'' +
", typeId=" + typeId +
", parentIdName='" + parentIdName + '\'' +
", parentId=" + parentId +
", code='" + code + '\'' +
", barcode='" + barcode + '\'' +
", importPrice=" + importPrice +
", vat=" + vat +
", price=" + price +
", wholesalePrice=" + wholesalePrice +
", oldPrice=" + oldPrice +
", status=" + status +
", multiUnitItems=" + multiUnitItems +
", comboItems=" + comboItems +
", categoryId=" + categoryId +
", internalCategoryId=" + internalCategoryId +
", brandId=" + brandId +
", shippingWeight=" + shippingWeight +
", unit='" + unit + '\'' +
", length=" + length +
", width=" + width +
", height=" + height +
", countryId=" + countryId +
", warrantyAddress=" + warrantyAddress +
", warrantyPhone='" + warrantyPhone + '\'' +
", warranty=" + warranty +
", warrantyContent='" + warrantyContent + '\'' +
", firstRemain=" + firstRemain +
", importType=" + importType +
", depotId=" + depotId +
", supplierName='" + supplierName + '\'' +
", supplierId=" + supplierId +
", checkcopyImg=" + checkcopyImg +
", attributeCombinated=" + attributeCombinated +
", metaTitle='" + metaTitle + '\'' +
", metaDescription='" + metaDescription + '\'' +
", metaKeywords=" + metaKeywords +
", tags=" + tags +
", tagSuggest=" + tagSuggest +
'}';
}
// private Multi imageUpload;
}
I want to Add same nuctk in every request in the body.
But request use the formData i can't convert this to object in interceptor.
My client
package com.example.demo.client;
import com.example.demo.config.NhanhPageFeignClientInterceptor;
import com.example.demo.request.CreateNhanhProductRequest;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
#FeignClient(
value = "nhanhPage",
url = "https://nhanh.vn/product",
configuration = NhanhPageFeignClientInterceptor.class
)
public interface NhanhProductV1Client {
#PostMapping(value = "/item/add", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
String createProduct(#RequestBody CreateNhanhProductRequest request);
}
This is my interceptor
package com.example.demo.config;
import com.example.demo.request.CreateNhanhProductRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import feign.RequestInterceptor;
import feign.form.FormData;
import feign.form.FormEncoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import java.io.IOException;
public class NhanhPageFeignClientInterceptor {
#Bean
public RequestInterceptor requestInterceptor() {
return requestTemplate -> {
String bodyTemplate = requestTemplate.bodyTemplate();
byte[] body = requestTemplate.body();
FormData formData = new FormData(MediaType.MULTIPART_FORM_DATA_VALUE, "data" , body);
requestTemplate.header(HttpHeaders.COOKIE, "Some cookie");
};
}
}
How to change the body in feign client interceptor.
Thank!
I was working on a project but I got this no property type found error.
Please check my code and try to understand what the problem is.
package com.bisoft.staj.poi;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class PoiApplication implements CommandLineRunner {
#Autowired
MesafeRepository mesafeRepository;
public static void main(String[] args) {
SpringApplication.run(PoiApplication.class, args);
}
#Override
public void run(String... strings) throws Exception {
System.out.println("Debug");
FileInputStream file = new FileInputStream(new File("C:/Users/MONSTER/Desktop/Hello.xlsx"));
XSSFWorkbook workbook = new XSSFWorkbook(file);
XSSFSheet sheet = workbook.getSheetAt(0);
Row row;
for (int i = 1; i <= sheet.getLastRowNum(); i++) {
row = (Row) sheet.getRow(i); //sheet number
String kayitNo;
if (row.getCell(0) == null) {
kayitNo = "0";
} else {
kayitNo = row.getCell(0).toString();
}
int cihazNo = 0;
if (row.getCell(1) != null) {
cihazNo = (int) row.getCell(1).getNumericCellValue();
}
String plaka;
if (row.getCell(2) == null) {
plaka = "null";
} else {
plaka = row.getCell(2).toString(); //exceldeki isimleri
}
String surucu;
if (row.getCell(3) == null) {
surucu = "null";
} else {
surucu = row.getCell(3).toString();
}
float ilkMesafeSayaci = 0;
if (row.getCell(4) != null) {
ilkMesafeSayaci = (float)row.getCell(4).getNumericCellValue();
}
String ilkMesafeTarih;
if (row.getCell(5) == null) {
ilkMesafeTarih = "null";
} else {
ilkMesafeTarih = row.getCell(5).toString();
}
float sonMesafeSayaci = 0;
if (row.getCell(6) != null) {
sonMesafeSayaci = (float)row.getCell(6).getNumericCellValue();
}
String sonMesafeTarih;
if (row.getCell(7) == null) {
sonMesafeTarih = "null";
} else {
sonMesafeTarih = row.getCell(7).toString();
}
float toplamMesafe = 0;
if (row.getCell(8) != null) {
toplamMesafe = (float)row.getCell(8).getNumericCellValue();
}
Mesafe c = new Mesafe();
c.setCihazNo(cihazNo);
c.setPlaka(plaka);
c.setSurucu(surucu);
c.setIlkMesafeSayaci(ilkMesafeSayaci);
c.setIlkMesafeTarih(ilkMesafeTarih);
c.setSonMesafeSayaci(sonMesafeSayaci);
c.setSonMesafeTarih(sonMesafeTarih);
c.setToplamMesafe(toplamMesafe);
mesafeRepository.save(c);
System.out.println(cihazNo + " " + plaka + " " + surucu);
}
mesafeRepository.findByName("Berkin").forEach(System.out::println);
file.close();
System.out.println("Completed!");
}
}
Repository
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bisoft.staj.poi;
import java.io.Serializable;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
/**
*
* #author MONSTER
*/
public interface MesafeRepository extends JpaRepository<Mesafe, Long>{
public List<Mesafe> findByName(String name);
}
Class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.bisoft.staj.poi;
import javax.annotation.Generated;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
/**
*
* #author MONSTER
*/
#Entity
public class Mesafe {
#Id
#SequenceGenerator(name = "customersequence", sequenceName = "customersequence", allocationSize = 1)
#GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "customersequence")
private Long kayitNo;
private int cihazNo;
private String plaka;
private String surucu;
private float ilkMesafeSayaci;
private String ilkMesafeTarih;
private float sonMesafeSayaci;
private String SonMesafeTarih;
private float toplamMesafe;
public Long getKayitNo() {
return kayitNo;
}
public void setKayitNo(Long kayitNo) {
this.kayitNo = kayitNo;
}
public int getCihazNo() {
return cihazNo;
}
public void setCihazNo(int cihazNo) {
this.cihazNo = cihazNo;
}
public String getPlaka() {
return plaka;
}
public void setPlaka(String plaka) {
this.plaka = plaka;
}
public String getSurucu() {
return surucu;
}
public void setSurucu(String surucu) {
this.surucu = surucu;
}
public float getIlkMesafeSayaci() {
return ilkMesafeSayaci;
}
public void setIlkMesafeSayaci(float ilkMesafeSayaci) {
this.ilkMesafeSayaci = ilkMesafeSayaci;
}
public String getIlkMesafeTarih() {
return ilkMesafeTarih;
}
public void setIlkMesafeTarih(String ilkMesafeTarih) {
this.ilkMesafeTarih = ilkMesafeTarih;
}
public float getSonMesafeSayaci() {
return sonMesafeSayaci;
}
public void setSonMesafeSayaci(float sonMesafeSayaci) {
this.sonMesafeSayaci = sonMesafeSayaci;
}
public String getSonMesafeTarih() {
return SonMesafeTarih;
}
public void setSonMesafeTarih(String SonMesafeTarih) {
this.SonMesafeTarih = SonMesafeTarih;
}
public float getToplamMesafe() {
return toplamMesafe;
}
public void setToplamMesafe(float toplamMesafe) {
this.toplamMesafe = toplamMesafe;
}
#Override
public String toString() {
return "Mesafe{" + "kayitNo=" + kayitNo + ", cihazNo=" + cihazNo + ", plaka=" + plaka + ", surucu=" + surucu + ", ilkMesafeSayaci=" + ilkMesafeSayaci + ", ilkMesafeTarih=" + ilkMesafeTarih + ", sonMesafeSayaci=" + sonMesafeSayaci + ", SonMesafeTarih=" + SonMesafeTarih + ", toplamMesafe=" + toplamMesafe + '}';
}
}
Error
by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mesafeRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property name found for type Mesafe!
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 18 common frames omitted
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property name found for type Mesafe!
at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:89) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.<init>(PartTreeJpaQuery.java:64) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:103) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:214) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) ~[spring-data-commons-1.13.4.RELEASE.jar:na]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101) ~[spring-data-jpa-1.11.4.RELEASE.jar:na]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.9.RELEASE.jar:4.3.9.RELEASE]
... 28 common frames omitted
my pom.xml and application.properties files are working OK so where can the problem be? Thanks...
I think the problem is in your repo:
public interface MesafeRepository extends JpaRepository<Mesafe, Long>{
public List<Mesafe> findByName(String name);
}
According to method findByName, your entity should have a property name, but there is no such property in Mesafe entity
You can just remove this method from repo, or add corresponding property to the entity
I am developing an ADF web application with Oracle EBS as the backend to call the procedure(Jdeveloper 12 c).
I have invoked a method calling EBS procedure (return type is list) and the result is stored in arraylist. the list is used to create Data control.
What my problem is i have set values to the data control but when i added that dc to view it shows nothing. But on debugging it shows all the values are set in the array list.
Bean class calling EBS procedure in ApplicationModule
BindingContainer bindings = getBindings();
OperationBinding operationBinding = (OperationBinding) bindings.getOperationBinding("getIexpenseLogin");
List<EmployeePojo> result = (List<EmployeePojo>) operationBinding.execute();
System.out.println("Result= " + result);
employeeDC.getEmployeeLogin(result); // Here the list is passed to the Employee DC class to create data controll.
ApplicationModule Containing Custom Procedure
public List getIexpenseLogin(String username,String password){
CallableStatement cs=null;
List<EmployeePojo> empList=new ArrayList<>();
try{
cs=getDBTransaction().createCallableStatement("begin xx_oie_mob_login.oie_mob_login(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?); end;",0);
cs.setString(1,username);
cs.setString(2, password);
cs.registerOutParameter(3, Types.NUMERIC);
cs.registerOutParameter(4, Types.VARCHAR);
cs.registerOutParameter(5, Types.VARCHAR);
cs.registerOutParameter(6, Types.NUMERIC);
cs.registerOutParameter(7, Types.VARCHAR);
cs.registerOutParameter(8, Types.NUMERIC);
cs.registerOutParameter(9, Types.VARCHAR);
cs.registerOutParameter(10, Types.NUMERIC);
cs.registerOutParameter(11, Types.VARCHAR);
cs.registerOutParameter(12, Types.NUMERIC);
cs.registerOutParameter(13, Types.BLOB);
cs.registerOutParameter(14, Types.VARCHAR);
cs.registerOutParameter(15, Types.VARCHAR);
cs.executeUpdate();
if(cs!=null)
{
EmployeePojo ePojo=new EmployeePojo();
ePojo.setEmployeeId(cs.getString(3));
ePojo.setEmployeeName(cs.getString(4));
ePojo.setEmployeeNumber(cs.getString(5));
ePojo.setManagerId(cs.getString(6));
ePojo.setManagerName(cs.getString(7));
ePojo.setJobId(cs.getString(8));
ePojo.setJobName(cs.getString(9));
ePojo.setOrgId(cs.getString(10));
ePojo.setOrgName(cs.getString(11));
ePojo.setImgId(cs.getString(12));
ePojo.setImage(cs.getBlob(13));
empList.add(ePojo);
}
return empList;
}catch(SQLException e){
throw new JboException(e);
}
}
EmployeeDC class used to create Data controll
public class EmployeeDC {
public EmployeeDC() {
super();
}
BindingContainer bindings = null;
private List<EmployeePojo> employee_data_controll=null;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void setEmployee_data_controll(List<EmployeePojo> employee_data_controll) {
List<EmployeePojo> oldEmployee_data_controll = this.employee_data_controll;
this.employee_data_controll = employee_data_controll;
propertyChangeSupport.firePropertyChange("employee_data_controll", oldEmployee_data_controll,
employee_data_controll);
}
public List<EmployeePojo> getEmployee_data_controll() {
return employee_data_controll;
}
public void setPropertyChangeSupport(PropertyChangeSupport propertyChangeSupport) {
PropertyChangeSupport oldPropertyChangeSupport = this.propertyChangeSupport;
this.propertyChangeSupport = propertyChangeSupport;
propertyChangeSupport.firePropertyChange("propertyChangeSupport", oldPropertyChangeSupport,
propertyChangeSupport);
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
public void getEmployeeLogin(List<EmployeePojo> result) {
setEmployee_data_controll(result);
getEmployee_data_controll();
System.out.println("DataControl=>"+getEmployee_data_controll().get(0));
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
}
EmployeePojo Class
public class EmployeePojo {
private String employeeId;
private String employeeName;
private String employeeNumber;
private String managerId;
private String managerName;
private String jobId;
private String jobName;
private String orgId;
private String orgName;
private String imgId;
private Blob image;
private PropertyChangeSupport propertyChangeSupport = new PropertyChangeSupport(this);
public void setPropertyChangeSupport(PropertyChangeSupport propertyChangeSupport) {
this.propertyChangeSupport = propertyChangeSupport;
}
public PropertyChangeSupport getPropertyChangeSupport() {
return propertyChangeSupport;
}
public void setEmployeeId(String employeeId) {
String oldEmployeeId = this.employeeId;
this.employeeId = employeeId;
propertyChangeSupport.firePropertyChange("employeeId", oldEmployeeId, employeeId);
}
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeName(String employeeName) {
String oldEmployeeName = this.employeeName;
this.employeeName = employeeName;
propertyChangeSupport.firePropertyChange("employeeName", oldEmployeeName, employeeName);
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeNumber(String employeeNumber) {
String oldEmployeeNumber = this.employeeNumber;
this.employeeNumber = employeeNumber;
propertyChangeSupport.firePropertyChange("employeeNumber", oldEmployeeNumber, employeeNumber);
}
public String getEmployeeNumber() {
return employeeNumber;
}
public void setManagerId(String managerId) {
String oldManagerId = this.managerId;
this.managerId = managerId;
propertyChangeSupport.firePropertyChange("managerId", oldManagerId, managerId);
}
public String getManagerId() {
return managerId;
}
public void setManagerName(String managerName) {
String oldManagerName = this.managerName;
this.managerName = managerName;
propertyChangeSupport.firePropertyChange("managerName", oldManagerName, managerName);
}
public String getManagerName() {
return managerName;
}
public void setJobId(String jobId) {
String oldJobId = this.jobId;
this.jobId = jobId;
propertyChangeSupport.firePropertyChange("jobId", oldJobId, jobId);
}
public String getJobId() {
return jobId;
}
public void setJobName(String jobName) {
String oldJobName = this.jobName;
this.jobName = jobName;
propertyChangeSupport.firePropertyChange("jobName", oldJobName, jobName);
}
public String getJobName() {
return jobName;
}
public void setOrgId(String orgId) {
String oldOrgId = this.orgId;
this.orgId = orgId;
propertyChangeSupport.firePropertyChange("orgId", oldOrgId, orgId);
}
public String getOrgId() {
return orgId;
}
public void setOrgName(String orgName) {
String oldOrgName = this.orgName;
this.orgName = orgName;
propertyChangeSupport.firePropertyChange("orgName", oldOrgName, orgName);
}
public String getOrgName() {
return orgName;
}
public void setImgId(String imgId) {
String oldImgId = this.imgId;
this.imgId = imgId;
propertyChangeSupport.firePropertyChange("imgId", oldImgId, imgId);
}
public String getImgId() {
return imgId;
}
public void setImage(Blob image) {
Blob oldImage = this.image;
this.image = image;
propertyChangeSupport.firePropertyChange("image", oldImage, image);
}
public Blob getImage() {
return image;
}
public void addPropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.addPropertyChangeListener(l);
}
public void removePropertyChangeListener(PropertyChangeListener l) {
propertyChangeSupport.removePropertyChangeListener(l);
}
}
This problem is with oracle 10g database. Same code is working fine with MySQL Database.
My Model Class
package com.killerlinks.model;
import java.io.Serializable;
import java.sql.Blob;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
#Entity
#Table(name="links")
public class Linkform implements Serializable
{
/**
*
*/
private static final long serialVersionUID = 1L;
#Id
#GeneratedValue(strategy=GenerationType.AUTO)
#Column(name="id")
private Long id;
#Column(name="tittle")
private String tittle;
#Column(name="xdesc")
private String desc;
#Column(name="url")
private String url;
#Column(name="category")
private String category;
#Column(name="xdate")
private String date;
#Column(name="xtime")
private String time;
#Column(name="tags")
private String tags;
#Column(name="image")
#Lob
private Blob fileData;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTittle() {
return tittle;
}
public void setTittle(String tittle) {
this.tittle = tittle;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getTags() {
return tags;
}
public void setTags(String tags) {
this.tags = tags;
}
#Override
public String toString()
{
return "Linkform [tittle=" + tittle + ", url=" + url + ", category="+ category +", tags="+ tags +", desc="+ desc +", fileData="+fileData+" ]";
}
public Blob getFileData() {
return fileData;
}
public void setFileData(Blob fileData) {
this.fileData = fileData;
}
}
This method from my controller class which helps to keep blob object to model class.
private Linkform preparingModelBean(LinkformBean linkformbean, MultipartFile file)
{
Linkform linkform = new Linkform();
linkform.setTittle(linkformbean.getTittle());
linkform.setUrl(linkformbean.getUrl());
linkform.setCategory(linkformbean.getCategory());
linkform.setDesc(linkformbean.getDesc());
linkform.setTags(linkformbean.getTags());
Date date = new Date();
SimpleDateFormat sdate = new SimpleDateFormat("yyyy.MM.dd");
SimpleDateFormat stime = new SimpleDateFormat("HH:mm");
linkform.setDate(sdate.format(date));
linkform.setTime(stime.format(date));
try {
Blob blob = Hibernate.createBlob(file.getInputStream());
linkform.setFileData(blob);
} catch (IOException e) {
e.printStackTrace();
}
return linkform;
}
This is another method from controller class, where i am trying to read blob object
#RequestMapping(value ="/image/{id}")
public String image(#PathVariable("id")Long id, HttpServletResponse response)
{
Linkform linkform = linkformservice.getALink(id);
try {
response.setHeader("Content-Disposition", "inline;filename=\"" +linkform.getTittle()+ "\"");
OutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
IOUtils.copy(linkform.getFileData().getBinaryStream(), out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
when i am trying to call specific image this is output i am getting
When i trigger the url from the browser http://localhost:7070/KillerLinks/image/381.htm
this is the error displayed in my console
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.sql.BLOB.getDBAccess(BLOB.java:955)
at oracle.sql.BLOB.getBinaryStream(BLOB.java:229)
at org.hibernate.lob.SerializableBlob.getBinaryStream(SerializableBlob.java:39)
at com.killerlinks.controllers.CategoryController.image(CategoryController.java:63)
at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
java.sql.SQLException: Closed Connection
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:208)
at oracle.sql.BLOB.getDBAccess(BLOB.java:955)
at oracle.sql.BLOB.getBinaryStream(BLOB.java:229)
at org.hibernate.lob.SerializableBlob.getBinaryStream(SerializableBlob.java:39)
at com.killerlinks.controllers.CategoryController.image(CategoryController.java:77)
at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:931)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Hibernate: select linkform0_.id as id1_0_, linkform0_.category as category1_0_, linkform0_.xdate as xdate1_0_, linkform0_.xdesc as xdesc1_0_, linkform0_.image as image1_0_, linkform0_.tags as tags1_0_, linkform0_.xtime as xtime1_0_, linkform0_.tittle as tittle1_0_, linkform0_.url as url1_0_, linkform0_.xviews as xviews1_0_ from links linkform0_ where linkform0_.id=?
Please help me to fix the bug.
I want image to be displayed.
Thanks in advance.
I think your controller should look like this:
#RequestMapping(value ="/image/{id}")
public void image(#PathVariable("id")Long id, HttpServletResponse response)
{
Linkform linkform = linkformservice.getALink(id);
try {
response.setContentType("application/x-download");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
OutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
IOUtils.copy(linkform.getFileData().getBinaryStream(), out);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
It will send your file to direct download.
In addition you can add image file to html page
<img src="/image/5"></img>
Try this
#RequestMapping(value ="/image/{id}")
public void image(#PathVariable("id")Long id, HttpServletResponse response)
{
Linkform linkform = linkformservice.getALink(id);
InputStream image = null;
image = linkform.getFileData().getBinaryStream();
try {
OutputStream out = response.getOutputStream();
response.setContentType("image/jpeg");
int length = (int) image.available();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
while ((length = image.read(buffer)) != -1) {
out.write(buffer, 0, length);
}
response.flushBuffer();
//image.close();
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
Is there any other piece of code invoking linkform.getFileData()? If not, do you mind modifying your code a little bit like following.
Entity Class:
#Column(name="image")
#Lob
private Byte[] fileData;
public Byte[] getFileData() {
return fileData;
}
public void setFileData(Byte[] fileData) {
this.fileData = fileData;
}
And also change your controller based on new getFileData().
I cannot guarantee that this solution would definitely solve your probleam, but it is worth giving it a go. The reason I am saying so is that the exception trace tells you code failed on opening an DB connection to load Blob data. And according to java doc, the Interface Blob is actually a logical pointer to underlying SQL Blob rather than holding real data. Since controller is out of hibernate session, it might not be able to open another connection to DB for retrieving Blob value.
I am trying to integrate the JSF with spring and hibernate.
Following is my code:
LeaveBean.java
package com.nagra.bean;
import java.io.Serializable;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import org.hibernate.HibernateException;
import com.nagra.leaveapp.BO.LeaveInfoBo;
import com.nagra.leaveapp.model.LeaveInfo;
#ManagedBean(name="customer")
#SessionScoped
public class LeaveBean implements Serializable{
/**
*
*/
//private LeaveAppDo leaveAppDo=new LeaveAppDo();
LeaveInfoBo leaveinfoBo;
public LeaveInfoBo getLeaveinfoBo() {
return leaveinfoBo;
}
public void setLeaveinfoBo(LeaveInfoBo leaveinfoBo) {
this.leaveinfoBo = leaveinfoBo;
}
private String total_sick_leave;
private String total_paidoff_leave;
private String start_date;
private String end_date;
private String reason;
private String status;
private Date secondDate;
public Date getSecondDate() {
return secondDate;
}
public void setSecondDate(Date secondDate) {
this.secondDate = secondDate;
}
public String getTotal_sick_leave() {
return total_sick_leave;
}
public void setTotal_sick_leave(String total_sick_leave) {
this.total_sick_leave = total_sick_leave;
}
public String getTotal_paidoff_leave() {
return total_paidoff_leave;
}
public void setTotal_paidoff_leave(String total_paidoff_leave) {
this.total_paidoff_leave = total_paidoff_leave;
}
public String getStart_date() {
return start_date;
}
public void setStart_date(String start_date) {
this.start_date = start_date;
}
public String getEnd_date() {
return end_date;
}
public void setEnd_date(String end_date) {
this.end_date = end_date;
}
public String getReason() {
return reason;
}
public void setReason(String reason) {
this.reason = reason;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
private static final long serialVersionUID = 1L;
//resource injection
#Resource(name="jdbc/leaveapp")
//private DataSource ds;
//if resource inject is not support, you still can get it manually.
/*public CustomerBean(){
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("jdbc:mysql://localhost:3306/leaveapp");
} catch (NamingException e) {
e.printStackTrace();
}
}*/
public List<LeaveInfo> getCustomerList() throws SQLException{
System.out.println("Getting In " );
return null;
// return leaveinfoBo.retrieveData();
}
public String addCustomer() throws HibernateException
{
/* String url = "jdbc:mysql://localhost:3306/leaveapp";
Connection con = DriverManager.getConnection(url,"root","root");
System.out.println(con);
if(con==null)
throw new SQLException("Can't get database connection");
String sql="insert into leaveinformation(start_date,end_date,reason,status)values(?,?,?,?)";
java.util.Date utilDate = new Date();
// Convert it to java.sql.Date
java.sql.Date date = new java.sql.Date(utilDate.getTime());
java.sql.Timestamp sqlDate = new java.sql.Timestamp(new java.util.Date().getTime());*/
DateFormat formatter ;
try
{
System.out.println("Start date " + getStart_date());
formatter = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = formatter.parse(LeaveBean.this.getStart_date());
System.out.println(startDate);
Date endDate = formatter.parse(LeaveBean.this.getEnd_date());
// Days d = Days.daysBetween(startDate,endDate);
// int days = d.getDays();
#SuppressWarnings("deprecation")
java.sql.Date startdate=new java.sql.Date(startDate.getDate());
#SuppressWarnings("deprecation")
java.sql.Date enddate=new java.sql.Date(endDate.getDate());
/* System.out.println("Today is " +date );
PreparedStatement ps
= con.prepareStatement(sql);
ps.setDate(1,startdate,Calendar.getInstance(Locale.ENGLISH));
ps.setDate(2,enddate,Calendar.getInstance(Locale.ENGLISH));
ps.setString(3,CustomerBean.this.reason);
ps.setString(4,"Waiting");*/
LeaveInfo leave = new LeaveInfo();
System.out.println("Entering addCustomer() ");
leave.setEnd_date(enddate);
leave.setStart_date(startdate);
leave.setReason(reason);
leave.setStatus("Waiting");
System.out.println(leave.toString());
leaveinfoBo.save(leave);
clearall();
// Insert the row
/* ps.executeUpdate();
con.close();*/
sendmail();
}
catch(Exception e)
{
System.out.println("There is an error " + e.getStackTrace().toString());
e.printStackTrace();
}
return "";
}
private void clearall() {
// TODO Auto-generated method stub
setEnd_date("");
setStart_date("");
setReason("");
setStatus("");
}
public String sendmail()
{
// Recipient's email ID needs to be mentioned.
String to = "nsbharathi88#gmail.com";
// Sender's email ID needs to be mentioned
String from = "web#gmail.com";
// Assuming you are sending email from localhost
String host = "localhost";
// Get system properties
Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", host);
// Get the default Session object.
Session session = Session.getDefaultInstance(properties);
try{
// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress(from));
// Set To: header field of the header.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
// Set Subject: header field
message.setSubject("This is the Subject Line!");
// Now set the actual message
message.setText("This is actual message");
// Send message
Transport.send(message);
System.out.println("Sent message successfully....");
}catch (MessagingException mex) {
mex.printStackTrace();
}
return "";
}
}
applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<!-- Database Configuration -->
<import resource="classes/spring/database/DataSource.xml"/>
<import resource="classes/spring/database/Hibernate.xml"/>
<!-- Beans Declaration -->
<import resource="classes/spring/bean/LeaveApp.xml"/>
</beans>
I am getting the following error when i run this on the tomcat server:
Start date 2012-02-03
java.lang.NullPointerException
at com.nagra.bean.LeaveBean.addCustomer(LeaveBean.java:167)
Fri Feb 03 00:00:00 IST 2012
Entering addCustomer()
LeaveInfo [id=0, total_sick_leave=15, total_paidoff_leave=15, start_date=1970-01- 01, end_date=1970-01-01, reason=cfklsn, status=Waiting]
There is an error [Ljava.lang.StackTraceElement;#fc644a
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.el.parser.AstValue.invoke(AstValue.java:262)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
I think, your startdate and enddate is of type String, Change it to java.util.Date and try
start_date=1970-01- 01
Your start date has a space in it. It wont parse.