由于在hibernate 3中不推荐使用buildSessionFactory方法,我们必须通过ServiceRegistry创建会话工厂。我已经创建了它,如下所示,
Configuration configuration = new Configuration().configure();
Map<String, String> map = new HashMap<String, String>((Map)configuration
.getProperties());
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(map)
.buildServiceRegistry();
但它向我显示了如下所示的 pmd 错误,
Multiple markers at this line
- Type safety: The expression of type Map needs unchecked conversion to conform to Map<? extends String,? extends
String>
- Map is a raw type. References to generic type Map<K,V> should be parameterized
我应该如何避免它?这是因为 (Map)configuration.getProperties() 中的演员,对吗?
为什么我不能在那里使用泛型,例如,
(Map<String,String>)configuration.getProperties()
上面也是初始化服务注册表的正确方法,因为 applySettings() 方法将 Map 作为参数?