休眠错误消息:意外令牌:NULLS(脚本文件行中的错误:13 意外令牌:NULLS)

Posted

技术标签:

【中文标题】休眠错误消息:意外令牌:NULLS(脚本文件行中的错误:13 意外令牌:NULLS)【英文标题】:Hibernate error message: unexpected token: NULLS (error in script file line: 13 unexpected token: NULLS) 【发布时间】:2012-02-04 08:18:43 【问题描述】:

在学习Hibernate的过程中,遇到了一个很模糊的错误信息。首先是一些快速的背景知识。我以前有一个工作正常的单表数据库。现在我添加了第二个表,第一个表包含第二个表的集合。更清楚地说,我以前有一个团队表。现在我添加了一个播放器表。 Team 包含一个属性,该属性将包含该团队的团队成员。当然,团队成员是由球员组成的。我想让这个工作,但我不明白错误消息。我已经包含了我认为相关的文件。我省略了我的主控制器和团队控制器以及相关的视图,因为以前的工作版本从未触及这些。也省略了 DAO 和服务层;又没碰。这是错误日志:

   [org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0,org.springframework.format.support.FormattingConversionServiceFactoryBean#0,org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0,org.springframework.web.servlet.handler.MappedInterceptor#0,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter,org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0,org.springframework.web.servlet.handler.SimpleUrlHandlerMapping#0,datasource,org.springframework.web.servlet.view.InternalResourceViewResolver#0,org.springframework.context.support.ReloadableResourceBundleMessageSource#0,sessionFactory,transactionManager,umpire,theTeam,removedTeam,thePlayer,playerManager,baseballservice,teamManager,baseballDAO,baseballDAOimp,baseballServiceImp,greeter,homeController,playerController,teamController,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@102b2b6
WARN : org.hibernate.util.DTDEntityResolver - recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
WARN : org.hibernate.cfg.AnnotationBinder - Package not found or wo package-info.java: com.ryans.MVCproject1
WARN : hsqldb.db.HSQLDB3310D13292.ENGINE - unexpected token: NULLS
org.hsqldb.HsqlException: unexpected token: NULLS
    at org.hsqldb.error.Error.parseError(Unknown Source)
    at org.hsqldb.ParserBase.unexpectedToken(Unknown Source)
    at org.hsqldb.ParserCommand.compileSetDatabaseProperty(Unknown Source)
    at org.hsqldb.ParserCommand.compileSet(Unknown Source)
    at org.hsqldb.ParserCommand.compilePart(Unknown Source)
    at org.hsqldb.ParserCommand.compileStatement(Unknown Source)
    at org.hsqldb.Session.compileStatement(Unknown Source)
    .
    at org.hsqldb.jdbc.JDBCDriver.getConnection(Unknown Source)
    at org.hsqldb.jdbc.JDBCDriver.connect(Unknown Source)
    at org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38)
    at org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582)
    at org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556)
    at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545)
    at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388)
    at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:113)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2863)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2859)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1870)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
    .
    .
    .
    .
    .
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:844)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:786)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:383)
    at org.springframework.web.servlet.handler.AbstractUrlHandlerMapping.registerHandler(AbstractUrlHandlerMapping.java:362)
    at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.detectHandlers(AbstractDetectingUrlHandlerMapping.java:82)
    at org.springframework.web.servlet.handler.AbstractDetectingUrlHandlerMapping.initApplicationContext(AbstractDetectingUrlHandlerMapping.java:58)
    at org.springframework.context.support.ApplicationObjectSupport.initApplicationContext(ApplicationObjectSupport.java:119)
    at org.springframework.web.context.support.WebApplicationObjectSupport.initApplicationContext(WebApplicationObjectSupport.java:72)
    at org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(ApplicationObjectSupport.java:73)
    at org.springframework.context.support.ApplicationContextAwareProcessor.invokeAwareInterfaces(ApplicationContextAwareProcessor.java:106)
    at org.springframework.context.support.ApplicationContextAwareProcessor.postProcessBeforeInitialization(ApplicationContextAwareProcessor.java:85)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:394)
    .
    .
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
    at javax.servlet.GenericServlet.init(GenericServlet.java:160)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1189)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1103)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1010)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4935)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5262)
    at org.apache.catalina.core.StandardContext$3.call(StandardContext.java:5257)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Feb 6, 2012 2:25:53 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Feb 6, 2012 2:25:53 PM org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Feb 6, 2012 2:25:53 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 5176 ms

