У меня есть два класса «FicheBesoins» и «PlanFormationGeneral» с отношением @@ ManyToOne, я хотел бы получить «nom» и «prenom» в фишке, я создал запрос в PlanFormationGRepository:
@Query("SELECT FicheBesoins.nom,FicheBesoins.prenom FROM FicheBesoins WHERE
PlanFormationGeneral.idplan=FicheBesoins.idplan" )
public List<FicheBesoins> getFiches();
}
FicheBesoins:
@Entity
public class FicheBesoins implements Serializable {
@Id
@GeneratedValue
private int id ;
private int matricule;
private String nom ;
private String prenom ;
private String emploi ;
private String filiere ;
private String tachePrincipale ;
private String DirectionAeroport ;
private String division ;
private String service ;
private int comptenceActuelleNA ;
private int competenceActuelleNR;
private int nouvellecompetenceNA ;
private int nouvellecompetenceNR;
private String theme ;
private String niveaudemande ;
private String typeformation ;
private String periode ;
@ManyToOne
@JoinColumn(name="idplan")
private PlanFormationGeneral planFormationGeneral;
public FicheBesoins() {
super();
}
public FicheBesoins(int matricule, String nom, String prenom, String emploi, String filiere, String tachePrincipale,
String directionAeroport, String division, String service, int comptenceActuelleNA,
int competenceActuelleNR, int nouvellecompetenceNA, int nouvellecompetenceNR, String theme,
String niveaudemande, String typeformation, String periode) {
super();
this.matricule = matricule;
this.nom = nom;
this.prenom = prenom;
this.emploi = emploi;
this.filiere = filiere;
this.tachePrincipale = tachePrincipale;
DirectionAeroport = directionAeroport;
this.division = division;
this.service = service;
this.comptenceActuelleNA = comptenceActuelleNA;
this.competenceActuelleNR = competenceActuelleNR;
this.nouvellecompetenceNA = nouvellecompetenceNA;
this.nouvellecompetenceNR = nouvellecompetenceNR;
this.theme = theme;
this.niveaudemande = niveaudemande;
this.typeformation = typeformation;
this.periode = periode;
}
public FicheBesoins(int matricule, String nom, String prenom, String emploi, String filiere, String
tachePrincipale,
String directionAeroport, String division, String service, int comptenceActuelleNA,
int competenceActuelleNR, int nouvellecompetenceNA, int nouvellecompetenceNR, String theme,
String niveaudemande, String typeformation, String periode, PlanFormationGeneral
planFormationGeneral) {
super();
this.matricule = matricule;
this.nom = nom;
this.prenom = prenom;
this.emploi = emploi;
this.filiere = filiere;
this.tachePrincipale = tachePrincipale;
DirectionAeroport = directionAeroport;
this.division = division;
this.service = service;
this.comptenceActuelleNA = comptenceActuelleNA;
this.competenceActuelleNR = competenceActuelleNR;
this.nouvellecompetenceNA = nouvellecompetenceNA;
this.nouvellecompetenceNR = nouvellecompetenceNR;
this.theme = theme;
this.niveaudemande = niveaudemande;
this.typeformation = typeformation;
this.periode = periode;
this.planFormationGeneral = planFormationGeneral;
}
PlanFormationGeneral:
@Entity
public class PlanFormationGeneral implements Serializable {
@Id
@GeneratedValue
private int idplan;
private String domaine;
private Date date ;
private String organismeformateur ;
private String depenseprevisionnelle ;
private int dureeJ;
private int dureeH;
@OneToMany( mappedBy = "planFormationGeneral",fetch = FetchType.LAZY)
private Collection<FicheBesoins> ficheBesoins;
при запуске проекта я получил эту ошибку:
Caused by: java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List org.sid.dao.PlanFormationGRepository.getFiches()!
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:93) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.<init>(SimpleJpaQuery.java:63) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromMethodWithQueryString(JpaQueryFactory.java:76) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryFactory.fromQueryAnnotation(JpaQueryFactory.java:56) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:140) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:207) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:78) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lookupQuery(RepositoryFactorySupport.java:574) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$mapMethodsToQuery$1(RepositoryFactorySupport.java:567) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source) ~[na:1.8.0_251]
at java.util.Iterator.forEachRemaining(Unknown Source) ~[na:1.8.0_251]
at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Unknown Source) ~[na:1.8.0_251]
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Unknown Source) ~[na:1.8.0_251]
at java.util.stream.AbstractPipeline.copyInto(Unknown Source) ~[na:1.8.0_251]
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source) ~[na:1.8.0_251]
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(Unknown Source) ~[na:1.8.0_251]
at java.util.stream.AbstractPipeline.evaluate(Unknown Source) ~[na:1.8.0_251]
at java.util.stream.ReferencePipeline.collect(Unknown Source) ~[na:1.8.0_251]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.mapMethodsToQuery(RepositoryFactorySupport.java:569) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$new$0(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at java.util.Optional.map(Unknown Source) ~[na:1.8.0_251]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:559) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:332) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.util.Lazy.getNullable(Lazy.java:212) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.util.Lazy.get(Lazy.java:94) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300) ~[spring-data-commons-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792) ~[spring-beans-5.2.6.RELEASE.jar:5.2.6.RELEASE]
... 34 common frames omitted
Caused by: java.lang.NullPointerException: null
at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source) ~[na:1.8.0_251]
at java.lang.String$CaseInsensitiveComparator.compare(Unknown Source) ~[na:1.8.0_251]
at java.util.TreeMap.getEntryUsingComparator(Unknown Source) ~[na:1.8.0_251]
at java.util.TreeMap.getEntry(Unknown Source) ~[na:1.8.0_251]
at java.util.TreeMap.get(Unknown Source) ~[na:1.8.0_251]
at org.hibernate.dialect.function.SQLFunctionRegistry.findSQLFunction(SQLFunctionRegistry.java:45) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.findSQLFunction(SessionFactoryHelper.java:385) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.tree.IdentNode.getDataType(IdentNode.java:366) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:667) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.propertyRef(HqlSqlBaseWalker.java:1154) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:2315) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:2256) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1518) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:597) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:325) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:273) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:113) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:155) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:604) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:716) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:23) ~[hibernate-core-5.4.15.Final.jar:5.4.15.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_251]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_251]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_251]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_251]
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:366) ~[spring-orm-5.2.6.RELEASE.jar:5.2.6.RELEASE]
at com.sun.proxy.$Proxy85.createQuery(Unknown Source) ~[na:na]
at org.springframework.data.jpa.repository.query.SimpleJpaQuery.validateQuery(SimpleJpaQuery.java:87) ~[spring-data-jpa-2.2.7.RELEASE.jar:2.2.7.RELEASE]
... 63 common frames omitted
Я пробовал с этим запрос, но кажется, что UNION не работает:
@Query("SELECT FicheBesoins.nom, FicheBesoins.prenom FROM FicheBesoins LEFT
Join PlanFormationGeneral ON PlanFormationGeneral.idplan=FicheBesoins.idplan
UNION ALL SELECT FicheBesoins.nom, FicheBesoins.prenom FROM FicheBesoins
RIGHT Join PlanFormationGeneral ON
PlanFormationGeneral.idplan=FicheBesoins.idplan ")
любая идея, пожалуйста!