当前位置:  开发笔记 > 编程语言 > 正文

Querydsl-线程“主”中的异常java.lang.IllegalArgumentException:未提供任何源

如何解决《Querydsl-线程“主”中的异常java.lang.IllegalArgumentException:未提供任何源》经验,为你挑选了1个好方法。

我正在使用Spring MVC,Thymeleaf,JPA(休眠)和Querydsl构建系统。在测试所有内容时,我遇到了此异常:

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Serviço nulo: false
[SER_USU] - Fazendo consulta...
[SER_USU] - Dao nulo: false

Exception in thread "main" java.lang.IllegalArgumentException: No sources given
    at com.querydsl.jpa.JPAQueryBase.serialize(JPAQueryBase.java:56)
    at com.querydsl.jpa.JPAQueryBase.serialize(JPAQueryBase.java:50)
    at com.querydsl.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:98)
    at com.querydsl.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:94)
    at com.querydsl.jpa.impl.AbstractJPAQuery.fetch(AbstractJPAQuery.java:201)
    at com.regra7.st.db.dao.Dao_Usuario.getPorID(Dao_Usuario.java:35)
    at com.regra7.st.servico.Ser_Usuario.cadastrar(Ser_Usuario.java:46)
    at com.regra7.st.testes.TesteDAO_001.(TesteDAO_001.java:43)
    at com.regra7.st.testes.TesteDAO_001.main(TesteDAO_001.java:19)

不幸的是,这不是很具描述性,因此,我不知道该怎么办。我已经尝试了所有方法,但是找不到解决方案。是的,那就是所有消息(堆栈跟踪)。这是我正在使用的一些文件...

pom.xml(我可能有一些依赖关系错误,我不清楚):


    4.0.0
    com.regra7
    Sistema_Teste_001
    0.0.1-SNAPSHOT
    war
    
        src
        

            
                maven-war-plugin
                2.6
                
                    WebContent
                    false
                
            

            
                maven-compiler-plugin
                3.3
                
                    1.7
                    1.7
                
            

            
            
                com.mysema.maven
                apt-maven-plugin
                1.1.3
                
                    
                        
                            process
                        
                        
                            target/generated-sources/java
                            com.querydsl.apt.jpa.JPAAnnotationProcessor
                        
                    
                
            

        
    
    

        
        
            org.apache.commons
            commons-lang3
            3.5
        

        
        
            org.springframework
            spring-webmvc
            4.3.5.RELEASE
        

        
        
            org.springframework
            spring-context
            4.3.5.RELEASE
        

        
        
            org.springframework
            spring-orm
            4.3.5.RELEASE
        

        
        
            org.postgresql
            postgresql
            9.3-1102-jdbc41
        

        
        
        
            javax.servlet
            javax.servlet-api
            3.1.0
        

        
        
        
            javax.validation
            validation-api
            1.1.0.Final
        

        
        
            org.hibernate
            hibernate-core
            5.2.6.Final
        

        
        
        
            org.hibernate
            hibernate-validator
            5.3.4.Final
        

        
        
            org.hibernate.javax.persistence
            hibernate-jpa-2.1-api
            1.0.0.Final
        

        
            javax.el
            javax.el-api
            2.2.4
        
        
            org.glassfish.web
            javax.el
            2.2.4
        

        
        
        
            org.thymeleaf
            thymeleaf
            3.0.3.RELEASE
        

        
        
        
            org.thymeleaf
            thymeleaf-spring4
            3.0.3.RELEASE
        

        
        
            com.querydsl
            querydsl-core
            4.1.4
        

        
        
            com.querydsl
            querydsl-jpa
            4.1.4
        

        
        
            com.querydsl
            querydsl-apt
            4.1.4
        

        
            org.slf4j
            slf4j-log4j12
            1.6.1
        

        
        
        
            com.mchange
            c3p0
            0.9.5.2
        

    

spring-config.xml(app-context.xml):






    
    
    
    
    

    
    

    
    

    
    
    
    
    

    
    

    
    
        
            
                
                
            
        
    

    
    

    
    
    
        
        
        
        
        
        
        
    

    
    
    
        
        
        
        
        
        
        
    

    
    
        
    

    
    
        
        
        
        
        

        
        
        
        
         
        
    

    
    
        
        
        
            
        
        
            
                none
                org.hibernate.dialect.PostgreSQL82Dialect
                false
                false
                false
                false
                regrast
                50
            
        
    

    
    
        
    

    
    
        
            
            
        
    


persistence.xml:




    

        
        org.hibernate.jpa.HibernatePersistenceProvider

    


我的主要考试班

public class TesteDAO_001 
{
    public static void main(String[] args) 
    {
        new TesteDAO_001(); // Line 19
    }

    public TesteDAO_001()
    {
        AbstractApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring-config.xml");
        Ser_Usuario servico = ac.getBean(Ser_Usuario.class); // Service class

        // For_Cadastro is an account registration form.
        For_Cadastro form = new For_Cadastro();
        form.setNome("Maria Pereira Maxwell"); // Name
        form.setLogin("rodrigologinsoares001");
        form.setSenha1("minhasenha001001"); // Password
        form.setSenha2("minhasenha001001"); // Password confirmation
        form.setCpf("01234567890"); // CPF = Brazil's Social ID
        form.setNascimento(LocalDate.now()); // Birthday
        form.setPai(0L); // Father
        form.setMae(0L); // Mother
        form.setGenero(0L); // Gender

        System.out.printf("Serviço nulo: %s%n" , servico == null);
        servico.cadastrar(form); // Line 43

        ac.close();
    }
}

服务方式

@Autowired
private Dao_Usuario _daoUsu;

@Transactional(rollbackFor = Exception.class)
public void cadastrar(For_Cadastro form)
{
    imprimir("Fazendo consulta...");
    imprimir(String.format("Dao nulo: %s%n", this._daoUsu == null));

    // This may return null.    
    Usuario pai = this._daoUsu.getPorID(form.getPai()); // Line 46
    Usuario mae = this._daoUsu.getPorID(form.getMae());

    imprimir(String.format("pai nulo: %s%n", pai == null));
    imprimir(String.format("mea nulo: %s%n", mae == null));

    // Usuario is a Domain Model Object. A POJO representation of a table.
    Usuario usu = new Usuario(form.getCpf()); // CPF = Brazil's Social ID
    usu.setGenero(Genero.getGenero(form.getGenero())); // Gender
    usu.setNome(form.getNome()); // Name
    usu.setLogin(form.getLogin());
    usu.setSenha(form.getSenha1().getBytes()); // Password
    usu.setNascimento(form.getNas

小智.. 6

好吧,我不好意思说我没早点听说。您查询的语法实际上是错误的

return new JPAQueryFactory(this._em)
        .select(QUsuario.usuario)
        .where(QUsuario.usuario.id.eq(id))
        .fetchOne();  

应该

 return new JPAQueryFactory(this._em)
        .selectFrom(QUsuario.usuario)
        .where(QUsuario.usuario.id.eq(id))
        .fetchOne(); 

它的selectFrom而不是select。



1> 小智..:

好吧,我不好意思说我没早点听说。您查询的语法实际上是错误的

return new JPAQueryFactory(this._em)
        .select(QUsuario.usuario)
        .where(QUsuario.usuario.id.eq(id))
        .fetchOne();  

应该

 return new JPAQueryFactory(this._em)
        .selectFrom(QUsuario.usuario)
        .where(QUsuario.usuario.id.eq(id))
        .fetchOne(); 

它的selectFrom而不是select。

推荐阅读
可爱的天使keven_464
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有