问题描述
目的是根据环境服务器向我的应用程序提供两种不同版本的实体。
因此,我创建了Entity1.hbm.xml和Entity2.hbm.xml,并在hibernate.cfg.xml中将<mapping resource="fr/myproject/config/pojos/Entity1.hbm.xml"/>
加载到与application.properties文件中编写的密钥相关的地方。
我也使用Java代码中的配置:
public class HibernateUtil {
private static final SessionFactory sessionFactory = buildSessionFactory();
public HibernateUtil() {
}
private static SessionFactory buildSessionFactory() {
try {
// Create the SessionFactory from hibernate.cfg.xml
return new AnnotationConfiguration().configure()
.buildSessionFactory();
} catch (Throwable ex) {
System.err.println("Initial SessionFactory creation Failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
但是我在处理过程中遇到了问题。在Tomcat上启动应用程序之前,使用实体上的新属性或更新属性更新hbm.xml文件时,除非重新编译并重建我的应用程序,否则它将无法正常工作。
在对xml之类的配置文件进行更改时,我们是否需要重新编译/重建应用程序?我以为xml文件与构建无关,我们可以随时进行修改。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)