Tim Holloway wrote:Forgive my blindness, but I can't find the explanation of what "N+1" error means.
Tim Holloway wrote:I do this all the time. In fact, I keep 2 distinct persistence logic layers in most of my apps. The lower-level (DAO) layer handles table-level stuff, the higher-level (service) layer handles the whole group of records as a working set.
Tim Holloway wrote:If you're seeing tons of SQL operations when doing something like this, then chances are that you're either not relating the Entity objects properly or your queries are not properly formed.
Tim Holloway wrote:I think that before you go too far down that road you should look at Apache Lucene. It's designed to support text searches on databases.
Tim Holloway wrote:One of the major strengths of JPA is that you don't normally have to code JOINs in JPQL. Instead you code the entity relationships (OneToMany, ManyToOne, OneToOne, ManyToMany) as annotations of the Entity class definitions and let JPA handle the joining.
You have a lot of code there and it's early in the morning, but I suspect that if you leveraged JPA properly you'd have a lot less code and it would be easier to understand.
Tim Holloway wrote:
That CriteriaBuilder especially bothers me because I suspect that all those constant parameters should be in an array of Strings and fed in via a simple query. CriteriaBuilder is primarily for when you want to make query components optional.
"error": "Internal Server Error",
Type definition error: [simple type, class com.crud.demo.dto.EmployeeDto];
nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException:
No serializer found for class com.crud.demo.dto.EmployeeDto and no properties discovered
to create BeanSerializer
Rob Spoor wrote:I take it that the model classes are mapped from JSON directly to your entities, right? If so, you're running into a bidirectional relation that is only set on one side. The unmarshalling from JSON creates new LoggingModel instances, and puts them into a list. It then sets that list on the created EmployeeModel instance. The EmployeeModel instance now has a reference to all of its LoggingModel instances. What is still missing is the reference in the LoggingModel instances to the EmployeeModel instance. The JSON unmarshalling doesn't set this because it simply doesn't know it should.
A quick solution is to fix these references yourself. A quick for-each statement will suffice: