Сибирские интеграционные системы
AngularSIS #1.18 - https://www.youtube.com/playlist?list=PLmEQRj1_Mt5fkeBYOw1o8k_o8-7POFZJN JavaSIS #2.19 - https://www.youtube.com/playlist?list=PLmEQRj1_Mt5f5MlXGlf5kzldb9Rl8Pwuo
Владимир
Лебедко
Спецификация
Вошла в EJB3
Первая версия JPA была выпущена 11 мая 2006 года
Текущая версия JPA 2.1 22 апреля 2013 года
<persistence ... version="2.0">
<persistence-unit name="my-pu">
<description>My Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<mapping-file>META-INF/mappingFile.xml</mapping-file>
<jar-file>packedEntity.jar</jar-file>
<class>sample.Book</class>
....
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:test" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="123" />
...
<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="show_sql" value="true"/>
</properties>
</persistence-unit>
</persistence>
Persistance.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<entity class="samples.Book"
access="FIELD" name="Book">
<attributes>
<id name="id"/>
<basic name="book_name"/>
<basic name="author_id"/>
</attributes>
</entity>
</entity-mappings>
spring.datasource.url=jdbc:h2:file:./data/jokes
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.h2.console.enabled=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=validate
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect
@Entity
@Table(name = "Book")
@Entity
@Table(name = "book")
public class Book {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "book_name")
private String bookName;
@ManyToOne
@JoinColumn(name = "author_id")
private Author author;
@OneToMany(mappedBy = "book", fetch = FetchType.LAZY)
private List<Page> pages;
}
@ManyToOne @OneToMany
Query query = entitymanager.createQuery("from Book");
List<Book> list=query.getResultList();
SessionFactory - EntityManagerFactory
Session - EntityManager
HQL - JPQL
By Сибирские интеграционные системы
ORM JPA HIBERNATE