Professional Documents
Culture Documents
Spring
Spring
3 types of Configuration:-
1)xml
2)Annotations
3)Java Configuration.
Maven project:-
1) Right click in the project explorer tab and new->maven->Maven-project
2) Select the default workspace and continue.
3) Enter the
Group id
Artifact id
Name (same as artifact id)
Continue.
4) in pom.xml file add dependencies ie spring-core and spring-context (take content
from net search mvnrepository->1st link->search Spring->select version->copy
content from net and paste under dependencies in pom.xml file.
//this will read the specified file,no errors should be present in beans.xml
otherwise ApplicationContext will be created successfully.
ApplicationContext context=new
ClassPathXmlApplicationContext("classpath:beans.xml");
A a = context.getBean(A.class);
If parameters are optional then use settors,if mandatory then use constructor.
Annotations:-
Annotations used mostly here as compared to xml.
@Component or @Service
@Autowired (does wiring by type)
(in beans.xml)
<context:component-scan base-package="com.ibm"></context:component-scan>
In one test case file, various test cases can be made and their order is not fixed.
Maven install will build and place it into the local repository.
Maven deploy will build and place it into the server where it woould be deployed.
***********************************************************************************
******************
JDBC used for database connectivity.
it does not provide full database independency.As all DB has different syntax.
ORM (object to relation mapping) ie hybernate is layer before JDBC that provides
full data independence.
HYBERNATE:-
Everything related to connections should always be present in the xml file
(hybernate.config.xml)
Coloumn name can be different from the field in class using the @Colounm
annotations
create,update,insert and delete operations all are run through functions of session
object.
If not function then createQuery(), this type is called named query.
Hybernate
1)update
2)fetch all employees
3)Max salary
4)acc to name fetch details
5)count total no of emp
EXAM (MCQ)
***********************************************************************************
********************************
Integrating SPRING and HYBERNATE together
Initially do all the steps required for the Spring. i.e Employee class, beans.xml
etc.
JPA is the set of interfaces.
real classes are present in Hibernate.
JPA can use different types of ORM, here we are using Hibernate.
SessionFactory is called EntitYManagerFactory
Session is called EntitYManager
Hibernate-config.xml is called here as persistence.xml
Right click on project Configure->Convert to JPA project
or
Create a folder in resources name META-INF, a file named persistence.xml is
created.
***********************************************************************************
**************************
dell->eclipse-workspace1->SpringHiberanteDemo2
(User is associated with course. One to one and one to many relationship present.)
Cascade used to create the address first and then mapped to employee.
NamedQuery:- query has a name and can be used anywhere using this logical name. It
is used for code Reusability.
HQL queries in Hibernate.
JPQL(java persistence query language)
Inheritance in JPA:-
1)Single Table strategy.But normalization notb present.
2)Table per class.Redundancy present.
3)Joined. Whatever type of emp, for id and name it will go in the emp
table,Foreign key needed.