8/29/2023 0 Comments Import.sql hibernate java![]() ![]() Query = session.createNativeQuery("select max(salary) from User_Info") Creating a Query by calling createNativeQuery() method to execute SQL max() function Query = session.createNativeQuery("select min(salary) from User_Info") Creating a Query by calling createNativeQuery() method to execute SQL min() function ("Retrieving values in multiple columns with property 'id' and 'firstName' ") List collection = query1.getResultList() ![]() Query query = session.createNativeQuery("select ID,First_Name from User_Info") Creating a Query by calling createNativeQuery() method to execute an SQL query Session.save(ob3) //Saving the third object Session.save(ob2) //Saving the second object Session.save(ob1) //Saving the first object SessionFactory sf= new Configuration().configure().buildSessionFactory() Object to perform the object persistence operations. Using Configuration object we can create a SessionFactory object, which is eventually used to create a Session This object is used to specify the location of a configuration file and This is the first object we use when using the Hibernate. The Hiber class creates a Configuration object, used to configure the Hibernate. This class will create some UserInfo objects, which will be persisted in a database table using the HibernateĪnd then it's going to execute the SQL commands like accessing multiple columns of a table andĮxecuting SQL methods like max(), min(), sum(), count() and avg() using the method createNativeQuery() of Query class. Public void setFirstName(String firstName)Ĭreating the class that calls the Hibernate API This class is an entity class, hence it will be preceded with the annotation plus a few other annotations used below. ![]() Some may even refer to such class whose objects needs to be persisted as the Model class. This is a simple Java class whose objects needs to be persisted/saved, these objects are also known as Plain Old Java Objects (POJO) or Entity class. Representing our Model class(whose objects needs to be persisted). We are going to create a general parent class that will contain all the Java code files
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |