> -----Original Message----- > From: Pinaki Poddar > Sent: Monday, July 18, 2011 14:55 > To: users@openjpa.apache.org > Subject: Re: Perfered way to convert JPA2 annotations to a > persistence.xml based mapping file? > > 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(); > }
How does one thank you? It worked perfectly. -Jason -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron PD Inc. http://www.pdinc.us - - Principal Consultant 10 West 24th Street #100 - - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is copyright PD Inc, subject to license 20080407P00.