更改数据库名称时,Hibernate事务未成功启动

时间:2017-02-27 09:54:48

标签: mysql hibernate tomcat jdbc

我正在将一个web-app部署到一个连接到mysql容器的tomcat容器中。当我部署战争时,在创建MySQL数据库(通过hibernate.cfg.xml插入)之后,一切正常。

但是,如果我想将我的网络应用程序连接到我将战争部署到webapps /文件夹后创建的新数据库,我有以下几行:

27-Feb-2017 09:47:36.199 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
27-Feb-2017 09:47:36.200 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
27-Feb-2017 09:52:03.503 SEVERE [http-apr-8080-exec-7] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [controller.AccountController] in context with path [/ShoppingAT] threw exception
 org.hibernate.TransactionException: Transaction not successfully started
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:200)
    at model.AbstractModel.create(AbstractModel.java:137)
    at controller.AccountController.doPost(AccountController.java:113)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)     
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)      
        at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:509)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1104)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
        at org.apache.tomcat.util.net.AprEndpoint$SocketWithOptionsProcessor.run(AprEndpoint.java:2445)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:745)

我该如何解决这个问题?

这是我的hibernate.cfg.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC^M
                "-//Hibernate/Hibernate Configuration DTD 3.0//EN"^M
                "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">^M
<hibernate-configuration>^M
    <session-factory>^M
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>^M
        <property name="hibernate.connection.password">pass</property>^M
        <property name="hibernate.connection.url">jdbc:mysql://172.19.0.3:3306/shine</property>^M
        <property name="hibernate.connection.username">root</property>^M
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
          <property name="hibernate.current_session_context_class">thread</property>
           <mapping class="entities.Responsabile"/>
           <mapping class="entities.Utente"/>
    <!--       <mapping class="entities.Prodotti"/>  --> 
    </session-factory>
</hibernate-configuration>

我的目标是从我最初的.war创建一个新的(复制的)网络应用程序。所以,我已经重命名了我的战争,将其部署到webapps /,并编辑了hibernate.cfg.xml。如果我重命名我的战争并将其指向初始数据库,那就没关系了。当我指向另一个数据库时出现此问题。实际上,在日志中,存在初始Web应用程序(/ ShoppingAT)的“上下文路径”。

0 个答案:

没有答案