Submitted by sneha on Sun, 04/15/2018 - 06:09
Submitted by sneha on Sun, 04/15/2018 - 06:08
An entity is a type on its own and has an existence of its own (e.g. Course, User etc.).
A value type is a type which doesn't have existence of its own, but belongs to an entity (e.g. Address of an User). Value types are always completely owned by their containing entity.
Defining entities and value types in Hibernate
@Entity annotation (javax.persistence.Entity) over the class tell hibernate to treat this class as our entity class that needs to be saved.
Submitted by sneha on Sun, 04/15/2018 - 06:07
Here we will discuss most commonly used basic annotations in hibernate - @Entity, @Table, @Id, @GeneratedValue, @Column, @Basic, @Transient, @Temporal and @Lob. Even though many annotations has both JPA (java.persistance) and hibernate (org.hibernate) versions, it is preferred to use JPA annotations whenever possible. As you can see below, some of the hibernate specific annotations are already deprecated.
Submitted by sneha on Sun, 04/15/2018 - 06:06
A java object within a hibernate application can be in one of the three states:
Important points about object states in Hibernate
Submitted by sneha on Sun, 04/15/2018 - 06:04
CRUD operations are Create(save), Read(select), Update(update) and Delete(delete).
Examples discussed here need to be tried out on top of the lab done @ http://javajee.com/lab-your-first-hibernate-43-program.
Select, Save, update and delete operations in hibernate should be called within a session:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Submitted by sneha on Sun, 04/15/2018 - 06:03
You have different logging options in Hibernate and let us see some of those options quickly. Hibernate supports simple property based log enabling to supporting standard logging frameworks and even programmatically accessing log statistics.
First, you can enable showsql property in Hibernate to see the exact query being executed. You can set the property to true in the hibernate.cfg.xml XML configuration file. Please refer to http://javajee.com/lab-your-first-hibernate-43-program.
Submitted by sneha on Sun, 04/15/2018 - 05:54
In JPA, the EntityManager controls the lifecycle of the entities.
Different ORM vendors provide its own entity manager, which is usually a wrapper around the core API and thus supports the JPA programming interfaces, life cycles and query language.
You obtain the EntityManager from an entity manager factory. EntityManagerFactory has the same role as SessionFactory in Hibernate.
Submitted by sneha on Sun, 04/15/2018 - 05:53
Before working with hibernate in your code, you will need to configure Hibernate with information regarding your database such as host, port, credentials etc. You also need to create mappings that tell hibernate how to map the state of a Java entity to the columns of its corresponding table.
We can configure various hibernate features either through annotations or through xml files (hbm files). Preferred approach currently is annotations.
You can configure Hibernate mainly in three ways:
Submitted by sneha on Sun, 04/15/2018 - 05:52
We will write a simple hibernate application to get started with hibernate.
Before starting, you should:
Submitted by sneha on Sun, 04/15/2018 - 05:48