I am using openjpa runtime of JPA specification.
At development time I am using annotations to configure jpa entities.
At Integration, Pre-Production and and Production environment, I am using orm mapping files to configure entities. Please suggest a tool which can generate mapping files from jpa annotations, so that these mapping files can be manually edited for different environment.
If there is already a opensource maven-plugin; will be great.
I don't really know OpenJPA so there is maybe a better way to do this but one option would be to first generate the XML schema file from annotated entities using the Schema Tool and then the orm.xml file from the schema.xml using the Reverse Mapping Tool. Actually, this process is discussed in this thread.
I've checked the OpenJPA Maven Plugin but it doesn't seem to support the Reverse Mapping part (it only has a openjpa:schema goal that allows to Create a file which contains the schema mapping XML, the first required operation, but nothing for the second part). Extending the plugin to add the missing openjpa:reverse-mapping goal would thus require some development but it shouldn't be an hard task.
There is another option though. OpenJPA provides the following Ant tasks for both operations:
org.apache.openjpa.jdbc.ant.ReverseMappingToolTask
org.apache.openjpa.jdbc.ant.SchemaToolTask
So it should be possible to call them from Maven using the Maven AntRun Plugin. Check the documentation for more details on how to use them.
Related
I have been using hyperjaxb tool to generate JPA entities and database scripts from XSD schemas. Now I want basically the inverse operation. How can I generate XSD schemas based on JPA anotated entities or database? I am using Maven, so any maven solution would be preferable.
If you're using IntelliJ IDEA, see the following link:
https://www.jetbrains.com/idea/help/generate-xml-schema-from-java-using-jaxb-dialog.html
This maven plugin ( jaxb2-maven-plugin ) might be useful for you.
This post has more information about its usage and the given example uses POJO's to do the transformation
Generate XSD from Java class
I am using jaxb to autogenerate java classes from an xsd file. I will need to persist the data that will be stored in the objects that will be instantiated from the classes. Is there some way that the hibernate code can be autogenerated in the same classes that are autogenerated by JAXB?
I will need to regenerate the classes many times in the course of development. If I have to write the hibernate code by hand, the only reasonable method I can imagine is to write separate classes with hibernate for persistence, and to write connector classes that migrate the autogenerated classes into the persistence classes. Otherwise, my hand-written hibernate code would be over-written every time I re-run jaxb based on fine tuning of the xsd file. If hibernate code were also autogenerated, I could end up using a lot fewer classes.
Hyperjaxb3 is the way to go. It is a JAXB plugin that you include in the build process. When you run your xsd file through xjc, you will not only get xml-related annotations on the generated classes, you will also get JPA annotations. Without writing hardly any code, you will be able to take an XML document, persist it to a database, query the document from the database and get XML text back out. The generated code can be customized either in the xsd file or in an associated binding file (just like with vanilla xjc). We also utilize hbm2ddl on the produced classes to configure hibernate.
We have been actively using this on several schemas for the past couple of years.
As you edit your XML schema/bindings (and thus your DB schema), you will have to manually write a SQL migration script to upgrade any existing databases. It seems like most DBMS have a schema comparison tool that can be leveraged here. We automatically compare the freshly created schema to the migrated (from a baseline) schema on every build.
I have an existing database. I need to generate the model classes in Java from it. Are there any tool/library that will allow me to do this. It will be of great help if it can emulate the entity relationships in the database into the model classes as well.
It is acceptable if the tool/library works with only one database vendor. I will create a database there and then generate the model.
Thanks in advance.
EDIT : I will probably use Hibernate as the ORM framework if I manage to generate the model.
The Hibernate Tools project (available as an Eclipse plug-in, as well as an Ant task) allows for "reverse-engineering" of database schemas into appropriate entity classes.
This project is also available in the JBoss Tools project.
The facility allows for reverse-engineering of the database metadata into a Hibernate configuration file. All artifacts (including the .java files) are generated from this config file.
You can control the nature of the reverse engineering process to suit your database structure. In other words, you can specify the schemas that you wish to have the tool reverse-engineer. You could also override the JDBC type mapping, apart from limiting the reverse-engineering process to a selected set of tables.
Obligatory link:
Screencast on Reverse engineering and code generation
Telosys does exactly this job
Let's have a look : http://www.telosys.org/
Minuteproject 4 JPA2 (http://minuteproject.wikispaces.com/JPA2) track does this task.
Minuteproject can be run from console or command line.
You can have a quick result by generating from the console where generate a maven project containing the JPA2 mapping classes in java or groovy.
If you use the command line then you need to fill an xml file that can contain additional customisation of your generated code such as packaging, enum, aliasing etc...
You can also try other track built on top JPA2 such as DAO with spring or EJB; REST; front end with Primefaces or Openxava; etc...
Hibernate has an Eclipse plugin Hibernate Tools http://www.hibernate.org/subprojects/tools.html that has reverse engineering capabilities.
See: http://docs.jboss.org/tools/3.2.0.GA/en/hibernatetools/html/plugins.html#refeng_codegen for more details on how to run and customize the reverse engineering process.
I am trying to configure hibernate search for my application by reading several web tutorials, the majority uses annotation but I uses xml mapping, also, many tutorial are saying to use spring and maven while I don't uses these.
Can someone help and provide some starting point for configuring hibernate search, many web tutorial are not working for me
The application is a gwt application using gilead with hibernate on the back end
As pointed out in the previous answer, Hibernate Search does not have a xml configuration. You can configure Hibernate via xml, but not Search. Since Hibernate Search 3.3 there is an alternative, however, which is the programmatic configuration api - http://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#hsearch-mapping-programmaticapi
There is an object called SearchMapping. Once instantiated it offers an fluent API to configure Search the same way you would do with annotations. Add the configured SearchMapping instance to your Hibernate Configuration instance using the key *hibernate.search.model_mapping* and Search will automatically bootstrap together with Hibernate Core. There is not much to it. You don't need Spring.
Once Search is running you probably want to write a few lines of code to index your existing database. There is code for that in the online manual.
Last, but not least you need some searches. Have a look how to create a FulltextQuery. Your system probably gets some sort of search input in what for so ever. Your task is to transform the search input from the "frontend" into a Lucene query which you can then pass to Search in order to execute the search and return managed objects.
Last, but not least - maven is a completely different thing. Now we are talking build systems. Using maven you can get automatically download the artifacts from the JBoss Maven repository. However, there are also dist bundles on SourceForge is this is more what you are after. Check http://www.hibernate.org/subprojects/search/download for Search download information.
Hope this helps.
http://docs.jboss.org/hibernate/search/3.3/reference/en-US/html_single/#d0e43
Hibernate Search, however, has itself its own set of annotations (#Indexed, #DocumentId, #Field,...) for which there exists so far no alternative configuration.
I also remember seeing something like this in "Hibernate Search in Action", where the author said that there's not much demand for non-annotation configuration (I don't have my copy now, so, I may be wrong). I guess that there is still not enough demand.
Note that Hibernate itself can be configured via XML, and I assume that you can mix both (XML for Hibernate mappings, annotations for Hibernate Search mappings).
In eclipse, the "default implementation library" what jars files do I need to include if I do not want to use server runtime?
I'm refering to this tutorial http://help.eclipse.org/help33/index.jsp?topic=/org.eclipse.jpt.doc.user/task_create_new_project.htm
Follow Using TopLink JPA with Dali to get started with the Toplink Essentials (JPA reference implementation). To get the mentioned jars (toplink-essentials.jar and toplink-essentials-agent.jar), download them from there or, if you use Maven, from the Java.Net Maven Repository.
PS: Please note that after 2.0-b36, the toplink-essentials-agent.jar file is no longer needed as the agent facility is now integrated into toplink-essentials.jar. So you can do like below.
$ java -javaagent:toplink-essentials.jar client.Client
Depends on what implementation you want to use. There are currently three most popular implementations: Hibernate, TopLink and EclipseLink.
I know about hibernate that it's README file explains what jars are mandatory for what functions. If you use JPA you must have some sort of EntityManager (hibernate can be used without EntityManager too), so you need all the dependencies of it.
To download hibernate JPA implementation use this link (look for hibernate-entitymanager). You need hibernate core, annotations and entity manager for JPA. If you use all the jars in those three packages you should be ok. But I strongly suggest you to read the README files.