Hibernate&EJB3 Studybook For students of university Author Sr.Java developer Dudnik Oxana.

Презентация:



Advertisements
Похожие презентации
1 © Luxoft Training 2012 Inner and anonymous classes.
Advertisements

Work with databases in Java. JDBC Tutorial for students of universities Author: Dudnik Oxana.
Work with database Oracle in Java Author: Dudnik Oxana.
Java Collections Framework (JCF) in Java Tutorial for students of universities Author: Oxana Dudnik.
WHAT IS THE SCHOOL?. ? WHAT IS THE MAIN AIM OF OUR LESSON.
My cat's name is Mura. Mura - capricious animal. If he is in good mood, he plays, he lets himself be ironed, but if he has a bad mood, he warns about.
Inner Classes. 2 Simple Uses of Inner Classes Inner classes are classes defined within other classes The class that includes the inner class is called.
If you are ready for the lesson, let's start. What kinds of schools do you know? Public school State school Boarding school All – boys school All – girls.
Psychological help for teens I want to create an organization where specialists will help teenagers to solve their problems with parents.
Hello from Russia! OUR SCHOOL This project is made for our American friends. We would like to tell you a little about our school in Kurganinsk.
Unit II Constructor Cont… Destructor Default constructor.
11 BASIC DRESS-UP FEATURES. LESSON II : DRESS UP FEATURES 12.
1/27 Chapter 9: Template Functions And Template Classes.
A class is just a collection of variables--often of different types--combined with a set of related functions. The variables in the class are referred.
Name: Yogesh Mehla Website: Phone:
What is happening in this picture? What do you think Tom is thinking? Bob? Tom Bob Blah, blah, blah… Mm m mm m m …
SOUND a range of compression wave frequencies to which the human ear is sensitive.
Taking out Money from a Cash Machine Authors: Aleksey Ermolaev, Daria Zaitseva, Maria Leontyeva, Anatoly Leshchev, Form 10 pupils Teacher: V. V. Sergoushina,
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Constructing Network Addresses Calculating Subnet Masks.
1/30 Chapter 8: Dynamic Binding And Abstract classes.
Транксрипт:

Hibernate&EJB3 Studybook For students of university Author Sr.Java developer Dudnik Oxana

Student //Entity annotation represents that it is an entity //class and is //mapped to a table in database. Table //annotation tells about the //table name to which this entity public class Student { //Id will correspond the primary key in the //database private Long id; protected String name; //Id - Represents that it is a primary key column //GeneratedValue - How the key to be //generated //column - Column to which this property = public Long getId() { return id; } public void setId(Long id) { this.id = id; } //There is annotation here so by default it is //mapped to //the column with name NAME. In annotation, //the properties are //by default mapped. In XML mapping by //default the columns //are not mapped. public String getName() { return name; } public void setName(String name) { this.name = name; } Бизнес - модель данных

persistence.xml (Put in META-INF folder under source folder) org.hibernate.ejb.HibernatePers istence

public class HibernateMappingJPA { public static void main(String[] args) { //The name hibernateMapping comes from persistence.xml EntityManagerFactory emf = Persistence.createEntityManagerFactory ("hibernateMapping"); EntityManager em =emf.createEntityManager(); EntityTransaction tx = em.getTransaction(); tx.begin(); Student student = new Student(); student.setName("James Bond"); em.persist(student); Query query = em.createQuery("Select s from Student s where s.name like ?"); query.setParameter(1, "James%"); List studentList=query.getResultList(); for(Student s :studentList){ System.out.println(s.getName()); } tx.commit(); em.close(); } Note that we do not have to map the entity class explicitly as these are scanned automatically based on annotation. More write-ups More write-ups

Успехов!