There are no reviews yet. Be the first to send feedback to the community and the maintainers!
Sample-Hibernate-Code
save, update,delete,SaveOrUpdate,GetJDBC_Operations
Insert, Update, Delete,Create TableSpring_SpringORM_Save_Update_Delete_Get_LoadAll_Maven
Add hibernate 3.x jars, Spring 3.x jars, common logggins jars, ojdbc6.jar or ojdbc14 jarHibernate_Pagination_With_Servlet_JSP_Maven
when response for request is too large [If we have 1000โs of records in the database] then instead of displaying all records at a time on browser we can display the response page by page manner using pagination mechanismSpring_Scopes_Singleton_Prototype
Servlet_File_Downloading
Hibernate_custom_random_generator_Maven
We need a Hibernate identifier generator that can take any value that we manually assign, and it can also automatically generate a unique identifier when the entity identifier is null. However, the user does not want to use a UUID-like random identifier. Instead, the user needs to generate a String value that combines a prefix and a numerical value that is obtained from a database sequence.Hibernate_Native_Generator_XML
Native means Your generator will use identity or sequence columns according to what your current database support. Native: This generation strategy is the default. It simply chooses the primary key generation strategy that is the default for the database in question, which quite typically is IDENTITY, although it might be TABLE or SEQUENCE depending upon how the database is configured. The native strategy is typically recommended, as it makes your code and your applications most portable.Hibernate_HQL_Select_Queries_Specific
Hibernate Query Language (HQL) is same as SQL (Structured Query Language) but it doesn't depends on the table of the database. Instead of table name, we use class name in HQL. So it is database independent query language. #Query Interface It is an object oriented representation of Hibernate Query. The object of Query can be obtained by calling the createQuery() method Session interface. The query interface provides many methods. There is given commonly used methods: public int executeUpdate() is used to execute the update or delete query. public List list() returns the result of the ralation as a list. public Query setFirstResult(int rowno) specifies the row number from where record will be retrieved. public Query setMaxResult(int rowno) specifies the no. of records to be retrieved from the relation (table). public Query setParameter(int position, Object value) it sets the value to the JDBC style query parameter. public Query setParameter(String name, Object value) it sets the value to a named query parameter.Hibernate_HQL_UniqueResult_ExecuteUpdate_CopyData_Delete_Update
Don't use 'Query.list()' when you really need 'Query.uniqueResult()' in Hibernate.Spring_Dependency_Check_annotation
Spring_ORM_Java_Configuration
Spring_Constructor_Injection_Constructor_arg
Hibernate_Native_SQL_Scalar_Using_DAO_Using_MAVEN
The most basic SQL query is to get a list of scalars (values) from one or more tables.Spring_Standalone_Application
Spring_Autowiring_XML_byType_byName_Constructor
Hibernate_increment_generator
increment keeps track of id in jvm and increments it within process.Spring_Scope_LookupMethod
Hibernate_Native_SQL_Using_DAO_Using_MAVEN
Documentations
Steps for Different Software InstallationSpring_Autowiring_Annotation_OneMatch_MultipleMatch_Qualifier
JDBC_LargeObjects_BLOB_PSTMT
Spring_Reference
In Spring we need to use <ref> element to inform spring container about the object dependency.Hibernate_ONE-TO-ONE_Mappings_Annotation_Save_Maven
The @OneToOne annotation is used to create the one-to-one relationship between childs and parent. A one-to-one association is similar to many-to-one association with a difference that the column will be set as unique. For example, an address object can be associated with a single employee object.Hibernate_SEQ_HILO_Generator_XML
uses a hi/lo algorithm to efficiently generate identifiers of type long, short or int, given a named database sequence.Servlet_ServletAnnotations_Servlet_JSP
Servlet API 3.0 has introduced a new package called javax.servlet.annotation. It provides annotation types which can be used for annotating a servlet class. If you use annotation, then the deployment descriptor (web.xml) is not required. But you should use tomcat7 or any later version of tomcat. Annotations can replace equivalent XML configuration in the web deployment descriptor file (web.xml) such as servlet declaration and servlet mapping. Servlet containers will process the annotated classes at deployment time.Hibernate_HQL_Select_Queries
Hibernate Query Language (HQL) is same as SQL (Structured Query Language) but it doesn't depends on the table of the database. Instead of table name, we use class name in HQL. So it is database independent query language.Servlet_FileUploading
A Servlet can be used with an HTML form tag to allow users to upload files to the server. An uploaded file could be a text file or image file or any document.Hibernate-_Many-to-Many_Mappings_XML_Save_Load_Maven
A Many-to-Many mapping can be implemented using a Set java collection that does not contain any duplicate element. We already have seen how to map Set collection in hibernate, so if you already learned Set mapping, then you are all set to go with manyto-many mapping. A Set is mapped with a <set> element in the mapping table and initialized with java.util.HashSet. You can use Set collection in your class when there is no duplicate element required in the collection.Spring_Java_Configuration
The central artifact in Spring's new Java-configuration support is the @Configuration-annotated class. These classes consist principally of @Bean-annotated methods that define instantiation, configuration, and initialization logic for objects that are managed by the Spring IoC container. Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. An application may use one @Configuration-annotated class, or many. @Configuration is meta-annotated as a @Component. Therefore, @Configuration-annotated classes are candidates for component-scanning and can also take advantage of @Autowired annotations at the field and method levels, but not at the constructor level. @Configuration-annotated classes must also have a default constructor. You can wire externalized values into @Configuration-annotated classes with the @Value annotation.Servlet_SendRedirect
The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file. It accepts relative as well as absolute URL. It works at client side because it uses the url bar of the browser to make another request. So, it can work inside and outside the server.Servlet_HttpServlet
HttpServlet class HttpServlet class Methods of HttpServlet class The HttpServlet class extends the GenericServlet class and implements Serializable interface. It provides http specific methods such as doGet, doPost, doHead, doTrace etc.Servlet_GenericServlet
GenericServlet class implements Servlet, ServletConfig and Serializable interfaces. It provides the implementation of all the methods of these interfaces except the service method. GenericServlet class can handle any type of request so it is protocol-independent. You may create a generic servlet by inheriting the GenericServlet class and providing the implementation of the service method.Hibernate-Versioning_HQL_Maven
Once an object is saved in a database, we can modify that object any number of times right, If we want to know how many no of times that an object is modified then we need to apply this versioning concept. When ever we use versioning then hibernate inserts version number as zero, when ever object is saved for the first time in the database. Later hibernate increments that version no by one automatically when ever a modification is done on that particular object. In order to use this versioning concept, we need the following two changes in our application Add one property of type int in our pojo class In hibernate mapping file, add an element called version soon after id elementHibernate_UUID_Generator_XML
Most developers prefer numerical primary keys because they are efficient to use and easy to generate. But that doesnโt mean that a primary key has to be a number. UUIDs, for example, have gained some popularity over the recent years. The main advantage of a UUID is its (practical) global uniqueness which provides a huge advantage for distributed systems. If you use the typical, numerical ID that gets incremented for each new record, you need to generate all IDs by the same component of your system or the components need to communicate with each other. With a globally unique UUID, you donโt need all of this. Each component can generate a UUID and there will not be any conflicts.Spring_JDBC_Maven_Save_Update_Delete
Spring JdbcTemplate is a powerful mechanism to connect to the database and execute SQL queries. It internally uses JDBC api, but eliminates a lot of problems of JDBC API.Hibernate_Sequence_Generator_XML
Hibernate_Native_SQL_Maven_Annotation
Hibernate_Association_Mapping_MAP_OneToMany_Save_Delete_Maven
Hibernate_Sequence_Generator_Annotation
It uses the sequence of the database. if there is no sequence defined, it creates a sequence automatically e.g. in case of Oracle database, it creates a sequence named HIBERNATE_SEQUENCE. In case of Oracle, DB2, SAP DB, Postgre SQL or McKoi, it uses sequence but it uses generator in interbase.Hibernate_Association_Mapping_ManyToOne_Save_Load_Maven
Hibernate_ComponentMapping_DAO_ManyToMany_Annotations
Hibernate_Pagination_Using_Servlet_html_Maven_Save
Spring_ORM_Hibernate_save
Hibernate_Association_Mapping_BAG_OneToMany_Save_Delete
Servlet_Context_Interface
An object of ServletContext is created by the web container at time of deploying the project. This object can be used to get configuration information from web.xml file. There is only one ServletContext object per web application. If any information is shared to many servlet, it is better to provide it from the web.xml file using the <context-param> element.JDBC_PREPARED_STATEMENT
The PreparedStatement interface is a subinterface of Statement. It is used to execute parameterized query.Servlet_ServletAttributeListener_Added_Replaced_Removed
Spring_Simple_Spring
Spring FrameworkDATABASE-CONNECTIVITY
Hibernate-_Many-to-Many_Mappings_IDBAG_XML_Save_Maven
Hibernate's <idbag> facility allows you to map many-to-many associations and collections of values to a single table with a surrogate keyHibernate_Association_Mapping_List_OneToMany_Save_Maven
Hibernate_Association_Mapping_BAG_OneToMany_Save_Delete_Maven
Hibernate_Test
Simple Hibernate project with configuration,mapping files with domain/entity classServlet_ServletRequestListener_NoOfClicksCount
Events are basically occurance of something. Changing the state of an object is known as an event. We can perform some important tasks at the occurance of these exceptions, such as counting total and current logged-in users, creating tables of the database at time of deploying the project, creating database connection object etc. There are many Event classes and Listener interfaces in the javax.servlet and javax.servlet.http packages. Event classes The event classes are as follows: ServletRequestEvent ServletContextEvent ServletRequestAttributeEvent ServletContextAttributeEvent HttpSessionEvent HttpSessionBindingEvent Event interfaces The event interfaces are as follows: ServletRequestListener ServletRequestAttributeListener ServletContextListener ServletContextAttributeListener HttpSessionListener HttpSessionAttributeListener HttpSessionBindingListener HttpSessionActivationListenerHibernate_Association_Mapping_Maven_Set_OneToMany_Save_
Spring_Jdbc_Using-Java_Configuration
Java-based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations explained in this chapter. @Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context.Servlet_Filters
A filter is an object that is invoked at the preprocessing and postprocessing of a request. It is mainly used to perform filtering tasks such as conversion, logging, compression, encryption and decryption, input validation etc. The servlet filter is pluggable, i.e. its entry is defined in the web.xml file, if we remove the entry of filter from the web.xml file, filter will be removed automatically and we don't need to change the servlet.Hibernate_CustomGenerator_Custom_StringType_Id_Generation
Spring_Core_InnerBean
Java inner classes are defined within the scope of other classes, similarly, inner beans are beans that are defined within the scope of another bean. Thus, a <bean/> element inside the <property/> or <constructor-arg/> elements is called inner beanHibernate_Inheritance_Mapping_Table_Per_Class_Hierarchy_Using_DAO_Using_Maven
Hibernate Inheritance Mapping Tutorial Table Per Hierarchy Table Per Concrete class Table Per Subclass We can map the inheritance hierarchy classes with the table of the database. There are three inheritance mapping strategies defined in the hibernate: 1.Table Per Hierarchy 2.Table Per Concrete class 3.Table Per SubclassServlet_Applet_Communication
Similar to HTML-to-servlet communication we need to perform applet-to servlet communication. In HTML-to-servlet communication the browser window automatically forms request URL and automatically forms query string having form data, when submit button is clicked. In applet-to-servlet communication all these activities should be taken care of by the programmers manually or explicitly as event handling operation.Hibernate_Component_Mapping_Using_DAO_Using_Maven
Hibernate - Component Mappings---> In component mapping, we will map the dependent object as a component. An component is an object that is stored as an value rather than entity reference. This is mainly used if the dependent object doen't have primary key. It is used in case of composition (HAS-A relation), that is why it is termed as component.Servlet_RequestDispatcher_Forward_WebLogic_Server
To forward the client request to another Servlet to honour (that is, client calls a Servlet but response to client is given by another Servlet). RequestDispatcher forward() Method When to use RequestDispatcher forward() method? Client calls a Servlet for some information. But the Servlet cannot honour the request because it is incapable. But it knows that another Servlet exists which can do the job of the client. Then how the first Servlet (called by the client) can send (forward) the request to another Servlet. Here, forward() method of RequestDispatcher is used. void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException: Forwards a request from a Servlet to another resource (Servlet, JSP file, or HTML file) on the server. This method allows one Servlet to do preliminary processing of a request and another resource to generate the response.Servlet_Config_Interface
ServletConfig Interface An object of ServletConfig is created by the web container for each servlet. This object can be used to get configuration information from web.xml file. If the configuration information is modified from the web.xml file, we don't need to change the servlet. So it is easier to manage the web application if any specific content is modified from time to time.JDBC_SCROLLABLE_RESULTSET
By default a ResultSet Interface is Non-Scrollable, In non-scrollable ResultSet we can move only in forward direction (that means from first record to last record), but not in Backward Direction, If you want to move in backward direction use Scrollable Interface.Hibernate_Service_Registry_BootStrapping
Service : Services are classes that provide Hibernate with pluggable implementations of various types of functionality. Specifically they are implementations of certain service contract interfaces ServiceRegistry : The central service API, aside from the services themselves, is the org.hibernate.service.ServiceRegistry interface. The main purpose of a service registry is to hold, manage and provide access to services.Hibernate_Inheritance_Mapping_Table_Per_Sub_Class_XML_Using_DAO_Using_Maven
In case of Table Per Subclass, subclass mapped tables are related to parent class mapped table by primary key and foreign key relationship. The <joined-subclass> element of class is used to map the child class with parent using the primary key and foreign key relation. In this example, we are going to use hb2ddl.auto property to generate the table automatically. So we don't need to be worried about creating tables in the database.Servlet_GenericServlet_Date
GenericServlet class implements Servlet, ServletConfig and Serializable interfaces. It provides the implementation of all the methods of these interfaces except the service method. GenericServlet class can handle any type of request so it is protocol-independent. You may create a generic servlet by inheriting the GenericServlet class and providing the implementation of the service method.Servlet_RequestDispatcher_Include_WebLogic_Server
The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp. This interface can also be used to include the content of another resource also. It is one of the way of servlet collaboration.Hibernate-_Many-to-Many_Mappings_Annotation_Save_Load_Maven
A Many-to-Many mapping can be implemented using a Set java collection that does not contain any duplicate element. We already have seen how to map Set collection in hibernate, so if you already learned Set mapping, then you are all set to go with manyto-many mapping. A Set is mapped with a <set> element in the mapping table and initialized with java.util.HashSet. You can use Set collection in your class when there is no duplicate element required in the collection.JSP_Servlet_Include_Page_Directive
The include directive is used to include the contents of any resource it may be jsp file, html file or text file. The include directive includes the original content of the included resource at page translation time (the jsp page is translated only once so it will be better to include static resource).Hibernate_Pagination_HQL_Maven_Simple
when response for request is too large [If we have 1000โs of records in the database] then instead of displaying all records at a time on browser we can display the response page by page manner using pagination mechanism In pagination, initially one page response will be displayed and we will get links for getting the next pages responseJBOSS_Sample_Servlet
JBoss is a division of Red Hat that provides support for the WildFly open source application server program (formerly called JBoss AS) and related middleware services. JBoss is an open source alternative to commercial offerings from IBM WebSphere and SAP NetWeaver.Hibernate_Inheritance_Mapping_concreteClass_UnionSubClassDAO_Maven
In case of Table Per Concrete class, there will be three tables in the database having no relations to each other. There are two ways to map the table with table per concrete class strategy. By union-subclass element By Self creating the table for each classSpring_Life_Cycle_Init_Destroy_Using_XML
You can define initialization and destroy methods with in the spring bean. You can configure it using init-method, and destroy-method in the xml based configuration file. These are part of spring bean life cycle. The initialization method will be called immediately after bean creation, and destroy method will be called before killing the bean instanceHibernate_Criteria_Queries_Using_DAO_Using_MAVEN
Hibernate provides alternate ways of manipulating objects and in turn data available in RDBMS tables. One of the methods is Criteria API, which allows you to build up a criteria query object programmatically where you can apply filtration rules and logical conditions. The Hibernate Session interface provides createCriteria() method, which can be used to create a Criteria object that returns instances of the persistence object's class when your application executes a criteria query. Following is the simplest example of a criteria query is one, which will simply return every object that corresponds to the Employee class. Criteria cr = session.createCriteria(Employee.class); List results = cr.list(); Restrictions with Criteria You can use add() method available for Criteria object to add restriction for a criteria query. Following is the example to add a restriction to return the records with salary is equal to 2000 โ Criteria cr = session.createCriteria(Employee.class); cr.add(Restrictions.eq("salary", 2000)); List results = cr.list();Spring_Static_Factory_Method
next โโ prev Dependency Injection with Factory Method in Spring Spring framework provides facility to inject bean using factory method. To do so, we can use two attributes of bean element. factory-method: represents the factory method that will be invoked to inject the bean. factory-bean: represents the reference of the bean by which factory method will be invoked. It is used if factory method is non-static. A method that returns instance of a class is called factory method.Hibernate_Association_Mapping_Maven_Set_OneToMany_ManyToOne_Bidirection_Save_Load
Hibernate_Composite_Primary_Key_MAVEN_Annotation
To map a composite key, you can use the EmbeddedId or the IdClass annotations.Hibernate_Association_Mapping_Maven_Set_OneToMany_FK_PK_Save_Load
Servlet_Forward_Mechanism_DAO_DTO_ConnectionFactory_Entity_WebLogic_Server
Spring_Stereotype_Annotation_Value_Maven
Pass the value to the variables through @Value Annotation. Annotation Used @Component, @Value, @AutowiredConnection_Commit_Rollback
If your JDBC Connection is in auto-commit mode, which it is by default, then every SQL statement is committed to the database upon its completion.Hibernate_Unique_Constraint_Annotation
UniqueConstraint Specifies that a unique constraint is to be included in the generated DDL for a primary or secondary table.Spring_Stereotype_Annotation
@Component Indicates that an annotated class is a "component". Such classes are considered as candidates for auto-detection when using annotation-based configuration and classpath scanning. Other class-level annotations may be considered as identifying a component as well, typically a special kind of componentSpring_reference_tag
In Spring, beans can โaccessโ to each other by specify the bean references in the same or different bean configuration file. Actually, the โrefโ tag can access to a bean either in same or different XML files, however, for the project readability, you should use the โlocalโ attribute if you reference to a bean which declared in the same XML file.Hibernate_Validation_API_Annotation_Simple
Itโs very easy to use Hibernate Validator and best part is that we can easily extend it and create our own custom validation annotations. Today we will look into the hibernate validator in detail with examples. Finally we will have a test program to check out the validations.Hibernate_Large_Objects_Maven_BLOB_CLOB
This tutorial shows you how to map byte array (byte[]) or Binary Large Object (java.sql.Blob) of Java type to database type using Hibernate ORM framework. Byte array or Blob can be used to store large binary data such as files and images. According to Hibernate Types: A primitive byte[] is mapped to a JDBC VARBINARY. A java.sql.Blob is mapped to a JDBC BLOB.Hibernate_Date_Annotation
When you save date to the database using hibernate, the date is converted to local time and stored. Suppose your date is '12-08-2017' ,hibernate inserts it into database in default format of"yyyy-mm-dd". Timestamp format is yyyy-mm-dd hh:mm:ss. Timestamp format takes 4 byte whereas DtaeTimeFormat takes 8 byte. Hibernate provides date type annotation which takes format 'yyyy-mm-dd'Servlet_ServletWrappers
Wrappers are required because the current implementation of the interface is container specific and hence you cannot extend them. However you can extend the wrappers and override only those methods that are required to be changed. The remaining method calls will be delegated to the container implementation. You may also implement the interfaces from scratch on your own, but that would be a very difficult and time consuming task.Spring_Bean_Externalization_propertiesFile
In case of XML, simply create bean for PropertyPlaceholderConfigurer and set the location of property file to externalize. In case of annotation, we need to create static bean of PropertyPlaceholderConfigurer in java configuration. PropertyPlaceholderConfigurer is used to resolve ${...} placeholders against a property. It can be local properties or system properties or environment variables. We can use PropertyPlaceholderConfigurer using XML as well as annotation. PropertyPlaceholderConfigurer externalizes the property configuration. Setting hard coded property values in our code is not good coding style. Properties should be configured in a property file inside or outside application. So that changing properties frequently will not cause to change the code.Servlet_ServletSecurity_Authentication_JSP
JavaServer Pages and servlets make several mechanisms available to Web developers to secure applications. Resources are protected declaratively by identifying them in the application deployment descriptor and assigning a role to them. Several levels of authentication are available, ranging from basic authentication using identifiers and passwords to sophisticated authentication using certificates. Role Based Authentication The authentication mechanism in the servlet specification uses a technique called role-based security. The idea is that rather than restricting resources at the user level, you create roles and restrict the resources by role. You can define different roles in file tomcat-users.xml, which is located off Tomcat's home directory in confJDBC_RESULTSET
The SQL statements that read data from a database query, return the data in a result set. The SELECT statement is the standard way to select rows from a database and view them in a result set. The java.sql.ResultSet interface represents the result set of a database query. A ResultSet object maintains a cursor that points to the current row in the result set. The term "result set" refers to the row and column data contained in a ResultSet object.Spring_Constructor_Injection_C_Schema
Spring_Java_Configuration_HAS-A
Java-based configuration option enables you to write most of your Spring configuration without XML but with the help of few Java-based annotations explained in this chapter. @Configuration & @Bean Annotations Annotating a class with the @Configuration indicates that the class can be used by the Spring IoC container as a source of bean definitions. The @Bean annotation tells Spring that a method annotated with @Bean will return an object that should be registered as a bean in the Spring application context.Hibernate_Inheritance_Mapping_concreteClass_UnionSubClassDAO_Implicit_Polymorphism_Maven
Hibernate_Association_Mapping_Joins_Set_OneToMany_ManyToOne_Bi_Inner_Left_Right
We use join statements, to select the data from multiple tables of the database, when there exist relationship with joins, its possible to select data from multiple tables of the database by construction a single query Hibernate supports 4 types of joins.. Left Join Right Join Full Join Inner Join the DEFAULT join in hibernate is Inner join Left join means, the objects from both sides of the join are selected and more objects from left side are selected, even though no equal objects are there at right side Right join means equal objects are selected from database and more objects are from right side of join are selected even though there is no equal objects are exist left side Full join means, both equal and un-equal objects from both sides of join are selected Inner join means only equal objects are selected and the remaining are discarded At the time of construction the join statements, we need to use the properties created in pojo class to apply relationship between the objects To construct a join statement, we use either HQL, or NativeSqlLove Open Source and this site? Check out how you can help us