Tag:Hibernate

  • JSP hibernate paging code page 1 of 3

    Time:2021-9-19

    It can be seen that using hibernate has great flexibility in query paging. Hibernate will first try to use the paging SQL of a specific database. If it is useless, then try scrollable. If not, finally use RSET. Next() to move.(1) Pager class* @(#)Pager.java 2005-5-3 * * Copyright (c) 2005, Jeffrey Hsu */ package com.jeffrey.messagelove; […]

  • Struts 2 + Spring + Hibernate paging code [more] page 1 / 7

    Time:2021-9-18

    Dao layer interface:Java code Copy codeThe code is as follows: package com.last999.im.news.dao; import java.util.*; import com.last999.im.news.entity.KindEntity; import com.last999.im.news.web.PageTool; public interface KindEntityDao{ public KindEntity get(String uuid); public void save(KindEntity kindEntity); public void update(KindEntity kindEntity); public void delete(String uuid); public void delete(KindEntity kindEntity); public List<KindEntity> findAll(); public KindEntity findKindEntityByName(String name); public List<KindEntity> getKindEntity(PageTool pageInfo); public int getRows(); […]

  • Principle of JSP hibernate data saving operation

    Time:2021-9-7

    Data saving, updating and deletion:1. Session. Save() method:The session. Save () method is used for the persistent saving of entity objects, that is, when the session. Save () method is executed, the corresponding insert SQL statement will be generated to save the data. As shown in the following code:User user=new User(); user.setName(“zx”); Transaction tx=session.beginTransaction(); session.save(user); […]

  • Introduction to JSP hibernate function

    Time:2021-9-6

    1、Configuration/SessionFactory/Session The configuration instance represents a complete set of Java type to SQL database mappings in an application. Configuration is used to build a (immutable) sessionfactorySessionfactory is thread safe and expensive to create.Session is non thread safe and lightweight. A session corresponds to a JDBC connection,The connection () of the session will get the database […]

  • Hibernate general database operation code

    Time:2021-9-5

    Insert method Copy codeThe code is as follows: public void insert(Object o){Session session = HibernateSessionFactory.currentSession();Transaction t = session.beginTransaction();session.save(o);t.commit();HibernateSessionFactory.clossSession();} Delete method Copy codeThe code is as follows: public void delete(Object o,Serializable id){Session session = HibernateSessionFactory.currentSession():Transaction t = session.beginTransaction();Object o = session.get(o.class,id);if(o!=null){session.delete(o);}t.commit();HibernateSessionFactory.clossSession();} Update method Copy codeThe code is as follows: public void update(Object o,Serializable id){Session session = […]

  • JSP hibernate Getting Started tutorial page 1 of 3

    Time:2021-9-4

    For example: Copy codeThe code is as follows: HibernateTest.java import onlyfun.caterpillar.*; import net.sf.hibernate.*; import net.sf.hibernate.cfg.*; import java.util.*; public class HibernateTest { public static void main(String[] args) throws HibernateException { SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); Session session = sessionFactory.openSession(); List users = session.find(“from User”); User updated = null; for (ListIterator iterator = users.listIterator(); iterator.hasNext(); ) { […]

  • Summary of Hibernate data updating methods

    Time:2021-9-2

    Copy codeThe code is as follows: Usertable user=null; Session session=HibernateSessionFactory.getSession(); String sql=”from Usertable as user where user.username=?”; Query q=session.createQuery(sql); q.setString(0,username); List l=q.list(); Iterator ite=l.iterator(); if(ite.hasNext()){ user=(Usertable)ite.next(); } return user; It can only be updated after the query. Just use session.update.The update () method of Hibernate’s session interface can update the persistent object and transfer the […]

  • JSP hibernate batch update and batch deletion processing code

    Time:2021-8-30

    The following procedure updates the age field of all records older than zero in the customers table in batches directly through the hibernate API:tx = session.beginTransaction();Iterator customers=session.find(“from Customer c where c.age>0”).iterator();while(customers.hasNext()){Customer customer=(Customer)customers.next();customer.setAge(customer.getAge()+1);} tx.commit();session.close(); If there are 10000 records older than zero in the customers table, the find () method of session will load 10000 customer […]

  • Summary of Hibernate query methods

    Time:2021-8-19

    1. get() and load() Java code  session.get(Clazz, id);   session.load(Clazz, id);   session.get(Clazz, id);   session.load(Clazz, id); Note: the difference between load() and get()Note that if there is no matching database record, the load () method may throw an unrecoverable exception. If the class mapping uses a proxy, the load () method will return an uninitialized proxy. You won’t […]

  • Implementation code of addition, deletion, modification and query in Hibernate

    Time:2021-8-10

    First, let’s take a look at the addition. In SQL, the addition is insert, that is, insert. In Hibernate, we only need to manipulate an object for Sava, and then commit the transaction to realize the insertion function. Next, let’s take a look at the code. I won’t write any more persistent classes, that is, […]

  • In SSH integration, hibernate is managed to spring to get sessionfactory

    Time:2021-7-2

    <prop key=”hibernate.current_session_context_class”>thread</prop> thenResource resource=new ClassPathResource(“/WEB-INF/applicationContext.xml”); BeanFactory factory=new XmlBeanFactory(resource); SessionFactory sessionFactory = (SessionFactory)factory.getBean(“sessionFactory”); You can get itThe rest will not be returned. My approach is to modify the hibernateutil file to get sessionfactory, and everything will be solvedimport org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; //Get sessionfactory when […]

  • Hibernate validator usage and custom validator annotation

    Time:2020-5-14

    Jsr-303 is a sub specification in Java EE 6, called bean validation, which is used to validate the values of fields in java bean. Hibernate validator is an implementation of this specification provided by hibernate. ——Hibernate validator is used for parameter verification. Use the annotation provided by hibernate validator for parameter verification annotation interpretation @Null […]