当前位置: 首页 > news >正文

公司国际网站怎么做北京网站设计与制作公司

公司国际网站怎么做,北京网站设计与制作公司,网站开发虚拟主机是什么,wordpress加密功能被Prepersist注解的方法 #xff0c;完成save之前的操作。 被Preupdate注解的方法 #xff0c;完成update之前的操作。 被PreRemove注解的方法 #xff0c;完成remove之前的操作。 被Postpersist注解的方法 #xff0c;完成save之后的操作。 被Postupdate注解的方法 #…被Prepersist注解的方法 完成save之前的操作。 被Preupdate注解的方法 完成update之前的操作。 被PreRemove注解的方法 完成remove之前的操作。 被Postpersist注解的方法 完成save之后的操作。 被Postupdate注解的方法 完成update之后的操作。 被PostRemovet注解的方法 完成remove之后的操作。 This page will provide JPA EntityListeners example with callbacks PrePersist, PostPersist, PostLoad, PreUpdate, PostUpdate, PreRemove, PostRemove. JPA EntityListeners is used on entity or mapped superclass at class level. JPA provides callback methods for saving, fetching, updating and removing data from database. Here we will use JPA EntityManager to interact with database. JPA EntityListeners EntityListeners annotation specifies the callback listener classes . This annotation can be used for an entity or mapped superclass.  1. To configure single callback listener class, we can do as follows. EntityListeners(UserListener.class) public class User {} 2. To configure multiple callback listener classes, we can do as follows. EntityListeners({UserListener1.class, UserListener2.class}) public class User { } JPA Callbacks Method JPA provides callback methods to listen saving, fetching, updating and removing data from database. These callback methods annotated in a listener bean class must have return type void and accept one argument. PrePersist: The method annotated with PrePersist in listener bean class is called before persisting data by entity manager persist() method. PostPersist: The method annotated with PostPersist is called after persisting data. PostLoad: The method annotated with PostLoad is called after fetching data using entity manager find() method in persistence context or refreshing it with database by using refresh() method. If the entity instance is already loaded in persistence context, then calling of find() method will not call PostLoad. PreUpdate: The method annotated with PreUpdate in listener bean class is called before updating data. PostUpdate: It is called after updating data. PreRemove: The method annotated with PreRemove in listener bean class is called before removing data by using entity manager remove() method. PostRemove: It is called after removing data. Database Schema For the demo we are using a table with following schema created in MySQL. Table: user CREATE TABLE user (id INT(11) NOT NULL,name VARCHAR(255) NULL DEFAULT NULL,PRIMARY KEY (id) ) COLLATElatin1_swedish_ci ENGINEInnoDB; Gradle File Find the gradle file. build.gradle apply plugin: java apply plugin: eclipse archivesBaseName HibernateJPA version 1 repositories {mavenCentral() } dependencies {compile org.hibernate:hibernate-entitymanager:5.0.7.Finalcompile mysql:mysql-connector-java:5.1.31 } Create Listener Class Find the listener class which consist callback methods annotated with PrePersist, PostPersist, PostLoad, PreUpdate, PostUpdate, PreRemove and PostRemove. UserListener.java package com.concretepage; import javax.persistence.PostLoad; import javax.persistence.PostPersist; import javax.persistence.PostRemove; import javax.persistence.PostUpdate; import javax.persistence.PrePersist; import javax.persistence.PreRemove; import javax.persistence.PreUpdate; public class UserListener {PrePersistpublic void userPrePersist(User ob) {System.out.println(Listening User Pre Persist : ob.getName());}PostPersistpublic void userPostPersist(User ob) {System.out.println(Listening User Post Persist : ob.getName());}PostLoadpublic void userPostLoad(User ob) {System.out.println(Listening User Post Load : ob.getName());} PreUpdatepublic void userPreUpdate(User ob) {System.out.println(Listening User Pre Update : ob.getName());}PostUpdatepublic void userPostUpdate(User ob) {System.out.println(Listening User Post Update : ob.getName());}PreRemovepublic void userPreRemove(User ob) {System.out.println(Listening User Pre Remove : ob.getName());}PostRemovepublic void userPostRemove(User ob) {System.out.println(Listening User Post Remove : ob.getName());} } Create Entity annotated with EntityListeners Now find the entity annotated with EntityListeners. User.java package com.concretepage; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityListeners; import javax.persistence.Id; import javax.persistence.Table; Entity EntityListeners(UserListener.class) Table(nameuser) public class User {IdColumn(nameid)private int id;Column(namename)private String name;public User() {}public User(int id, String name) {this.id id;this.name name;}public int getId() {return id;} public String getName() {return name;}public void setName(String name) {this.name name;} } persistence.xml Find the persistence.xml file. ?xml version1.0 encodingUTF-8 ? persistence xmlnshttp://java.sun.com/xml/ns/persistencexmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsdversion2.0persistence-unit namecom.concretepagedescriptionJPA Demo/descriptionproviderorg.hibernate.ejb.HibernatePersistence/providerpropertiesproperty namehibernate.dialect valueorg.hibernate.dialect.MySQLDialect/property namehibernate.hbm2ddl.auto valueupdate/property namejavax.persistence.jdbc.driver valuecom.mysql.jdbc.Driver/property namejavax.persistence.jdbc.url valuejdbc:mysql://localhost/concretepage/property namejavax.persistence.jdbc.user valueroot/property namejavax.persistence.jdbc.password value//properties/persistence-unit /persistence Run Application First find the JPA utility singleton class that will provide the instance of EntityManager. JPAUtility.java package com.concretepage; import javax.persistence.EntityManager; import javax.persistence.EntityManagerFactory; import javax.persistence.Persistence; public class JPAUtility {private static final EntityManagerFactory emFactory;static {emFactory Persistence.createEntityManagerFactory(com.concretepage);}public static EntityManager getEntityManager(){return emFactory.createEntityManager();}public static void close(){emFactory.close();} } Find the class to test the application. JPAListenerDemo.java package com.concretepage; import javax.persistence.EntityManager; public class JPAListenerDemo {public static void main(String[] args) {EntityManager entityManager JPAUtility.getEntityManager(); entityManager.getTransaction().begin();//persist userUser user new User(1, Mahesh);entityManager.persist(user);entityManager.getTransaction().commit();//refresh userentityManager.refresh(user);//update userentityManager.getTransaction().begin(); user.setName(Krishna);entityManager.getTransaction().commit();//remove userentityManager.getTransaction().begin(); entityManager.remove(user);entityManager.getTransaction().commit(); entityManager.close();JPAUtility.close(); } } Find the output. Listening User Pre Persist : Mahesh Listening User Post Persist : Mahesh Listening User Post Load : Mahesh Listening User Pre Update : Krishna Listening User Post Update : Krishna Listening User Pre Remove : Krishna Listening User Post Remove : Krishna
http://www.yutouwan.com/news/157395/

