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
// 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
<?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
// 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
@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
@Converter(autoApply = true) | |
public class LocalDateAttributeConverter implements AttributeConverter<LocalDate, Date> { | |
@Override | |
public Date convertToDatabaseColumn(LocalDate locDate) { | |
return locDate == null ? null : Date.valueOf(locDate); | |
} | |
@Override | |
public LocalDate convertToEntityAttribute(Date sqlDate) { |
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
List<BookValue> results = ((Session)this.em.getDelegate()).createSQLQuery("SELECT b.id, b.title, b.version, a.firstName || ' ' || a.lastName as authorName FROM Book b JOIN Author a ON b.author_id = a.id") | |
.addScalar("id", StandardBasicTypes.LONG).addScalar("title").addScalar("version", StandardBasicTypes.LONG).addScalar("authorName") | |
.setResultTransformer(new AliasToBeanResultTransformer(BookValue.class)).list(); | |
results.stream().forEach((book) -> { | |
System.out.println("Book: ID [" + book.getId() + "] title [" + book.getTitle() + "] authorName [" + book.getAuthorName() + "]"); | |
}); |
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
@SqlResultSetMapping( | |
name = "BookValueMapping", | |
classes = @ConstructorResult( | |
targetClass = BookValue.class, | |
columns = { | |
@ColumnResult(name = "id", type = Long.class), | |
@ColumnResult(name = "title"), | |
@ColumnResult(name = "version", type = Long.class), | |
@ColumnResult(name = "authorName")})) |