try {
// Add mapping locations
PropertyValue mappingLocationsProp = properties.getPropertyValue("mappingLocations");
if (mappingLocationsProp != null) {
List<TypedStringValue> mappingLocations = (List<TypedStringValue>) mappingLocationsProp.getValue();
if (mappingLocations != null) {
ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver();
for (TypedStringValue mappingLocation : mappingLocations) {
LOG.info("Found mappingLocation " + mappingLocation.getValue());
Resource[] resources = resourcePatternResolver.getResources(mappingLocation.getValue());
for (int i = 0; i < resources.length; i++) {
LOG.info("Adding resource " + resources[i].getURL());
try {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
// Disable DTD resolution
documentBuilder.setEntityResolver(new EntityResolver() {
@Override
public InputSource resolveEntity(String arg0, String arg1) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
});
Document document = documentBuilder.parse(resources[i].getInputStream());
config.addDocument(document);
} catch (SAXException e) {
throw new DatabaseException("Error reading document " + resources[i].getURL(), e);
}
}
}
}
}
} catch (Exception e) {
if (e instanceof DatabaseException) {
throw (DatabaseException) e;
} else {
throw new DatabaseException(e);
}
}
我正在尝试构建配置并从中构建映射文件。 config.buildMappings();
在 hibernateTestContext.xml 中,我将映射位置定义为:
<property name="mappingLocations">
<list>
<value>classpath*:../WEB-INF/mapping/*/*.hbm.xml</value>
</list>
</property>
我的{hbms E:\*\web\src\main\webapp\WEB-INF\mapping
但我仍然无法扫描hbms
。我也尝试过使用file:../web/src/main/webapp/WEB-INF/mapping/*/*.hbm.xml
但我得到了这个例外:
org.hibernate.InvalidMappingException: Could not parse mapping document from unknown
完整错误:org.hibernate.PropertyNotFoundException: field [testHole] not found on org.test.*.*.synchronization.hole.Hole
阅读和构建hibernate配置文件:
` Configuration config = new Configuration();
// Disable xml validation
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setValidating(false);
// Read configuration
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(registry);
reader.setNamespaceAware(true);
reader.loadBeanDefinitions(new ClassPathResource(connection.getPath()));`