Spring provides many ways to interact with a database and perform various operations on it. One of the approach using DriverManagerDataSource was discussed in a previous post. The above approach…
What is Interceptor? An interceptor in a web application is a component which is the first to receive a request. All requests to the application first arrive at the interceptor…
What does mapping an Entity to database table mean ? A Java class represents an Entity in ORM terminology. Mapping an Entity to a table means associating the java class(which…
Imagine you are working on a Spring application where most of the objects are created using Spring annotations and fields are also injected using Spring mechanisms (using
@Autowired or XML configuration). Now you develop a component or use an API which is written without any use of Spring and you need one of your Spring managed classes in it. (more…)
Hibernate framework is used for interacting with database records as Java Objects and vice-versa. It saves/updates java objects as database records, fetches database records as java objects etc. Hibernate performs database interaction using its Session objects. Session objects are retrieved with the help of a SessionFactory. This SessionFactory is related to a particular database.
It’s a common method to use a configuration file where database connection details, mapped entity details are provided which we commonly call as hibernate.cfg.xml or hibernate.properties.
It is a common belief that to start using hibernate we have to use a configuration file. But let me tell you that it is also possible to completely omit this file and configure hibernate alongwith a particular database directly from the code. Let’s see how: (more…)
When sending data from UI to server, generally a DTO (data object) is used. But when saving to database, it must be converted to an entity which means that the values of properties from dto should be copied to the entity object.
This can be done using utility methods of BeanUtils class in Spring as: