Hibernate has the SQL/HQL features of Mybits (annotations and XML are correct) and mybitshql

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.