0% found this document useful (0 votes)
2 views5 pages

Advance 3 Java

The document provides an overview of Hibernate, a Java framework for database interaction, detailing its lifecycle states: Transient, Persistent, Detached, and Removed. It also introduces the JavaMail API, which facilitates building mail applications and supports various protocols like SMTP, POP, and IMAP. Additionally, it discusses Spring's method injection for dependency management and outlines different types of Hibernate transactions.

Uploaded by

apple
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Advance 3 Java

The document provides an overview of Hibernate, a Java framework for database interaction, detailing its lifecycle states: Transient, Persistent, Detached, and Removed. It also introduces the JavaMail API, which facilitates building mail applications and supports various protocols like SMTP, POP, and IMAP. Additionally, it discusses Spring's method injection for dependency management and outlines different types of Hibernate transactions.

Uploaded by

apple
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1HIBERNATE-

Hibernate is a Java framework that simplifies the development of Java application


to interact with the database. It is an open source, lightweight, ORM (Object
Relational Mapping) tool. Hibernate implements the specifications of JPA (Java
Persistence API) for data persistence.
HIBERNATE LIFECYCLE-
Hibernate Lifecycle Here we will learn about Hibernate Lifecycle or in other
words, we can say that we will learn about the lifecycle of the mapped instances
of the entity/object classes in hibernate.
There are mainly four states of the Hibernate Lifecycle :
1. Transient State
2. Persistent State
3. Detached State
4. Removed State

State 1: Transient State The transient state is the first state of an entity object.
When we instantiate an object of a POJO class using the new operator then the
object is in the transient state. This object is not connected with any hibernate
session. As it is not connected to any Hibernate Session
1. When objects are generated by an application but are not connected to any
session.
2. The objects are generated by a closed session.
State 2: Persistent State –
Once the object is connected with the Hibernate Session then the object moves
into the Persistent State. So, there are two ways to convert the Transient State to
the Persistent State :
1. Using the hibernated session, save the entity object into the database
table.
2. 2. Using the hibernated session, load the entity object into the database
table.
Methods-
[Link](e);
[Link](e);
[Link](e);
State 3: Detached State-
For converting an object from Persistent State to Detached State, we either
have to close the session or we have to clear its cache. As the session is
closed here or the cache is cleared, then any changes made to the data will
not affect the database table. Whenever needed, the detached object can be
reconnected to a new hibernate session.
Methods-
merge()
• update()

• load()
State 4: Removed State-
In the hibernate lifecycle it is the last state. In the removed state, when the
entity object is deleted from the database then the entity object is known to
be in the removed state. It is done by calling the delete() operation.
MAIL API-

The JavaMail API provides a platform-independent and protocol-


independent framework to build mail and
messaging applications. The JavaMail API provides a set of abstract classes
defining objects that comprise a mail
system. It is an optional package (standard extension) for reading,
composing, and sending electronic messages.
JavaMail provides elements that are used to construct an interface to a
messaging system, including system
components and interfaces. While this specification does not define any
specific implementation, JavaMail does
include several classes that implement RFC822 and MIME Internet
messaging standards. These classes are
delivered as part of the JavaMail class package.
Following are some of the protocols supported in JavaMail API:
 SMTP: Acronym for Simple Mail Transfer Protocol. It provides a
mechanism to deliver email.
 POP: Acronym for Post Office Protocol. POP is the mechanism most
people on the Internet use to get their
mail. It defines support for a single mailbox for each user. RFC 1939
defines this protocol.
 IMAP: Acronym for Internet Message Access Protocol. It is an advanced
protocol for receiving messages. It
provides support for multiple mailbox for each user, in addition to, mailbox
can be shared by multiple users. It is
defined in RFC 2060.
 MIME: Acronym for Multipurpose Internet Mail Extensions. . It is not a
mail transfer protocol. Instead, it defines
the content of what is transferred: the format of the messages,
attachments, and so on. There are many different
documents that take effect here: RFC 822, RFC 2045, RFC 2046, and RFC
2047. As a user of the JavaMail API,
you usually don't need to worry about these formats. However, these
formats do exist and are used by your
programs.
 NNTP and Others:There are many protocols that are provided by third-
party providers. Some of them are
Network News Transfer Protocol (NNTP), Secure Multipurpose Internet Mail
Extensions (S/MIME) etc.

Spring Method Injection


Similar to field injection, Spring allows method dependency injection to
inject the dependency into the bean. Spring uses primarily two types of
dependency injection: Constructor and Setter Injection but we can also use
another injection technique called method injection. The method injection
is similar to setter injection except that method can be any regular
method. It uses the @Autowired annotation to mark a method as method
injection.

// [Link]
This file contains code to create an IOC container for our application. The
AnnotationConfigApplicationContext class is used to create an object for
application context.
// [Link]
This is a configuration file in Java which is an alternate of
the [Link] file that we created for the XML-based
configuration example. The @Configuration annotation indicates that this is
not a simple class but a configuration class and
the @ComponentScan annotation is used to indicate the location of the
component class in our spring project
/ [Link]
This is a component class that will be read by the Spring IOC container.
// [Link]
This is another component class and it implements the Writer interface.
This class uses @Autowired annotation with method to implement method
dependency injection and no setter method is created only the getter
method is created.
// [Link]
This is another component class and it implements the Writer interface.
This class uses @Autowired annotation with the method to implement
method dependency injection and no setter method is created only the
getter method is created.

// [Link]
It is an interface that contains two methods and each class that
implements it will have to implement its methods as well.
// [Link]
This file contains all the dependencies of this project such as spring jars,
servlet jars, etc. Put these dependencies into your project to run the
application
.
Different typea of Hibernate Transaction

1. void begin() starts a new transaction.

2. void commit() ends the unit of work unless we are in [Link].

3. void rollback() forces this transaction to rollback.

4. void setTimeout(int seconds) it sets a transaction timeout for any


transaction started by a subsequent call to begin on this instance.

5. boolean isAlive() checks if the transaction is still alive.

6. void registerSynchronization(Synchronization s) registers a user


synchronization callback for this transaction.

7. boolean wasCommited() checks if the transaction is commited


successfully.

8. boolean wasRolledBack() checks if the transaction is rolledback


successfully

You might also like