プロジェクトごとに外部にあるプロパティファイルを読み込んでセッションファクトリを作成しています。私のプロパティファイルは次のとおりです。
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 メソッドは文字列を受け入れません。では、注釈付きクラスを構成に追加する方法は?
ありがとう