Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify ORM guide #1058

Merged
merged 1 commit into from
Feb 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 2 additions & 72 deletions docs/src/main/asciidoc/hibernate-orm-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -153,32 +153,8 @@ If you have a `persistence.xml`, then you cannot use the `quarkus.hibernate.*` p
and only persistence units defined in `persistence.xml` will be taken into account.
--

In your `pom.xml`, add the following dependencies:

* the Hibernate ORM extension
* your JDBC driver extension (`quarkus-jdbc-postgresql-deployment`, `quarkus-jdbc-h2-deployment`, `quarkus-jdbc-mariadb-deployment`, ...)

[source,xml]
--
<dependencies>
<!-- Hibernate ORM specific dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-deployment</artifactId>
<scope>provided</scope>
</dependency>

<!-- JDBC driver dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql-deployment</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
--

Annotate your persistent objects with `@Entity`
then add your `persistence.xml` in `META-INF`:
Your `pom.xml` dependencies as well as your Java code would be identical to the precedent example. The only
difference is that you would specify your Hibernate ORM configuration in `META-INF/persistence.xml`:

[source,xml]
--
Expand Down Expand Up @@ -212,52 +188,6 @@ then add your `persistence.xml` in `META-INF`:
</persistence>
--

A `EntityManagerFactory` will be created based on {project-name} `datasource` configuration as long as the Hibernate ORM extension is declared in your `pom.xml`.

You can then happily inject your `EntityManager`:

[source,java]
--
@ApplicationScoped
public class SantaClausService {
@Inject private EntityManager em; <1>

@Transactional <2>
public void createGift(String giftDescription) {
Gift gift = new Gift();
gift.setName(giftDescription);
em.persist(gift);
}
}

//and of course our entity
@Entity
public class Gift {
private Long id;
private String name;

@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="giftSeq")
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
--

<1> Inject your entity manager and have fun
<2> Mark your CDI bean method as `@Transactional` and the `EntityManager` will enlist and flush at commit.

== Caching

Applications that frequently read the same entities can see their performance improved when the Hibernate ORM second-level cache is enabled.
Expand Down