This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NamedStoredProcedureQuery( | |
name = "calculate", | |
procedureName = "calculate", | |
parameters = { | |
@StoredProcedureParameter(mode = ParameterMode.IN, type = Double.class, name = "x"), | |
@StoredProcedureParameter(mode = ParameterMode.IN, type = Double.class, name = "y"), | |
@StoredProcedureParameter(mode = ParameterMode.OUT, type = Double.class, name = "sum") | |
} | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set input parameter | |
query.setParameter("x", 1.23d); | |
query.setParameter("y", 4.56d); | |
// call the stored procedure and get the result | |
query.execute(); | |
Double sum = (Double) query.getOutputParameterValue("sum"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.1" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> | |
<persistence-unit name="EFS2015-persistence-unit" transaction-type="JTA"> | |
<description>Forge Persistence Unit</description> | |
<provider>org.hibernate.ejb.HibernatePersistence</provider> | |
<jta-data-source>java:jboss/datasources/ExampleDS</jta-data-source> | |
<exclude-unlisted-classes>false</exclude-unlisted-classes> | |
<properties> | |
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// call the named query | |
Query nq = this.em.createNamedQuery("selectAuthorOfBook2"); | |
List<AuthorValue> authors = nq.getResultList(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CriteriaBuilder cb = this.em.getCriteriaBuilder(); | |
// create update | |
CriteriaUpdate<Order> update = cb.createCriteriaUpdate(Order.class); | |
// set the root class | |
Root e = update.from(Order.class); | |
// set update and where clause | |
update.set("amount", newAmount); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. create the Order | |
cart.start(); | |
// 2. add one Item to the Order | |
cart.addItem("myFirstProduct"); | |
// 3. add additional Item to the Order | |
cart.addItem("mySecondProduct"); | |
// 4. write Order with its Items to the database | |
cart.persist(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2015-12-09 04:51:31,426 DEBUG [org.hibernate.SQL] (default task-1) select nextval ('hibernate_sequence') | |
2015-12-09 04:51:31,456 DEBUG [org.hibernate.SQL] (default task-1) select nextval ('hibernate_sequence') | |
2015-12-09 04:51:31,591 DEBUG [org.hibernate.SQL] (default task-1) insert into Author (firstName, lastName, version, id) values (?, ?, ?, ?) | |
2015-12-09 04:51:31,595 DEBUG [org.hibernate.SQL] (default task-1) insert into Author (firstName, lastName, version, id) values (?, ?, ?, ?) | |
2015-12-09 04:51:31,599 DEBUG [org.hibernate.SQL] (default task-1) update Author set firstName=?, lastName=?, version=? where id=? and version=? | |
2015-12-09 04:51:31,603 DEBUG [org.hibernate.SQL] (default task-1) select author0_.id as id1_0_, author0_.firstName as firstNam2_0_, author0_.lastName as lastName3_0_, author0_.version as version4_0_ from Author author0_ where author0_.lastName=? | |
2015-12-09 04:51:31,615 INFO [org.hibernate.engine.internal.StatisticalLoggingSessionEventListener] (default task-1) Session Metrics { | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class MyEntity { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = "id", updatable = false, nullable = false) | |
private Long id; | |
@Column | |
private LocalDate date; |