`

javaassist used in the hibernate

阅读更多
  javaassist opensource framework is the initials of  the"Java Programming Assistant" , it makes Java bytecode manipulation simple and easy. you can manipulate the behaviors of the java the following aspects:
1 soruce code level
2 bytecode level
hibernate use the javaassist to instead to the cglib in version 3.3, its function is similar to the cglib ,it can implement the lazy loading and generate the po objects
for examples:
package antlr;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;




public class TestAntlr {

    public static void main(String[] args) throws Exception {
        ClassPool cp = ClassPool.getDefault();
        CtClass cc = cp.get("antlr.Hello");
        CtMethod m = cc.getDeclaredMethod("say");
//         m.setBody("{System.out.println(\"s\");}");

        m.insertBefore("System.out.println(\"ss\");");
        Class c = cc.toClass();
        Hello h = (Hello)c.newInstance();
        h.say();
       
//         ClassPool cp = ClassPool.getDefault();
//         CtClass cc = cp.get("java.lang.String");
//         CtMethod m = cc.getDeclaredMethod("toString");
////         m.setBody("{System.out.println(\"s\");}");
//
////         m.insertBefore("System.out.println(\"ss\");");
//         Class c = cc.toClass();
//         String h = (String)c.newInstance();
//         h.toString();
       
       
    }
}



package antlr;

class Hello{
public void say() {
        System.out.println("Hello");
    }
}
分享到:
评论

相关推荐

    Java Persistence WIth Hibernate 2nd

    In a recent poll, Hibernate was among the top five tools used by many Java developers every day. This shows that SQL databases are still the preferred technology for reliable data storage and ...

    A Testing Framework used in the web Testing

    A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used in the web Testing A Testing Framework used...

    Java.Persistence.with.Hibernate.2nd.Edition

    design patterns that are used with Hibernate, such as the Data Access Object (DAO). You see how you can test your Hibernate application easily and learn what other best practices are relevant if you ...

    Programming Finite Elements in Java

    The FEM is commonly used in the design and development of products, especially where structural analysis is involved. The simple object model of the Java™ programming language lends itself to ...

    The Finite Volume Method in Computational Fluid Dynamics

    The second is OpenFOAM®, an open source framework used in the development of a range of CFD programs for the simulation of industrial scale flow problems. With over 220 figures, numerous examples ...

    CAN protocol used in the STM32 bootloader.pdf

    This application note describes the CAN protocol used in the STM32 microcontroller bootloader. It details each supported command. This document applies to the STM32 products embedding bootloader ...

    Modern Java In Action 2019

    Put simply, the new features in Java 8 along with the (less-obvious) changes in Java 9 are the biggest change to Java in the 21 years since Java 1.0 was released. Nothing has been taken away, so all ...

    Hibernate Recipes(Apress,2ed,2015)

    Hibernate 4.x continues to be the most popular out-of-the-box, open source framework solution for Java persistence and data/database accessibility techniques and patterns and it works well with the ...

    Applied Artificial Intelligence_Where AI Can Be Used in Business 2018.pdf

    The structure of the chapter is very similar, so I hope the reader won’t find diffi- culties in establishing comparisons or understanding the differences between specific problems AI is being used ...

    Java in a Nutshell, 7th Edition

    This updated edition of Java in a Nutshell not only helps experienced Java programmers get the most out of Java versions 9 through 11, it’s also a learning path for new developers. Chock full of ...

    hibernate_reference.pdf

    The architecture section provides an overview of the core components and design patterns used in Hibernate. - **Overview**: This introduces the main concepts and components of Hibernate's ...

    Data Structures and Algorithms in Java, 5th Edition (Part 3/3)

    Library (net.datastructures) of Java constructs used in the book Problems database and search engine Student hints to all exercises in the book Instructor resources, including solutions to ...

    On the 20/40 MHz Coexistence of Overlapping BSSs in WLANs

    Our results show that if clear channel assessment (CCA) is not used in the overlapping channel, the throughput in legacy BSS is almost zero, while the throughput of 20/40 MHz BSS decreases ...

    Java_for_the_Web_with_Servlets

    "Java for the Web with Servlets, JSP, and EJB: A Developer’s Guide to J2EE Solutions" by Budi Kurniawan is a comprehensive guide aimed at helping developers master web programming in Java. The book ...

    Data Structures and Algorithms in Java, 5th Edition (Part 2/3)

    Library (net.datastructures) of Java constructs used in the book Problems database and search engine Student hints to all exercises in the book Instructor resources, including solutions to ...

    The Java Module System.epub

    In this new book, you'll learn how the module system improves reliability and maintainability, and how it can be used to reduce tight coupling of system components. Foreword by Kevlin Henney. ...

    Pro JPA 2 in Java EE 8: An In-Depth Guide to Java Persistence APIs.pdf

    Learn to use the Java Persistence API (JPA) and other related APIs as found in the Java EE 8 platform from the perspective of one of the specification creators. A one-of-a-kind resource, this in-depth...

    think in java pattern

    On the other hand, by going through this book you’re going to learn a lot about object-oriented programming by seeing objects used in many different situations. If your knowledge of objects is ...

    Hibernate_A Developers Notebook

    Hibernate: A Developer's Notebook shows you how to use Hibernate to automate persistence: you write natural Java objects and some simple configuration files, and Hibernate automates all the ...

Global site tag (gtag.js) - Google Analytics