Hi Jason,
  Try the following to get a XML mapping output out of the annotated
classes:

  public void testOutput() throws Exception {
        Class[] classes = {Book.class, Audit.class}; // the persistent classes 
        
        // Cast a generic EntityManagerFactory to OpenJPA-specifc
configuration
        OpenJPAConfiguration conf =
OpenJPAPersistence.cast(_emf).getConfiguration();

        // Cast it again to get a JDBC specific configuration
        JDBCConfiguration jconf = (JDBCConfiguration)conf;

        // Initailize the serialization utility         
        XMLPersistenceMappingSerializer serializer = new
XMLPersistenceMappingSerializer(jconf);

        // Access the repository of meta data
        MetaDataRepository repos = conf.getMetaDataRepositoryInstance();
        
       // Ensure that the repository loads all the metadata
        for (Class<?> cls : classes) {
                repos.getMetaData(cls, null, true);
        }
        
        // Supply the serializer the loaded repository 
        serializer.addAll(repos);
                
        // Write it out on the cosole (or a file)
        Writer writer = new PrintWriter(System.out, true);
        serializer.serialize(writer, MetaDataModes.MODE_ALL);
        writer.close();
}


-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: 
http://openjpa.208410.n2.nabble.com/Perfered-way-to-convert-JPA2-annotations-to-a-persistence-xml-based-mapping-file-tp6593170p6595927.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to