I am using Hibernate, Maven, and Eclipse (STS build) to build a project. I'm using hbm.xml files to specify my schema. I want to use Hibernate's hbm2java to generate my model classes. I have it working well and generating the kind of code I want.

It runs perfectly from the command line, generating the model code and then building and testing as expected.

However, Eclipse seems unable to handle it. It will periodically "lose its mind" and be unable to resolve very simple imports and classes referenced in my DAO classes, which are hand-coded. The things it can't find are classes like HibernateUtil. Ironically, it appears to not have any trouble finding the model classes.

The unresolved classes are in target/classes/blah-blah folder at the end of the run. So they're apparently getting copied to the right place.

In a "continuous integration" environment, is it best to generate the sources once, commit them to my version control, and then disable code gen? Or is it possible to have the code generated each time, thus ensuring I pick up any database changes without human intervention?

有帮助吗?

解决方案

IMHO, entities should be the core of your application, and should be designed, implemented and documented with care. They're supposed to be objects, with methods encapsulating behavior. Having them autogenerated is an absurdity, IMO.

Generating them at the very beginning might be an option to get you started, but once they've been generated, hand-craft them and don't generate them again. Add necessary properties and methods as the schema changes, and refactor existing code.

BTW, I really prefer using annotations for the mapping, because it's less verbose, less error-prone, and all the information is in a single place.

其他提示

Try this:

From command line traverse to your project directory where the project's pom.xml is present and run:

mvn eclipse:clean eclipse:eclipse

If it says unable to find plugin eclipse then try:

mvn eclipse:install-plugin

First and then try the command above again.

In this way all the maven and project dependencies will be resolved at eclipse level also.

Let me know if this is not what you were looking for.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top