step1: open dilsecodie
step 2 : check https://dilsecodie.com/sourcecode/topic/Java/tutorial/Criteria
step 3 : can change class name for any entity to get result .
step 4 : This only work Hibernate Criteria
step 5: Can be used in any serviceImp class
For hibernate, cover all the advanced concepts as well, including transaction management, session handling, isolation, caching. The many to one, one to many mappings,
how to make joins in entities, how to write criteria for join queries etc
Java Persistence API, that is, JPA is a specification whereas Hibernate is its implementation.
JPA provides the abstraction over the specific ORM. It provides the APIs that are implemented by the ORM. It's like an interface. You write an implementation of it. Then use the interface references to keep the objects of its implementation(s).
The advantage of using it is that you can replace the ORM in your application because-
You would be using the JPA interfaces to wire the entity manager in your repository classes.
To write the queries you'd be using JPQL or the JPA Criteria.
Thus making your code independent of the underlying ORM
Criteria c = this.sessionFactory.getCurrentSession().createCriteria(Test.class)
.add(Restrictions.eq("do_name", doName)).
add(Restrictions.eq("test_name",TestName));
return c.list();
There is no such thing as Spring JPA. JPA is the Java Persistence API and it is only a specification.
Spring Data JPA makes it easy to implement JPA-based repositories and you can use them along with an ORM, such as Hibernate, or not
Session–Cache or collection of loaded objects relating to a single unit of work
XDoclet Annotations used to support Attribute Oriented Programming
Defines HQL for expressing queries to the database
Supports Entity Relationships through mapping files and annotations in JavaDoc
Provides a Persistence Manager API exposed via the Session, Query, Criteria, and Transaction API
Provides callback support through lifecycle, interceptor, and validatable interfaces
Entity Relationships are unidirectional. Bidirectional relationships are implemented by two unidirectional relationships.
The exceptions of JDBC are checked. We must place them in try catch blocks. It is a burden to programmar.
After completion of the source code of the project, If a table structure is altered then we need to modify all the queries wherever they are placed in project. It is a time consuming process.
In JDBC persistance logic we use SQL commands suppose if database is changed then SQL commands also need to be changed means JDBC persistance logic is database dependent.
The primary responsibility of hibernate is transferring the data between Java and database in the form of objects. It is a light weight ORM and DAO layer framework. Hibernate is non invasive which does not force programmar to extend any class or implement any interface. Here in hibernate we use HQL(hibernate query language). It is database independent which reduces burden on developers. HQL queries are converted to database-specific commands by hibernating at runtime.
There are many features like caching, lazy loading, Criteria, Locking, Filters, connection pooling are available in Hibernate.
Hibernate: wherever lots of Edit update, Delete is required we always prefer to hibernate basically every data is coming from Java Object and even though it is very simple to save data. just like set value into Bean class and call save(POJORef); that will save the data.
Some of the important points remember while doing a practical
Always follow coding guidelines
always catch Exceptions.
write log statement for checking purposes.
No comments:
Post a Comment