java - Service abstraction springMVC -
i'm trying create abstract service in springmvc application. data flows* perfect through layers, persistence (abstraction), not find way save/delete/update database, these classes:
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>{ }
i got 500 status error , tocatlog shows following message:
severe: servlet.service() servlet [tavalendodispatcherservlet] in context path [/tavalendo] threw exception [request processing failed; nested exception org.springframework.beans.notreadablepropertyexception: invalid property 'id' of bean class [java.util.linkedhashmap]: not find field property during fallback access!] root cause org.springframework.beans.notreadablepropertyexception: invalid property 'id' of bean class [java.util.linkedhashmap]: not find field property during fallback access! @ org.springframework.data.util.directfieldaccessfallbackbeanwrapper.getpropertyvalue(directfieldaccessfallbackbeanwrapper.java:56) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:956) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:423) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1079) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:625) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:316) @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1145) @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:615) @ org.apache.tomcat.util.threads.taskthread$wrappingrunnable.run(taskthread.java:61) @ java.lang.thread.run(thread.java:745)
does can explain happend?
it seems spring cannot find id field of medicine:
invalid property 'id' of bean class [java.util.linkedhashmap]: not find field property during fallback access!]
actually, medicine not seem have id
field, need add it.
Comments
Post a Comment