You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jason Pyeron <jp...@pdinc.us> on 2011/07/18 03:34:29 UTC

Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

What is the perfered way to convert JPA2 annotated entities to an XML mapping
file?

We are using openjpa 2.1.

-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.



RE: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

Posted by Jason Pyeron <jp...@pdinc.us>.
> -----Original Message-----
> From: Michael Dick [mailto:michael.d.dick@gmail.com] 
> Sent: Monday, July 18, 2011 10:16
> To: users@openjpa.apache.org
> Subject: Re: Perfered way to convert JPA2 annotations to a 
> persistence.xml based mapping file?
> 
> If the tables have already been created you can use OpenJPA's 
> reverse mapping 
> tool<http://openjpa.apache.org/builds/latest/docs/manual/manua
> l.html#ref_guide_pc_reverse>.
> It will recreate the .java files for you in addition to the 
> XML mapping file. There's no need to use the generated .java 
> files though.

Rather the Entities have already been made, using annotations and now it is
needed in XML.

> 
> If you don't have the tables created, you could use the 
> OpenJPA forward mapping tool 
> <http://openjpa.apache.org/builds/latest/docs/manual/manual.ht
> ml#ref_guide_mapping_mappingtool>to
> create the temporary database. Then use the reverse mapping 
> tool to create the XML file.
> 
> I'm not aware of a tool that writes the XML mapping files 
> without going to a database, but this should at least get you started.

Unfortuanatly, it is not the issue at hand. So I will continue by hand.

> 
> On Sun, Jul 17, 2011 at 8:34 PM, Jason Pyeron 
> <jp...@pdinc.us> wrote:
> 
> > What is the perfered way to convert JPA2 annotated entities 
> to an XML 
> > mapping file?
> >
> > We are using openjpa 2.1.
> >


--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-                                                               -
- 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.

 


Re: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

Posted by Michael Dick <mi...@gmail.com>.
If the tables have already been created you can use OpenJPA's reverse
mapping tool<http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_pc_reverse>.
It will recreate the .java files for you in addition to the XML mapping
file. There's no need to use the generated .java files though.

If you don't have the tables created, you could use the OpenJPA forward
mapping tool
<http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_mappingtool>to
create the temporary database. Then use the reverse mapping tool to create
the XML file.

I'm not aware of a tool that writes the XML mapping files without going to a
database, but this should at least get you started.

-mike

On Sun, Jul 17, 2011 at 8:34 PM, Jason Pyeron <jp...@pdinc.us> wrote:

> What is the perfered way to convert JPA2 annotated entities to an XML
> mapping
> file?
>
> We are using openjpa 2.1.
>
> -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.
>
>
>

RE: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

Posted by Pinaki Poddar <pp...@apache.org>.
> How does one thank you? It worked perfectly. 
You already did. Have fun with OpenJPA.

-----
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-tp6593170p6596372.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

RE: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

Posted by Jason Pyeron <jp...@pdinc.us>.

> -----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.

 


Re: Perfered way to convert JPA2 annotations to a persistence.xml based mapping file?

Posted by Pinaki Poddar <pp...@apache.org>.
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.