More Related Content Similar to Hibernate&ejb3 . part3. Similar to Hibernate&ejb3 . part3. (20) More from Asya Dudnik (6) Hibernate&ejb3 . part3.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")
Бизнес -
модель данных
4. • persistence.xml (Put in META-INF folder under
source folder)
<?xml version="1.0" encoding="UTF-8"?>
• <persistence version="1.0"
•
xmlns="http://java.sun.com/xml/ns/persistence"
•
xmlns:xsi="http://www.w3.org/2001/XMLSche
ma-instance"
•
xsi:schemaLocation="http://java.sun.com/xml/n
s/persistence
5. • public class HibernateMappingJPA {
• public static void main(String[] args) {
• //The name hibernateMapping comes from
persistence.xml
• EntityManagerFactory emf =
•
Persistence.createEntityManagerFactory("hiber
nateMapping");
•
• EntityManager em =emf.createEntityManager();
• EntityTransaction tx = em.getTransaction();
• tx.begin();