-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 posts ] 
Author Message
 Post subject: A framework to enhance JPA/Hibernate
PostPosted: Mon Oct 19, 2015 8:29 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Hi, Hibernate Friends

I'm a Chinese programmer who loves hibernate very much. I used my spare time to develop a new framework to(but not only) enhance Hibernate since 2008. After 7 years, Now, it's has been finished, and published on github.

Please view https://github.com/babyfish-ct/babyfish to know more.

After I finished it, suddenly I found I do not know how to let more friends know it, so I take the liberty to come to this forum.

There are many very detailed documentation in the project in GitHub. Unfortunately, I'm Chinese guy with poor English skill, please forgive my ugly English documents. Thanks.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Wed Oct 21, 2015 2:32 am 
Newbie

Joined: Thu Oct 15, 2015 11:05 pm
Posts: 4
thanks for your great sharing


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Thu Oct 22, 2015 9:28 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Welcome! Looks very interesting.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 4:58 am 
Newbie

Joined: Mon Oct 19, 2015 10:41 am
Posts: 1
I like the query path, thanks guy!


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 7:46 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
I hope my work can help you solve practical problems.
Steve, you said it is very interesting. Haha, that means I reach my design goals, thank you for sure.

Now, this framework has been uploaded to "Maven Central Repository", so the step "Install the babyfish framework" of "get-started.html" is unnecessary and it can be skipped.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 8:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Haha. I certainly meant in a good way :-)

Are there any changes in Hibernate that would make this work more smoothly?

Coupled with the major rewriting of bytecode enhancement we did for 5.0, I really like the idea of enhancing the entity to optionally allow injection of the Metadata (in some form) into the enhanced class. Although we already have the JPA "static metamodel" which fulfills some of this need; hopefully soonish I hope to make that available from native (non-JPA) uses.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 11:28 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Haha, Agree, It need to be done more smoothly :)

