Home > Back-end >  Spring Data JPA entity class variables can get without corresponding database field value
Spring Data JPA entity class variables can get without corresponding database field value

Time:09-25

I these two fields is sub queries found out the use of the individual name, thought to the entity class, two temporary variables to receive, as a result, other places also need to use the same entity class, error can't find this two fields

And then to the online @ Transient entity class can not mapping, but also make the two temporary variables and can't receive value


Please, coach coach!!!!!!

CodePudding user response:

Attached SQL:
 @ Query (value="https://bbs.csdn.net/topics/SELECT r. *, + 
"New com. Fxweb. Pojo. SelectResult ((SELECT ` name ` FROM menu WHERE menu. Category_Level1=r.p arent_Id AND category_Level2=0) as category_Lv2, +"
"(SELECT ` name ` FROM menu WHERE id=(the SELECT menu. The parent_Id FROM menu WHERE category_Level1=r.p arent_Id AND category_Level2=0)) as category_Lv1)" +
"FROM the resources AS r")
Page FindBackDataAll (Example Example, Pageable Pageable);

CodePudding user response:

SelectResult this class with you to the two fields, if any new com. Fxweb. Pojo. SelectResult when the database field corresponding to the entity attribute names, such as database _type _type as entity, at the same time SelectResult class head with @ AllArgsConstructor annotations;
If SelectResult isn't what you need to return an object, you need to you to build an object to receive you caught the child table fields

CodePudding user response:

JPA support for complex queries are weak, no write their own queries to fast, good understanding, so my suggestion is that the results of a query or use their own DTO to receive, don't use entity, but if you want to use dtos to pick up, you need to do the custom ResultTransformer implementation, or use the JPA provides will trouble to death,
  • Related