I’m trying to extend my library for integrating Swing and JPA by making JPA config as automatic (and portable) as can be done, and it means programmatically adding <class> elements. (I know it can be done via Hibernate’s AnnotationConfiguration or EclipseLInk’s ServerSession, but ̵…
Tag: jpa
Spring fails to inject entity manager factory
I writing tests for my DAO classes using JPA, with Hibernate as JPA provider, and Spring 3.2. I am not able to inject the entity manager correctly, I get a NullPointerException when trying to access it. My GenericDAO implementation looks like this: The class of the test looks like this: My root-context.xml is…
What’s the difference between JPA and Spring Data JPA?
I am a bit confused about the difference between Spring Data-JPA and JPA. I know about JPA that it is a specification for persisting the Java Objects to a relational database using popular ORM …
How to paginate a JPA Query
I have a submission table with columns like ID, Name, Code among other properties. My requirement is to search for records based on the mentioned properties and return a paginated set. This is the pseudocode for what I am looking for: There seem to be many options like CriteriaBuilder, NamedQuery, etc. Which …
Link fires method multiple no. of times
The problem is that whenever I click the link Next page on Home.xhtml to goto getMoreStatusList Page, the function getMoreStatusList is called non-stop until it throws a index out of bound exception. I am even printing the value of index that I get from the session object statusindex and the string insidegetm…
Hibernate faster EntityManagerFactory creation
In my desktop application new databases get opened quite often. I use Hibernate/JPA as an ORM. The problem is, creating the EntityManagerFactory is quite slow, taking about 5-6 Seconds on a fast machine. I know that the EntityManagerFactory is supposed to be heavyweight but this is just too slow for a desktop…
How to prevent SQL Injection with JPA and Hibernate?
I am developing an application using hibernate. When I try to create a Login page, The problem of Sql Injection arises. I have the following code: How will i prevent Sql Injection in this scenario ?The create table syntax of loginInfo table is as follows: Answer You have other options too, see this nice artic…
What is difference between CrudRepository and JpaRepository interfaces in Spring Data JPA?
What is the difference between CrudRepository and JpaRepository interfaces in Spring Data JPA? When I see the examples on the web, I see them there used kind of interchangeably. What is the difference between them? Why would you want to use one over the other? Answer JpaRepository extends PagingAndSortingRepo…
JPA could not locate named parameter
I keep getting the following error: “could not locate named parameter [articleCommentId]” but it doesn’t make sense to me because to me the named parameter is very much in place. Here is an extract of the stack trace with the relevant error: Answer I bet it is due to the extra ; in your quer…
How can I avoid the Warning “firstResult/maxResults specified with collection fetch; applying in memory!” when using Hibernate?
I’m getting a warning in the Server log “firstResult/maxResults specified with collection fetch; applying in memory!”. However everything working fine. But I don’t want this warning. My code is My query is Answer Reason for this warning is that when fetch join is used, order in result …