Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7C92E7E93 for ; Mon, 18 Jul 2011 20:20:45 +0000 (UTC) Received: (qmail 26082 invoked by uid 500); 18 Jul 2011 20:20:45 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 26016 invoked by uid 500); 18 Jul 2011 20:20:44 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 26006 invoked by uid 99); 18 Jul 2011 20:20:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jul 2011 20:20:44 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [67.90.184.26] (HELO mail.pdinc.us) (67.90.184.26) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 Jul 2011 20:20:36 +0000 Received: from black (c-68-49-204-238.hsd1.md.comcast.net [68.49.204.238]) (authenticated bits=0) by mail.pdinc.us (8.12.11.20060308/8.12.11) with ESMTP id p6IKKjWW023203 for ; Mon, 18 Jul 2011 16:20:46 -0400 From: "Jason Pyeron" To: References: <02EE19614393412387758A4103F4481E@black> <1311015281545-6595927.post@n2.nabble.com> Subject: RE: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file? Date: Mon, 18 Jul 2011 16:22:24 -0400 Organization: PD Inc Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: AcxFfEkBhLX0k2+CQUSmhiBPO3yDDwACs06w X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4862 In-Reply-To: <1311015281545-6595927.post@n2.nabble.com> X-Virus-Checked: Checked by ClamAV on apache.org > -----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.