Hibernate has the SQL/HQL features of Mybits (annotations and XML are correct) and mybitshql
The first time I wrote a blog. The article is a little scum. If you like it, you just have a look. If you don't like it, you can get a thumbs up.
Effect: multiple statements are used directly.
First, use the HQL/SQL + Freemarker template to generate query statements.
1: Write SQL/HQL in XML.
2: Write a file scanner (missing)
3: Read the interpreted XML
4: cache query statement by entity Space
5: direct use
Note: Do not copy the package directly. first understand the process, because it is written in the old version and test package, and some code is omitted. Therefore, the package path is incorrect. The program is not complete. If you lack it, let everyone think about it. Basically, it depends on Spring. If it does not rely on Spring injection, you can consider using proxy mode injection (reflection/generation of bytecode (javassist/asm)/CGLIB, etc)
1: to facilitate the first definition of the constraint Query. dtd
2: Create entity class user. class
3: Create the corresponding XML (User. query. xml)
4: parse cache XML
5: Define the DBAdapter interface.
6: Write implementation (AbstractHibernateDBAdapter, HibernateSingleDBAdapter)
AbstractHibernateDBAdapter
HibernateSingleDBAdapter
7. xml injection
<! -- QueryFile injection -->
<Beanid ="QueryFactory"Class ="Com. cheuks. bin. db. manager. QueryFactory">
<Propertyname ="Files"Value ="*. Query. xml"/>
</Bean>
<! -- Single DBAdapter injection -->
<Beanid ="DBAdapter"Class ="Com. cheuks. bin. db. manager. HibernateSingleDBAdapter">
<Propertyname ="SessionFactory"Ref ="SessionFactory"/>
<Propertyname ="QueryFactory"Ref ="QueryFactory"/>
</Bean>
8: Use AbstractDao and UserDao
AbstractDao
UserDao
The whole process is complete. For the XML part, see DTD. If you think it is good, you can add it to your favorites. But please do not change your name to your own achievements!