相关文章:

  • 做网站端口映射网站建设方式有哪些
  • 房山网站建设优化seo提供徐州网站建设
  • 海口网站建设方案报价实时热点新闻事件2021
  • 镇江网站关键字优化机构如何自己做资源类网站
  • 医药企业网站设计制作漂亮logo图片
  • 温州专业网站建设58同城网站建设思路
  • 网站建设需求分析报告wordpress支付宝收银台
  • 给一个网站如何做推广财税公司怎么找客源
  • 湛江网站模板asp做网站搜索
  • 合肥道路建设从哪个网站可以看到wordpress前端修改影响升级
  • 美食网站建设实施方案北京做网站推广seo
  • 住宅小区物业管理系统网站建设荆门网站开发公司
  • 网站推荐男生正能量上海建设检测行业协会官网
  • 官方在家做兼职的网站注册小公司
  • 哈尔滨网站排名公司活动策划网站
  • 网站品牌词如何优化精美网站模板下载
  • 驻马店哪家做网站好网站布局分类
  • 写字就能赚钱做网站哪里有免费的域名注册建网站
  • 哈尔滨龙彩做网站多少钱网站维护需要
  • 什么是主机托管求职seo推荐
  • 哪里有免费的网站网址温州哪里可以做企业网站
  • 互联业务登录页 网站网站主页 优帮云
  • 深圳最好的营销网站建设公司美容店网站建设
  • 移动端网站开发语言企业网站整合
  • 会计上大额网站费如何做分录短视频制作软件app
  • 合肥网站建设兼职wordpress 菜单显示
  • 电商网站入口门户网站建设公司哪家好
  • 榆林网络公司建设网站自助建站在线快速建站
  • 海创网站建设wordpress外观
  • 园林绿化网站建设dz网站模板 首页显示内容