java - jpql left join fetch not returning results for like -
Text after "itemprop =" text ">
In a app using a Spring MVC Hibernate and MySQL, I've written the following query method to return a list of names with patients To:
@SuppressWarnings ("uncheck") public collection & lt; Person & gt; FindPersonByLastName (string ln) throws DataAccessException {query query = this.em.createQuery ("DISTINCT person joining rimPerson person to pers.names n.m. ou nm.family choose to leave from like: LNM"); Query.setParameter ("LN", LN); Return query.getResultList (); }
This is used to produce the following hibernate SQL:
Select specific person0_.hppid as hibernate: hppid1_340_0_, names1_.HJID HJID1_89_1_, as as person0_2_.classCode_HJID classCod2_339_0_, administ2_341_0_ as person0_1_.administrativeGenderCode_HJID, birthTim3_341_0_, DELIMITE2_89_1_ as names1_.DELIMITER_, FAMILY3_89_1_ as names1_.FAMILY, named5_89_1_ as names1_.named_entity_hppid, SUFFIX4_89_1_ as names1_.SUFFIX, name9_340_0__ as names1_.name_entity_HJID, names1_ .HJID as HJID1_89_0__ as person0_1_.birthTime_HJID Rim_person person0_Internal rim_living_subject person0_1_ on person0_.hppid = person0_1_.hppid Ntrik include rim_entity person0_2_ person0_.hppid = person0_2_.hppid internal included rim_infrastructure_root Wykti0_3_ person0_.hppid = person0_3_.hppid left outer join N name 1_ person0_.hppid = names1_. Name_entity_HJID where like names1_.FAMILY?
When I call the above JPQL method with the following command, it returns zero results:
this.myappService.findPersonByLastName ("");
When I give the above generated hibernate code in the MySQL command line client and give it past, I get zero results and If, however, i ?
to code>.
Above the hibernate generated SQL and the small SQL place in the MySQL command line client, I have four results, each for the last name field value.
How can I change JPQL so that it generates a hibernate query that returns four results when `` the empty string parameter is passed as? I want to include the results set to give every result when the user returns empty input, but to give filtered results when the user types in any text input.
The typical reason is that This is cute for inserting the This will match anything that ends with the parameter that has passed the method. like
fails to do that It looks like this should be forgotten to put wildcards in the pattern string. For example, if you want to match all the usernames starting with 'Code', then you have to do something like 'code%', such as 'code%' , no name 'code' / Code>.
findPersionByLastName
caller in the %
wildcard. For a better implementation the caller has to specify which name they are looking for, and then the code is created in which the wildcard was placed in the right place. When you are looking for the last name, you can do something like this:
query.setParameter ("lnm", "%" + ln);
Comments
Post a Comment