質問

I'm using Hibernate Tools in Eclipse to reverse engineer the domain entities of an existing database.

I more-or-less have everything generating how I want, although I still get a batch of "Metamodel" classes generated alongside my domain classes. These are classes with the same name, but suffixed with and underscore "_".

I've read some docs on the metamodel concept here, but I'm still not sure on their purpose...

Is it safe for me to simply delete those classes? If they are not useful to me I'd rather not have them cluttering up my package explorer.

役に立ちましたか?

解決

The Metamodel classes are used by the "typesafe Criteria API" that was added in JPA 2.0. Details on this API are here:

http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html_single/#querycriteria

Hibernate EntityManager can use the metamodel classes to verify that a Criteria is valid for a given set of entities. For example, if you attempt to write a query which adds a "where" clause against an entity's property, Hibernate can validate the property actually exists in your model and (I believe) generate a compile-time error or warning. With Hibernate's old Criteria API, the only way to validate such a query was to execute it and see if an exception was thrown.

If you don't plan to use this Criteria API then it's probably safe to delete the classes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top