I have multi module project like below
I have configured hibernate in DbUtils project with configuration file as below
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "com.test.dbutils.pojos" });
Now I want to use this session factory in both sub modules and I want to setPackagesToScan
Project wise. ie for Doctor Module com.test.doctor.pojos
and for Patient module com.test.patient.pojos
Q.1) How to achieve this?
Q.2) Is there any other better approach creating and using session factory in multi modules?
If you are on Hibernate4+ then you may want to go thru http://docs.jboss.org/hibernate/orm/4.2/devguide/en-US/html/ch16.html
Otherwise, to my knowledge, you have to let JVM know about set packagesToScan at compile time. If you are running Doctor and Patient as separate SpringBoot applications or so[but still leveraging upon common code in DBUtils] then you have option to pass the packages as String via some application.properties file and set the right POJO package in the child module.
If you have both Doctor and Patient running in the same application, you can atleast try to pass multiple packages [sessionFactory.setPackagesToScan(new String[] { "com.test.doctor.pojos", "com.test.patient.pojos" });]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.