• java.lang.IllegalArgumentException异常 数据库别名问题


     1 java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [from com.tao.pojo.Student  inner join clazz]
     2     at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:133)
     3     at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
     4     at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
     5     at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:670)
     6     at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:686)
     7     at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
     8     at com.tao.test.StudentTest.test001(StudentTest.java:47)
     9     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    10     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    11     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    12     at java.lang.reflect.Method.invoke(Method.java:498)
    13     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    14     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    15     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    16     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    17     at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    18     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
    19     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    20     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    21     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    22     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    23     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    24     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    25     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    26     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    27     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    28     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    29     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    30     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    31     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    32     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    33     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
    34 Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Path expected for join! [from com.tao.pojo.Student  inner join clazz]
    35     at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
    36     at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)
    37     at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
    38     at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189)
    39     at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:141)
    40     at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115)
    41     at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
    42     at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:153)
    43     at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:553)
    44     at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:662)
    45     ... 28 more
    46 
    47 org.hibernate.TransactionException: Transaction was marked for rollback only; cannot commit
    48     at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:228)
    49     at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
    50     at com.tao.test.StudentTest.testAfter(StudentTest.java:32)
    51     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    52     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    53     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    54     at java.lang.reflect.Method.invoke(Method.java:498)
    55     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    56     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    57     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    58     at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
    59     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    60     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
    61     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
    62     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    63     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    64     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    65     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    66     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    67     at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    68     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    69     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    70     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    71     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    72     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    73     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

    这里这个错误是因为类Student没有起别名,给个别名就对了
    @Test
        public void test001() {
            Query<Object[]> query = session.createQuery("from Student inner join clazz", Object[].class);
            List<Object[]> list = query.list();
            for (Object[] oo : list) {
                System.out.println(oo[0]+","+oo[1]);
            }
        }
    正确写法(这样写最后返回的就是Object类型的数组)
      @Test
        public void test001() {
            Query<Object[]> query = session.createQuery("from Student s inner join s.clazz", Object[].class);
            List<Object[]> list = query.list();
            for (Object[] oo : list) {
                System.out.println(oo[0]+","+oo[1]);
            }
        }
    第一行末尾已经指出,
    Path expected for join! [from com.tao.pojo.Student inner join clazz]
  • 相关阅读:
    2022/04/09 Solidity_Day1
    2022/04/22 DeFi_Study_Day2
    2022/06/09 Solidity_Day4
    2022/07/06 Solidity_Day7
    2022/06/08 Solidity_Day3
    2022/06/10 Solidity_Day5
    2022/04/09 Solidity_概念理解
    2022/04/02~04/03 DeFi_Study_Day1
    2022/04/23 DeFi_Study_Day3
    2022/04/14 Solidity_Day2
  • 原文地址:https://www.cnblogs.com/jili6254/p/8195962.html
Copyright © 2020-2023  润新知