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 Book { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = “id”, updatable = false, nullable = false) | |
private Long id; | |
@OneToMany(mappedBy = “book”) | |
private List reviews = new ArrayList(); |
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
Query q = em.createQuery("SELECT a, size(a.books) FROM Author a GROUP BY a.id"); | |
List<Object[]> results = q.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
Statistics stats = sessionFactory.getStatistics(); | |
long queryCount = stats.getQueryExecutionCount(); | |
long collectionFetchCount = stats.getCollectionFetchCount(); |
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
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure() | |
.build(); |
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 Book { | |
@Id | |
@GeneratedValue(strategy = GenerationType.AUTO) | |
@Column(name = “id”, updatable = false, nullable = false) | |
private Long id; | |
private LocalDate publishingDate; |
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
EntityManager em = emf.createEntityManager(); | |
em.getTransaction().begin(); | |
FullTextEntityManager fullTextEm = Search.getFullTextEntityManager(em); | |
QueryBuilder tweetQb = fullTextEm.getSearchFactory().buildQueryBuilder().forEntity(Tweet.class).get(); | |
Query tweetQuery = tweetQb.all().createQuery(); | |
FullTextQuery fullTextQuery = fullTextEm.createFullTextQuery(tweetQuery, Tweet.class); |
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 Author { | |
@Temporal(TemporalType.DATE) | |
private Date dateOfBirth; | |
... | |
} |
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
@AnalyzerDef( | |
name = “textanalyzer”, | |
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), | |
filters = { | |
@TokenFilterDef(factory = LowerCaseFilterFactory.class), | |
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, | |
params = { @Parameter(name = “language”, value = “English”) }) | |
} | |
) |
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 = em.getCriteriaBuilder(); | |
CriteriaQuery cq = cb.createQuery(Book.class); | |
Root root = cq.from(Book.class); | |
// call the database function calculate | |
ParameterExpression doubleParam1 = cb.parameter(Double.class); | |
ParameterExpression doubleParam2 = cb.parameter(Double.class); | |
cq.where(cb.greaterThan(doubleParam2, cb.function(“calculate”, Double.class, root.get(Book_.price), doubleParam1))); | |
TypedQuery q = em.createQuery(cq); |