I am using SpringBoot and JPA. i have couple of textfields
and i am using binder.bindInstanceFields(this);
to bind its values. Below is my code,
POJO Class
@Entity
public class Bunch {
@Id
@GeneratedValue
private Long pickupNumber;
private String materialDesc;
private String invoiceNo;
public Bunch() {
}
public Bunch(String materialDesc, String invoiceNo) {
this.materialDesc = materialDesc;
this.invoiceNo = invoiceNo;
}
//Getters and Setters
}
Binding Logic
public class BunchCreation extends FormLayout{
private static final long serialVersionUID = 1L;
private Bunch bunch;
private BunchCreationRepo repo;
TextField materialDesc = new TextField("material Desc");
TextField invoiceNo = new TextField("invoice No");
Button save = new Button("Save");
Binder<Bunch> binder = new Binder<>(Bunch.class);
public BunchCreation(BunchCreationRepo repo) {
this.repo = repo;
add(materialDesc, invoiceNo, save);
binder.bindInstanceFields(this);
save.addClickListener(e -> save());
}
private void save() {
repo.save(bunch);
}
}
None of the text fields are mapping to properties and also getting below error message.
org.springframework.dao.InvalidDataAccessApiUsageException: Target object must not be null; nested exception is java.lang.IllegalArgumentException: Target object must not be null
at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:373) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:255) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527) ~[spring-orm-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) ~[spring-tx-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) ~[spring-tx-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153) ~[spring-tx-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:144) ~[spring-data-jpa-2.1.10.RELEASE.jar:2.1.10.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.1.9.RELEASE.jar:5.1.9.RELEASE]
..................................
Caused by: java.lang.IllegalArgumentException: Target object must not be null
at org.springframework.util.Assert.notNull(Assert.java:198) ~[spring-core-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.AbstractNestablePropertyAccessor.setWrappedInstance(AbstractNestablePropertyAccessor.java:195) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
at org.springframework.beans.BeanWrapperImpl.setWrappedInstance(BeanWrapperImpl.java:153) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
Can anyone please help.