//the document is syntactically incorrect
//DOM4J sometimes wraps the SAXParseException wo much interest
final Throwable throwable = e.getCause();
if ( e.getCause() == null || !( throwable instanceof SAXParseException ) ) {
throw new MappingException( "Could not parse JPA mapping document", e );
}
errors.add( (SAXParseException) throwable );
}
boolean isV1Schema = false;
if ( errors.size() != 0 ) {
SAXParseException exception = errors.get( 0 );
final String errorMessage = exception.getMessage();
//does the error look like a schema mismatch?
isV1Schema = doc != null
&& errorMessage.contains("1.0")
&& errorMessage.contains("2.0")
&& errorMessage.contains("version");
}
if (isV1Schema) {
//reparse with v1
errors.clear();
setValidationFor( saxReader, "orm_1_0.xsd" );
try {
//too bad we have to reparse to validate again :(
saxReader.read( new StringReader( doc.asXML() ) );
}
catch ( DocumentException e ) {
//oops asXML fails even if the core doc parses initially
throw new AssertionFailure("Error in DOM4J leads to a bug in Hibernate", e);
}
}
if ( errors.size() != 0 ) {
//report errors in exception
StringBuilder errorMessage = new StringBuilder( );
for (SAXParseException error : errors) {
errorMessage.append("Error parsing XML (line")
.append(error.getLineNumber())
.append(" : column ")
.append(error.getColumnNumber())
.append("): ")
.append(error.getMessage())
.append("\n");
}
throw new MappingException( "Invalid ORM mapping file.\n" + errorMessage.toString() );
}
add( doc );
return this;
}
finally {