gpt4 book ai didi

java - NotReadablePropertyException : Invalid property 'id' of bean class [java. util.LinkedHashMap]

转载 作者:太空宇宙 更新时间:2023-11-04 12:34:18 25 4
gpt4 key购买 nike

我正在尝试在我的 springMVC 应用程序中创建一个抽象服务。我的数据流*完美地穿过我的层,但我的持久性(抽象)无法找到保存/删除/更新我的数据库的方法,这些是类:

abstract class BaseServiceImpl<T, ID extends Serializable>
implements BaseService<T, ID> {

protected abstract BaseRepository<T, ID> getRepository();

private BaseRepository<T, ID> repository;

public BaseServiceImpl(BaseRepository<T, ID> repository){
this.repository = repository;
}

public List<T> findAll(){
return getRepository().findAll();
}

public T find(ID id){
return getRepository().findOne(id);
}

public T save(T persisted){
return this.repository.save(persisted);
}

public void delete(ID id){
getRepository().delete(id);
}

public long count(){
return getRepository().count();
}

public boolean exists(ID id){
return getRepository().exists(id);
}
}

//---

@Service
public class MedicineServiceImpl
extends BaseServiceImpl<Medicine, Integer>
implements MedicineService {

@Autowired
private MedicineRepository repository;

@Autowired
public MedicineServiceImpl(MedicineRepository repository) {
super(repository);
}

@Override
public BaseRepository<Medicine, Integer> getRepository() {
return repository;
}
}

//--

@MappedSuperclass
abstract class BaseDomain {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}
}

//--

@Entity
@Table(name = "medicines")
public class Medicine
extends BaseDomain implements Serializable{

@NotNull
private String name;
private String description;
private String purpose;
@Column(name = "active_principle")
private String activePrinciple;
@Column(name = "therapeutic_class")
private String therapeuticClass;
@Column(name = "ean_code")
private String eanCode;
@Column(name = "ms_code")
private String msCode;
@Column(name = "avisa_warning")
private String anvisaWarning;
@Column(name = "lab_name")
private String labName;
@Column(name = "lab_phone")
private String labPhone;

@NotNull
private String contraindication;

public Medicine() {
}
}

//--

@NoRepositoryBean
public interface BaseRepository<T,ID extends Serializable>
extends Repository<T,ID> {

List<T> findAll();

long count();

void delete(ID id);

T save(T s);

T findOne(ID id);

boolean exists(ID id);

void delete(T deleted);

}

//--

@Repository
public interface MedicineRepository
extends BaseRepository<Medicine, Integer>{

}

我收到 500 状态错误,并且我的 tocatlog 显示以下消息:

SEVERE: Servlet.service() for servlet [TavalendoDispatcherServlet] in context with path [/tavalendo] threw exception [Request processing failed; nested exception is org.springframework.beans.NotReadablePropertyException: Invalid property 'id' of bean class [java.util.LinkedHashMap]: Could not find field for property during fallback access!] with root cause org.springframework.beans.NotReadablePropertyException: Invalid property 'id' of bean class [java.util.LinkedHashMap]: Could not find field for property during fallback access! at org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper.getPropertyValue(DirectFieldAccessFallbackBeanWrapper.java:56) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745)

谁能解释一下发生了什么?

最佳答案

我在 JPA 中使用 Projection 时遇到了同样的问题。

错误代码:

Optional<List<AbcProj>> getData(--);

进行以下更改后解决:

List<AbcProj> getData(--);

关于java - NotReadablePropertyException : Invalid property 'id' of bean class [java. util.LinkedHashMap],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37501016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com