Home » JPA » Page 12

Tag Archives: JPA

Schema Creation Script With Hibernate 4, JPA And Maven

The scenario is trivial – you want to generate a database schema creation script while building your application (and then execute the script on the target database) This was relatively easy with Hibernate 3, as there was the hibernate3-maven-plugin, but it is not compatible with Hibernate 4. And for every new project you should start with Hibernate 4, of course. ...

Read More »

EasyCriteria – An easy way to use the JPA Criteria

java-interview-questions-answers

Today we will see about this tool that make easier to use the JPA Criteria. The application that uses this library will be cleaner, easier to use and portable across the JPA implementations. At the end of this post you will find the source code to download. What is Criteria? Currently is the best solution to create dynamic queries. Imagine ...

Read More »

Ultimate JPA Queries and Tips List – Part 3

java-interview-questions-answers

Before you read the third part , remember the first and second part of the series JPA: Creating a object from a query The JPA allow us to create objects inside a query, just with the values that we need:               package com.model; public class PersonDogAmountReport { private int dogAmount; private Person person; public ...

Read More »

Ultimate JPA Queries and Tips List – Part 2

java-interview-questions-answers

This part continues from the first part of the series. JPA: NamedQuery, querying with dates, warnings about the getSingleResult method To avoid the repetition of queries codes, upgrade the performance and make easier to maintain the queries we can use the NamedQueries. A NamedQuery uses JPQL as syntax and it is declared in the entity class. It is easier to ...

Read More »

Ultimate JPA Queries and Tips List – Part 1

java-interview-questions-answers

There are several JPAs “how to” that we can find on the internet, here in this blog, that teaches how to do several tasks with JPA. Usually I see some people asking questions about Queries with JPA; usually to answer this kind of questions several links are provided trying to find a solution to the question. Until today I could ...

Read More »

Four solutions to the LazyInitializationException – Part 2

This article continues from part 1 of the tutorial. Load collection by Stateful EJB with PersistenceContextType.EXTENDED This approach can be applied only to applications that works with Full JEE environments: to use a EJB with PersistenceContextType.EXTENDED. Check the code below how the DAO would look like: package com.ejb; import javax.ejb.Stateful; import javax.persistence.*; import com.model.Person; @Stateful public class SystemDAOStateful { @PersistenceContext(unitName ...

Read More »

Four solutions to the LazyInitializationException – Part 1

In the post today we will talk about the common LazyInitializationException error. We will see four ways to avoid this error, the advantage and disadvantage of each approach and in the end of this post, we will talk about how the EclipseLink handles this exception. To see the LazyInitializationException error and to handle it, we will use an application JSF ...

Read More »

Test JPQL / HQL without a deploy

Have you ever wanted to test your JPQL / HQL without doing a full deploy of your application? What we will see here today is simple solution that works for any JPA implementation: Hibernate, OpenJPA, EclipseLink and others. The base source code found in this post came from this book: “Pro JPA 2: Mastering the Java™ Persistence API – Mike ...

Read More »

Full Web Application Tomcat JSF Primefaces JPA Hibernate – Part 2

ManagedBeans This post continues from part 1 of this tutorial. In the “com.mb” package you will need to create the classes bellow:             package com.mb; import org.primefaces.context.RequestContext; import com.util.JSFMessageUtil; public class AbstractMB { private static final String KEEP_DIALOG_OPENED = 'KEEP_DIALOG_OPENED'; public AbstractMB() { super(); } protected void displayErrorMessageToUser(String message) { JSFMessageUtil messageUtil = new JSFMessageUtil(); messageUtil.sendErrorMessageToUser(message); ...

Read More »