They are two framework, not one framework, it tried my best but it is impossible to find the smooth solution. I hope the ORM part of my framework can be merged into hibernate in the future if you can accept it.(The reason why I did it like this is the actual work is larger than my image, when I decide to do it in 2008, my goal of ORM part very small, but now, it's so huge)

Then I show the most important functionalities and show how did I implement them.

(1) ObjectModel4JPA, it can manage the bidirectional associations of JPA entities as powerful as ObjectModel4Java(User modification of one side can trigger an event to notify and change the other side automatically and implicitly).

(a) Use org.babyfish.hibernate.cfg.Configuration.processPersistentClasses() to replace the Hibernate Collection Type, the collection property is collection wrapper chain with 3 layers.
+-Dynamically generated derived class that extends the collection under the package "org.babyfish.hibernate.association"(For bidirectional association managment)
|
\----+-Persistent MA Collection under the package "org.babyfish.hibernate.collection", Replace hibernate lazy collections, When the inverse collection is lazy, the modification implemented by fake mode, but the modifcation event will still be triggered.
|
\------MA Collection under the package "org.babyfish.collection", The Java part of this framework, support Unstable Collection Elements, Event Trigger and Bubble event
(b) Use org.babyfish.hibernate.proxy.FrozenLazyInitializerImpl to replace the javassist Handler of Hibernate Proxy to let it can trigger even if it's lazy.

That's why the powerful functionalities of ObjectModel4Java can also be used on JPA Entity class too.

(2) QueryPath:
For TypedQueryPath, it is created by the programmer via the generated source code. Be different with JPA static metadata model, the generated source code of TypedQueryPath dose not use the IOC, so it dose not depend on Hibernate injection, and it can be used wherever and whenever, eg: Hibernate is not started; In the bussiness logic layer or UI layer; Another remote machine that does not run Hibernate.
For NonTypedQueryPath(Often created by javascript of UI layer), use the embeded query path compiler(babyfish-entity/src/main/antlr4/..../QueryPath.g4) to compile it.

Then org.babyfish.hibernate.hql.XQueryTranslatorImpl parses and changes the byte code of org.hibernate.hql.internal.ast.QueryTranslatorImpl to change the logic of HQL compiler, changes the HQL AST to apply query paths to add dynamic association fetches and dynamic order, then changes the SQL AST to do final optimization, finally uses batch query to load the fetched scalars(This progress it very complex, it uses org.babyfish.lang.reflect.asm.ClassEnhancer which is a powerful bytecode hacker, it can create derived class from a super class, and rewrite the private, final or static methods of super class).

Fewest demos that can demonstrate my solution as fast as possible:
(A) Unstable Collections Element: babyfishdemo-macollections/src/test/java/org/babyfishdemo/xcollection/uce/UnstableCollectionElementsTest.java(This is very important to ORM, because ORM entities are often unstable)
(B) Bubble Event: babyfishdemo-macollection/src/test/java/org/babyfishdemo/macollection/bubble/SimpleBubbleEventTest.java(Java Collection Framework is more complex than the collection of other langugages, ObjectModel is impossible to be implmeneted without bubble event)
(C) ObjectModel4Java: babyfishdemo-om4java(babyfishdemo-om4-jpa only shows how to inject ObjectModel into JPA entity by byte code instrument, but does not show what the ObjectModel is)
(D) QueryPath: babyfishdemo-spring/src/test/java/org/babyfishdemo/spring/dal/QueryPathTest(In real project, it can resolve problems very fast)


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 11:44 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Forgot one thing

For the original functionalities of Hibernate, BabyFish collection framework can help it to improve the performance. Maybe it can be implemented in the future.

(1) MA Collection can record all the modification event when user change the collection by any way(collection itself, view collection, iterator or map entry), the event queue can help the collection to avoid dirty-checking when it's submitted.
(2) Non-inverse collection need not to load itself when it's modified because dirty-checking is not unnecessary, so both inverse collection and non-inverse collection can work in the the classic lazy="extra" style.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Fri Oct 23, 2015 4:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Yes I totally agree. I wanted to look at the collection stuff.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Thu Oct 29, 2015 9:39 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
I want to cry T_T. I've created and published the first Chinese video for this framework and it get good reply and discussion; then I started to try my best to create the English video, but I found it's impossible to be finished because of my poor English skills.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Sat Oct 31, 2015 3:49 pm 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Hi guys

I've tried my best to create the first English video

https://youtu.be/DBDdQkBLrLU

I apologize for my ugly English again


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Tue Nov 17, 2015 3:08 am 
Newbie

Joined: Mon Nov 16, 2015 11:11 pm
Posts: 2
Seven years, you're so good. Congratulate and cheer for you. Do you have a qq group.


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Wed Nov 18, 2015 8:33 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Yes, I have QQ group for this project: 511924129, Welcome to this group.

I guess you are Chinese too because you asked me the QQ group number, please use git to clone the repository and read the Chinese doc file "fast-learn_zh_CN.docx" which contains not only characters but also pictures(If not, the English version "fast-learn.docx" will be added one or two weeks later).


Top
 Profile  
 
 Post subject: Re: A framework to enhance JPA/Hibernate
PostPosted: Tue Dec 08, 2015 5:37 am 
Regular
Regular

Joined: Mon Oct 19, 2015 7:49 am
Posts: 61
Location: ChengDu China
Finally, the tutorial document with both text and pictures are finished, you can find these files under the root directory of the github page of this project.
English version: tutorial.html
Chinese version: tutorial_zh_CN.html

As Steve Ebersole said, the JPA part is not smooth. Yes, he's right, I've used some byte code hack technologies to change the behavior of hibnerate.

Now, my tutorial document is finished so that everyone can understand this framework in short time, if some guys think it's valuable, is it possible to let Hibernate do a little refactor so that I can enhance it more smoothly? or is it possible to merge the JPA part of my framework and Hibernate together?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 14 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.