Reputation: 56904
I have spent several days now researching Hibernate and have several small questions about it that in and of themselves don't really merit cluttering SO but I think, together, help give some insight to how Hibernate operates as a whole:
hibernate.cfg.xml
config file as well as annotating the respective POJO as being an @Entity
. This feels horribly redundant. Why can you just use the annotation and just skip the XML entry?Query
API, but I see no such options for the Criteria
API. Is parameterizing possible with Criteria
instances: if so, how, and if not, why?CacheProvider
, throw it on the ruuntime classpath and have Hibernate use your own homegrown cache system (like SLF4J does with logger bindings)?Thanks in advance!
Upvotes: 2
Views: 68
Reputation: 691685
Because it would force Hibernate to scan all the classes of the classpath to discover annotated classes. And because you might have some entities in the classpath that you don't want to use in your application. Or you might want to have some entities in a session factory, and some others in another one. Or even the same entity in two seperate session factories.
The Criteria API has methods which bind the parameters directly: Restrictions.eq("someProperty", someValue);
for example.
It's of course possible to write your own second-level cache, but you would have to configure Hibernate to use it, as you do with all the other providers. Dropping the classes in the classpath is not sufficient.
Upvotes: 2