java - Where should define Entity model class in spring boot -
i wore java based app , used spring boot
this model :
@entity @table(name = "task_list") public class task implements serializable
and config class spring boot uses start :
@configuration @enableautoconfiguration @enablejparepositories @enabletransactionmanagement @componentscan(basepackages = {"controller", "dao", "service"}) class config { @bean(name = "datasource") public datasource datasource() { embeddeddatabasebuilder builder = new embeddeddatabasebuilder(); return builder.settype(embeddeddatabasetype.hsql).build(); } @bean(name = "entitymanager") public localcontainerentitymanagerfactorybean entitymanagerfactory() { hibernatejpavendoradapter vendoradapter = new hibernatejpavendoradapter(); vendoradapter.setdatabase(database.hsql); vendoradapter.setgenerateddl(true); localcontainerentitymanagerfactorybean factory = new localcontainerentitymanagerfactorybean(); factory.setjpavendoradapter(vendoradapter); factory.setpackagestoscan(getclass().getpackage().getname()); factory.setdatasource(datasource()); return factory; } @bean public platformtransactionmanager transactionmanager() { return new jpatransactionmanager(); }
and application :
@springbootapplication() public class application { public static void main(string[] args) { springapplication.run(config.class); } }
so when run application works , creates bean when want interact database , hibernate got error
org.hibernate.mappingexception: unknown entity: model.task
i think because of there not persistence.xml mapping model class,
so should in spring boot app ? should put xml? there annotation tells spring boot map model classes ?
thanks in advance .
thanks xtreme biker , solve problem
i add model package in localcontainerentitymanagerfactorybean
.
@bean(name = "entitymanager") public localcontainerentitymanagerfactorybean entitymanagerfactory() { hibernatejpavendoradapter vendoradapter = new hibernatejpavendoradapter(); vendoradapter.setdatabase(database.hsql); vendoradapter.setgenerateddl(true); localcontainerentitymanagerfactorybean factory = new localcontainerentitymanagerfactorybean(); factory.setjpavendoradapter(vendoradapter); factory.setpackagestoscan("model"); factory.setdatasource(datasource()); return factory; }
Comments
Post a Comment