Search in sources :

Example 1 with Persistence

use of org.hibernate.jpamodelgen.xml.jaxb.Persistence in project hibernate-orm by hibernate.

the class JpaDescriptorParser method getPersistence.

private Persistence getPersistence() {
    Persistence persistence = null;
    String persistenceXmlLocation = context.getPersistenceXmlLocation();
    InputStream stream = xmlParserHelper.getInputStreamForResource(persistenceXmlLocation);
    if (stream == null) {
        return null;
    }
    try {
        Schema schema = xmlParserHelper.getSchema(PERSISTENCE_SCHEMA);
        persistence = xmlParserHelper.getJaxbRoot(stream, Persistence.class, schema);
    } catch (XmlParsingException e) {
        context.logMessage(Diagnostic.Kind.WARNING, "Unable to parse persistence.xml: " + e.getMessage());
    }
    try {
        stream.close();
    } catch (IOException e) {
    // eat it
    }
    return persistence;
}
Also used : Persistence(org.hibernate.jpamodelgen.xml.jaxb.Persistence) ObjectInputStream(java.io.ObjectInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) XmlParsingException(org.hibernate.jpamodelgen.util.xml.XmlParsingException) Schema(javax.xml.validation.Schema) IOException(java.io.IOException)

Example 2 with Persistence

use of org.hibernate.jpamodelgen.xml.jaxb.Persistence in project hibernate-orm by hibernate.

the class JpaDescriptorParser method determineMappingFileNames.

private Collection<String> determineMappingFileNames() {
    Collection<String> mappingFileNames = new ArrayList<String>();
    Persistence persistence = getPersistence();
    if (persistence != null) {
        // get mapping file names from persistence.xml
        List<Persistence.PersistenceUnit> persistenceUnits = persistence.getPersistenceUnit();
        for (Persistence.PersistenceUnit unit : persistenceUnits) {
            mappingFileNames.addAll(unit.getMappingFile());
        }
    }
    // /META-INF/orm.xml is implicit
    mappingFileNames.add(DEFAULT_ORM_XML_LOCATION);
    // not really part of the official spec, but the processor allows to specify mapping files directly as
    // command line options
    mappingFileNames.addAll(context.getOrmXmlFiles());
    return mappingFileNames;
}
Also used : Persistence(org.hibernate.jpamodelgen.xml.jaxb.Persistence) ArrayList(java.util.ArrayList)

Aggregations

Persistence (org.hibernate.jpamodelgen.xml.jaxb.Persistence)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 ArrayList (java.util.ArrayList)1 Schema (javax.xml.validation.Schema)1 XmlParsingException (org.hibernate.jpamodelgen.util.xml.XmlParsingException)1