我通过读取项目外部的属性文件来创建会话工厂。我的属性文件如下,
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.username=root
hibernate.connection.password=root
hibernate.connection.url=jdbc:mysql://localhost:3306/hi5
hibernate.dialect=org.hibernate.dialect.MySQLDialect
entity=CmtFreeformpages,CmtNewsTicker
我通过如下读取属性文件来创建 Sessionfactory,
properties.load(new FileReader(new File(global.constants.GlobalConstants.parentDirectory + File.separator + global.constants.GlobalConstants.propertiesFile)));
Configuration configuration = new Configuration().setProperties(properties);
Set<Object> setOfProperties = properties.keySet();
for(Object propertyObject : setOfProperties){
if (propertyObject != null) {
String propName = propertyObject.toString();
if(propName.equalsIgnoreCase("entity")){
String value = properties.getProperty(propName);
Object[] entities = value.split(",");
for(int i=0;i<entities.length;i++){
configuration.addAnnotatedClass(entities[i]);
}
sessionFactory = configuration.buildSessionFactory();
但是 configuration.addAnnotatedClass 方法不接受字符串。那么如何将带注释的类添加到配置中?
谢谢