I'm upgrading an old project from hibernate3 to hibernate5. The project has a dependency on hbm2java (the so-called reverse engineering tool). In the old project this was executed with mvn hibernate3:hbm2java.
Unfortunately, hbm2java is nowhere to be found in Hibernate5 - not in the code, not in the documentation.
What is the Hibernate5 equivalent of the old hbm2java? Or in case it's no longer supported, what's the closest alternative? I'm willing to get out of Hibernate entirely, if that's what it takes to get out of Hibernate 3.
The latest version of the hibernate-maven-plugin is 4.3.1.
You would get out of hibernate 3 by using hibernate 4.3.1 naturally.
It looks like the hbm2java task exists in the sources of the latest hibernate release: https://github.com/hibernate/hibernate-tools/blob/master/main/src/java/org/hibernate/tool/ant/Hbm2JavaExporterTask.java. That is what your were looking for isn't it? So it should also be possible to build the hibernate5 github project in your local maven repo and then bind the dependencies in your projects pom.
At last add the appropriate task and goal in your execution section.
Suggestion#1:
You can use maven ant runner. It may help.
mvn antrun:run#hbm2java
If you have modified templates (see the documentation) then, in pom.xml, modify the hibernate tool tag to look like:
<hibernatetool templatepath="src/the/path/to/the/directory/containing/pojo/directory">
The above path must point to the parent of the directory named pojo, containing your templates.
Also, if you have a custom reverse engineering strategy class the, in pom.xml add this attribute to jdbcconfiguration tag.
reversestrategy="fully.qualified.name.CustomDelegatingReverseEngineeringStrategy"
Resource Link: Hibernate tools reverse engineering using Maven
I haven't checked it but you can try with this procedure using Hibernate 5.X version.
Suggestion#2:
This issue seems critical in Hibernate 5.x version. All recommendation is to use 4.3 version for reverse engineering instead of 5.x
Resource Link: https://stackoverflow.com/a/37577315
Step by step tutorial to use 4.3 instead of 5.1 with pictorial view is given here:
http://o7planning.org/en/10125/using-hibernate-tools-generate-entity-classes-from-tables
Some issues are given below:
Database case-sensitive issue
type mapping
table filtering
no <schema-selection> tag is specified
This issues is required to resolve by hand (it's just basic XML) or you can use the Hibernate plugins, which provides a specialized editor.
http://www.hibernate.org/30.html
For reverse engineering rule, you can go through this tutorial: Chapter 6. Controlling reverse engineering
Related
I'm currently using Eclipse Dali with EclipseLink 2.5.2.
Now I want to change to version EclipseLink 2.7.5, but I'm unable to find out how to setup Dali for new EclipseLink versions.
The JPA project dialog only shows EclipseLink 2.5.2 as a possible choice for the platform:
So I guess, I must download and install a new persistence platform so I'm able to select EclipseLink 2.7.5 from this dialog? Note that I already downloaded the zip archive for EclipseLink 2.7.5 - is it perhaps somehow possible to point Dali to this archive? Or is it necessary to manually remove EclipseLink 2.5.2 from the project's classpath and instead add the corresponding jar files for EclipseLink 2.7.5?
I'm sure that I'm missing something very obvious here since updating the persistence platform is certainly a common and easily done task... any help appriciated.
I was able to update to EclipseLink 2.7.5 by manually adding a new user library and then selecting this library in the JPA project dialog:
In the user library I simply added all jar files of EclipseLink 2.7.5 in the EclipseLink jlib folder.
Note that the folder of the library must not be a subfolder of the Eclipse project folder, otherwise Eclipse Dali will complain with the following error message (see this question):
The class 'javax.persistence.Convert' is required to be in the
selected libraries
Note also that for some reason it was necessary to move the EclipseLink 2.7.5 user library to the top of the dependency list in the Eclipse Run Configurations dialog.
I will happily accept any other answer that provides a more convenient way of updating EclipseLink.
In project properties I can go to
Java Compiler > Annotation Processing > Factory Path
and point to my jar file and everything is fine, but it's something I have to do for each project (and I have many and am constantly adding/deleting projects). That configuration path isn't available at the workspace level and I'm wondering if there is another way to set it up.
You probably should be using Maven (with the Eclipse m2e plugin), and configuring the annotation processing in each project's POM files ... or in a common parent POM file.
This page describes how to configure Maven's Java compiler plugin, and this one lists the attributes you can set in the POM file.
As far as I know, M2Eclipse doesn't handle natively the annotation processing phase.
To make up for this lack, there is the Maven Integration for Eclipse JDT Annotation Processor Toolkit plugin provided by JBoss Tools team that handles annotation processing with M2Eclipse.
Explanations of how it works are given in the readme part of the GitHub page and in this blog post. Get a careful reading of the aforedmentioned blog post to understand the configuration.
I always used Hibernate annotations in my old job, but since all our projects were already set up, I never really learned the mechanism behind it.
Could someone please give me a brief outline of how to set everything up, just to get me started?
I am developing in Java using Maven and Oracle 10g Express Edition. My IDE is Eclipse.
I'd recommend starting with the Hibernate tutorial. Basically, you'll need to create a Hibernate configuration file on your classpath (dropping it in src/main/resources works with the default Maven project layout) and then start annotating your data objects. There's a tutorial for Hibernate with XML configuration as well.
The (non-Maven) steps to build a Hibernate project in Eclipse would be:
Step 1: Add the required JARs to setup Hibernate project
Step 2: Add the JARs to the lib folder of your project
Step 3: Additionally, I would suggest you to explore the Hibernate directory structure since you are using it for the first time.
If you need more assistance, I wrote a post on my site http://myjavatrainer.com/setup-hibernate-project/
Hope it will be helpful to you.
Maven is build tool for your projects. Maven is a build tool by Apache, it will help to manage the dependencies better. You will have to install Maven separately and set it up. Read its documentation full and get it setup. Instead of creating a normal Java app or a web app in Eclipse, you will be creating a Maven project.
MAKE SURE YOU ADD A JAR FOR DRIVER CONNECTOR for the type of database you are planning to use through Hibernate.
Warning: I have just picked up Maven, so things mentioned might be wrong or not best practice.
I have a medium size open source project that I am migrating to Maven from the basic
NetBeans project management. This is not a developer team sharing the same room, this is 1-5 people over the internet sharing a SVN repo. Reading over the how-tos on dependencies, it seems that the only way to get dependencies is to get them from an online repo or install them locally.
This is not what I was looking for. I want to keep all dependencies in the SVN for many reasons including portability (anybody can pass by, check out the repo, build, and use; all that simply without manual adding to local repo's and whatnot), getting newer versions (discussed below), and manual versioning.
The other issue I have with the maven repository is that they are quite behind in versions. Logback for example is 0.9.18 in mvnbrowser but 0.9.24 officially. PircBot is 1.4.6 in mvnbrowser but 1.5.0 officially. Why such old versions?
Issue 3 is that I have dependencies that don't even exist in the repos, like Easier Java Persistence.
So
How can I force all dependencies to come from /lib for example
On a related note, can mvn build from library's SVN repo directly? Just curious
Is there an automatic way to get the newest version directly from a dependencies site/svn repo if they also use Maven? IE libraries like commons-lang or logback
Is there a better way of managing dependencies? (IE Ivy or some weird POM option I'm missing)
FYI, this is a Java project with 3 modules, project global dependencies and module specific dependencies.
Bonus points if it can work with the bundled version of Maven that comes with NetBeans.
Not a duplicate of
Maven: add a dependency to a jar by relative path - Not wanting to install to local repository
maven compile fails because i have a non-maven jar - Don't think a System dependency is the right answer
maven look for new versions of dependencies - Still uses(?) repository, just the latest (old) version
This is not what I was looking for. I want to keep all dependencies in the SVN for many reasons (...)
I will come back on this but the solution I described in Maven: add a dependency to a jar by relative path (using a file-based repository) allows to implement such a solution.
The other issue I have with the maven repository is that they are quite behind in versions. Logback for example is 0.9.18 in mvnbrowser but 0.9.24 officially. PircBot is 1.4.6 in mvnbrowser but 1.5.0 officially. Why such old versions?
It looks like mvnbrowser indices are totally out of date (making it useless as repository search engine) because the maven central repository does have logback-core-0.9.24.jar (the logback project is doing what has to be done to make this happen) but only has an old pircbot-1.4.2.jar. Why? Ask the pircbot team. Anyway, you're right, the central repository might not always have ultimate versions.
Issue 3 is that I have dependencies that don't even exist in the repos, like Easier Java Persistence.
Yeah, this happens too.
How can I force all dependencies to come from /lib for example
As previously hinted, you should re-read carefully the solution suggested in Maven: add a dependency to a jar by relative path. This solution is not about installing libraries to the local repository but is about using a file-based repository (that could thus be stored in SVN). You might have missed the point, this matches your use case. And also check Brett's answer for a variation.
On a related note, can mvn build from library's SVN repo directly? Just curious
Didn't get that one. Can you clarify?
Is there an automatic way to get the newest version directly from a dependencies site/svn repo if they also use Maven? IE libraries like commons-lang or logback
Maven supports version ranges and you could use a syntax allowing to use "any version greater than X". But I do NOT recommend using version ranges at all, for the sake of build reproducibility. You don't want the build to suddenly fail because of some automatic update that happened on your back. Only upgrade if you need bug fixes or new features, but do it explicitly (if it ain't broke, don't fix it).
You might also find mentions of the LATEST and RELEASE version markers. I don't recommend them neither for the same reasons as above and even less since they're removed from Maven 3.x.
Is there a better way of managing dependencies? (IE Ivy or some weird POM option I'm missing)
Can't say for Ivy. But in the Maven land, if you can't host up a "corporate" repository for your project (Nexus, Archiva, Artifactory), then the file-based repository is IMO the best approach.
Setup your own Maven repository.
http://archiva.apache.org/
I want to autogenerate some java classes from interfaces. My first thought was to write a code generator, and integrate it as a maven plugin.
I was thinking of creating a maven plugin with a codegen goal that is called during the build process.
So if I choose this route, how do I provide the plugin with the interfaces to be processed? And where should the generated files go?
Are there any existing plugins that can be configured to generate default class implementations?
Sources should go in {project.build.directory}/generated-sources/[plugin-id]/
Most plugins take configuration passed through the plugin configuration section in the pom. You can use default values as well, or an annotation and classpath scanning.
A plugin like the maven-jspc-plugin generates code, which you could take a look at. The "Better Builds With Maven" e-book also contains a reasonably comprehensive chapter on writing plugins.
Maybe have a look at the XDoclet Maven plugin- XDoclet is often used for generating sources from doclet-style markup in classes (e.g. autogenerating MBean interfaces from implementations) and that sounds similar to what you're doing.
I have used APT-Jelly to successfully generate java source code from annotated java. You may want to check it out.