这是与这个小程序相关的文件...

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ryans</groupId>
    <artifactId>MVCproject1</artifactId>
    <name>abc</name>
    <packaging>war</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>
    <properties>
        <java-version>1.6</java-version>
        <org.springframework-version>3.0.5.RELEASE</org.springframework-version>
        <org.springframework.roo-version>1.0.2.RELEASE</org.springframework.roo-version>
        <org.aspectj-version>1.6.9</org.aspectj-version>
        <org.slf4j-version>1.5.10</org.slf4j-version>
    </properties>
    <dependencies>
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>$org.springframework-version</version>
            <exclusions>
                <!-- Exclude Commons Logging in favor of SLF4j -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>$org.springframework-version</version>
        </dependency>
        <!-- this was added by me for JPA annotations -->
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0</version>
            <optional>true</optional>
        </dependency>

        <!-- Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, 
            and iBatis. (depends on spring-core, spring-beans, spring-context, spring-tx) 
            Define this if you need ORM (org.springframework.orm.*) -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>$org.springframework-version</version>
        </dependency>


        <!-- Roo dependencies -->
        <dependency>
            <groupId>org.springframework.roo</groupId>
            <artifactId>org.springframework.roo.annotations</artifactId>
            <version>$org.springframework.roo-version</version>
            <scope>provided</scope>
        </dependency>

        <!-- AspectJ -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>$org.aspectj-version</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>$org.slf4j-version</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>$org.slf4j-version</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>$org.slf4j-version</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.15</version>
            <exclusions>
                <exclusion>
                    <groupId>javax.mail</groupId>
                    <artifactId>mail</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>javax.jms</groupId>
                    <artifactId>jms</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jdmk</groupId>
                    <artifactId>jmxtools</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.sun.jmx</groupId>
                    <artifactId>jmxri</artifactId>
                </exclusion>
            </exclusions>
            <scope>runtime</scope>
        </dependency>

        <!-- @Inject -->
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <!-- Servlet -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet.jsp</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

        <!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.7</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>


        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>3.6.7.Final</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>

    <!--  added for hibernate annotations 2/3/12 -->    
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>$hibernate-core-version</version>
        </dependency>


        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-proxool</artifactId>
            <version>4.0.0.CR4</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.12.1.GA</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
    <repositories>
        <!-- For testing against latest Spring snapshots -->
        <repository>
            <id>org.springframework.maven.snapshot</id>
            <name>Spring Maven Snapshot Repository</name>
            <url>http://maven.springframework.org/snapshot</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <!-- For developing against latest Spring milestones -->
        <repository>
            <id>org.springframework.maven.milestone</id>
            <name>Spring Maven Milestone Repository</name>
            <url>http://maven.springframework.org/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>

            <!-- For hibernate support -->
            <repository>
                <id>jboss</id>
                <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            </repository>



    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>$java-version</source>
                    <target>$java-version</target>

servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">


    <!-- DispatcherServlet Context: defines this servlet's request-processing 
        infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />
    <!-- Enables the transactional annotations -->
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving 
        up static resources in the $webappRoot/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Connection to Database 

    *****   hsqldb.lock_file=false *****

    -->
    <beans:bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <beans:property name="driverClassName" value="org.hsqldb.jdbcDriver" />
        <beans:property name="url" value="jdbc:hsqldb:G:/SpringProjects/MVCProj1/database;shutdown=true" />                                     
        <beans:property name="username" value="ryan" />
        <beans:property name="password" value="ryan" />
    </beans:bean>

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources 
        in the /WEB-INF/views directory -->
    <!-- View Resolver -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <!-- MessageSource -->
    <beans:bean
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <beans:property name="basename" value="classpath:messages" />
        <beans:property name="defaultEncoding" value="UTF-8" />
    </beans:bean>

    <!-- Hibernate SessionFactory -->
    <!-- <beans:bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   this was the original working bean class 2/3/12-->

        <beans:bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <beans:property name="dataSource" ref="datasource"></beans:property>
        <beans:property name="configLocation" value="classpath:hibernate.cfg.xml"></beans:property>
        <beans:property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration"></beans:property>
        <beans:property name="annotatedClasses">
            <beans:list>
                <beans:value>com.ryans.MVCproject1.Team</beans:value>
                <beans:value>com.ryans.MVCproject1.Player</beans:value>
            </beans:list> 

        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</beans:prop>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
                <beans:prop key="hibernate.hbm2dll.auto">create-drop</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>



     <!-- Define a transaction Manager -->
    <beans:bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    <beans:property name="sessionFactory" ref="sessionFactory"></beans:property>
    </beans:bean>



    <!-- Custom Greeter Bean -->
    <beans:bean id="umpire" class="com.ryans.MVCproject1.Greeter">
    <beans:property name="theMessage" value="I am the umpire!"></beans:property>
    </beans:bean>

    <beans:bean id="theTeam" class="com.ryans.MVCproject1.Team"></beans:bean>

    <beans:bean id="removedTeam" class="com.ryans.MVCproject1.Team"></beans:bean>

    <beans:bean id="thePlayer" class="com.ryans.MVCproject1.Player"></beans:bean>

    <beans:bean id="playerManager" class="com.ryans.MVCproject1.baseballServiceImp">
    <beans:constructor-arg ref="baseballDAO"></beans:constructor-arg>
    </beans:bean>

    <beans:bean id="baseballservice" class="com.ryans.MVCproject1.baseballServiceImp"> 
    <beans:constructor-arg ref="baseballDAO"></beans:constructor-arg>
    </beans:bean>

    <beans:bean id="teamManager" class="com.ryans.MVCproject1.baseballServiceImp">
    <beans:constructor-arg ref="baseballDAO"></beans:constructor-arg>
    </beans:bean> 

    <beans:bean id="baseballDAO" class="com.ryans.MVCproject1.BaseballDAOimp">
    <beans:property name="sessionFactory" ref="sessionFactory"></beans:property>
    </beans:bean> 


    <context:component-scan base-package="com.ryans.MVCproject1" />


</beans:beans>

hibernate.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <mapping package="com.ryans.MVCproject1" />
        <mapping class="com.ryans.MVCproject1.Player"/>
        <mapping class="com.ryans.MVCproject1.Team"/>
    </session-factory> 

</hibernate-configuration>

PlayerController.java

package com.ryans.MVCproject1;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 
 * @author Captain Duh
 * 
 * Handle Requests for the player page
 *
 */

@Controller
@RequestMapping(value="/player")
public class PlayerController 

    private static final Logger logger = LoggerFactory.getLogger(PlayerController.class);
    @Autowired
    private Team thePlayer;
    @Autowired
    private baseballService playerManager;
    @Autowired baseballService baseballservice; //all teams in the database



    @RequestMapping(method=RequestMethod.GET)
    public String PlayerPage(Model model)
        logger.info("You have entered the player controller.");
        model.addAttribute("thePlayer", thePlayer);
        return "player";
    

    @RequestMapping("/storePlayer")
    public String storePlayer(@ModelAttribute("thePlayer")Player enteredPlayer,BindingResult result)
        playerManager.addPlayer(enteredPlayer); //the @ModelAttribute is binding to the model attribute added in the get method

        return "redirect:/home";
    

    public void getAllTeams(Model model)
        logger.info("Getting all teams for player...");
        //ModelAndView mav = new ModelAndView("home");
        List<Team> teamsToSelect = baseballservice.getAllTeams(); //Query for all teams in database
        //mav.addObject("GET_TEAMS_KEY", allTeams); 
        model.addAttribute("teamsToSelect", teamsToSelect);
        return;    
    


player.jsp

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>    

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Team Player Management</title>
</head>
<body>
<h3>Welcome to the Player Manager</h3>

