Презентация, доклад на тему Hibernate, fundamentals. Part 3. Для студентов старших курсов университета

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 is mapped@Entity@Table(name="Student")public class Student {     //Id will correspond

Слайд 1Hibernate&EJB3
Studybook
For students of university
Author Sr.Java developer Dudnik Oxana

Hibernate&EJB3StudybookFor students of universityAuthor Sr.Java developer Dudnik Oxana

Слайд 3Student //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 is mapped
@Entity
@Table(name="Student")
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 is //mapped
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="STUDENT_ID")    
    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;
    }
}

Бизнес - модель данных

Student  //Entity annotation represents that it is an entity //class and is//mapped to a table in

Слайд 4persistence.xml (Put in META-INF folder under source folder)

           xmlns="http://java.sun.com/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
             http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
 
        org.hibernate.ejb.HibernatePersistence
       
           
           
           
           
       

   



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

Слайд 5public 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 the @Entity annotation. More write-ups
public class HibernateMappingJPA {    public static void main(String[] args) { //The name hibernateMapping comes from persistence.xmlEntityManagerFactory

Слайд 6Успехов!

Успехов!

Что такое shareslide.ru?

Это сайт презентаций, где можно хранить и обмениваться своими презентациями, докладами, проектами, шаблонами в формате PowerPoint с другими пользователями. Мы помогаем школьникам, студентам, учителям, преподавателям хранить и обмениваться учебными материалами.


Для правообладателей

Яндекс.Метрика

Обратная связь

Email: Нажмите что бы посмотреть