<form:form method="POST" modelAttribute="thePlayer" action="player/storePlayer">
<table>
<tr>
              <td>Player First Name:</td>
              <td><form:input path="firstName" /></td>
          </tr>
          <tr>
              <td>Last Name:</td>
              <td><form:input path="lastName" /></td>
          </tr>
          <tr>
                <td>Jersey No.</td>
                <td><form:input path="jerseyNumber"/></td>  
          </tr>
          <tr>
                <c:forEach var="team" items="$teamsToSelect"></c:forEach>
                <form:select path="playerTeam">
                <form:option value="NONE" label="**Select a Team **"/>
                <form:options items="$teamsToSelect"/>
                </form:select>
          </tr>

          <tr>
              <td colspan="2">
                  <input type="submit" value="Create Player" />
              </td>
          </tr>

</table>
</form:form>
<a href="home">Back Home</a>

</body>
</html>

如果您需要更多信息,请告诉我。这对我来说没有意义。谢谢。

【问题讨论】:

导致这个异常的代码是什么? 我发布了修改过的文件。我添加了播放器类、控制器和视图。我还在 pom 文件中添加了与 hibernate 注释相关的依赖项。如果我真的知道运行时异常发生在哪里,那么我可能会找出错误在哪里。 阅读堆栈跟踪:它会告诉你异常是在哪里引发的。由于您只发布了堆栈跟踪的开头,我们无法知道。 我将发布整个堆栈跟踪,但原始问题之下的 90% 与第一个问题有关。通常,当最初的错误得到解决后,后续的问题就会消失。 由于论坛的字符数限制,我无法发布整个跟踪。我想补充一点,这是应用程序加载到 Tomcat 时的服务器堆栈跟踪。该应用程序尚未在服务器上运行,原因很明显:消息表明它无法运行。也许我创建的数据库不正确?这是我的 sql 代码:CREATE TABLE TEAM (ID IDENTITY, TEAMNAME VARCHAR(20), CITY VARCHAR(20)); CREATE TABLE PLAYER (ID IDENTITY, LASTNAME VARCHAR(25), FIRSTNAME VARCHAR(25), JERSEY INTEGER); 【参考方案1】:

问题出在 database.script 文件中。当我添加一个玩家表时,以下行被添加到脚本中(这一定是自动的,因为我没有接触过这个文件):

SET DATABASE SQL NULLS FIRST TRUE
SET DATABASE SQL AVG SCALE 0

然后我不得不改变这一行:

database.script 的变化来自

SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE

SET DATABASE TRANSACTION ROLLBACK ON DEADLOCK TRUE

谁能解释这是为什么? HSQL 不喜欢标记 NULLAVG?无论如何,那是在堆栈跟踪中。

【讨论】:

如果你运行hsqldb v2.2.6,当它关闭时,它会在你的db文件中添加SET DATABASE SQL AVG SCALE 0并将SET DATABASE TRANSACTION ROLLBACK ON DEADLOCK TRUE更改为SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE。删除 AVG 行(你会得到它的堆栈跟踪),并将 CONFLICT 改回 DEADLOCK (或者你也会得到堆栈跟踪)。然后您应该能够在 2.2.4 下再次运行数据库。至少这对我有用。【参考方案2】:

您必须在db.script 文件中更改这一行:

SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE

SET DATABASE TRANSACTION ROLLBACK ON DEADLOCK TRUE

在此之后再次打开db.script删除新生成的行

SET DATABASE SQL AVG SCALE 0

这将使它工作。

【讨论】:

以上是关于休眠错误消息:意外令牌:NULLS(脚本文件行中的错误:13 意外令牌:NULLS)的主要内容,如果未能解决你的问题,请参考以下文章

休眠异常:意外令牌:HAVING

致命错误:未捕获的异常“Phalcon\Mvc\Model\Exception”与消息“语法错误,意外令牌>,

意外的令牌:在休眠状态下使用 spring data jpa 时的位置

开玩笑错误意外的令牌...(ES6)

从服务器获取错误作为“消息”:“意外的令牌 d”

调用 TF.exe 的 powershell 脚本中的表达式或语句中出现意外的令牌“工作区”