2015-12-24 133 views
0

在這一點上,我一直試圖設置Wicket與Hibernate和MySQL好幾個小時。我正在使用Maven作爲依賴管理。無可否認,我對Jave 2EE有點新,如果有什麼我可以提供的讓我知道,我會得到它。配置Hibernate ClassNotFoundException

我的HibernateUtil(這是許多嘗試之一,但最有意義的我)

public class HibernateUtil{ 
    private static SessionFactory sessionFactory = initSessionFactory(); 
    private static Properties getHibernateProperties(){ 
     return new Properties(){ 
     { 
      setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); 
      setProperty("hibernate.connection.driver_class","com.mysql.jdbc.Driver"); 
      setProperty("hibernate.connection.url","jdbc:mysql://192.168.33.15/eventApp"); 
      setProperty("hibernate.connection.username","root"); 
      setProperty("hibernate.connection.password","test101"); 
     } 
    }; 
} 

private static SessionFactory initSessionFactory(){ 
    Configuration cfg = new Configuration(); 
    cfg.setProperties(getHibernateProperties()); 
    return cfg.buildSessionFactory(); 
} 
public static SessionFactory getSessionFactory(){ 
    return sessionFactory; 
} 

}

我可以看看在罈子裏,看看Configuration.java然而,當我保存形式,調用HomePage.java

public class HomePage extends BaseTemplate { 
    Event event= new Event(); 
    // TODO Add any page properties or variables here 

/** 
* Constructor that is invoked when page is invoked without a session. 
* 
* @param parameters 
*   Page parameters 
*/ 
public HomePage(final PageParameters parameters) { 

    Form createEventForm = new Form("createEventForm"){ 
     @Override 
     protected void onSubmit() { 
      super.onSubmit(); 
      System.out.println("### Event name: " + event.getEventName()); 

      SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); 
      Session session = sessionFactory.openSession(); 
      session.getTransaction().begin(); 
      session.persist(event); // cascades the tool & skill relationships 
      session.getTransaction().commit(); 
     } 
    }; 

    TextField eventName = new TextField("eventName",new PropertyModel(event, "eventName")); 

    createEventForm.add(eventName); 
    add(createEventForm); 

} 

}

到Hibern調用ateUtil失敗,下面

java.lang.ClassNotFoundException: javax.transaction.SystemException 
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333) 
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1167) 
at java.lang.Class.forName0(Native Method) 
at java.lang.Class.forName(Unknown Source) 
at org.jboss.logging.Logger$1.run(Logger.java:2554) 
at java.security.AccessController.doPrivileged(Native Method) 
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2529) 
at org.jboss.logging.Logger.getMessageLogger(Logger.java:2516) 
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28) 
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24) 
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:86) 
at com.dappercloud.wicket.wicket.util.HibernateUtil.initSessionFactory(HibernateUtil.java:29) 
at com.dappercloud.wicket.wicket.util.HibernateUtil.<clinit>(HibernateUtil.java:15) 
at com.dappercloud.wicket.wicket.home.HomePage$1.onSubmit(HomePage.java:40) 
at org.apache.wicket.markup.html.form.Form.delegateSubmit(Form.java:1328) 
at org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:776) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at org.apache.wicket.RequestListenerInterface.invoke(RequestListenerInterface.java:183) 
at org.apache.wicket.request.target.component.listener.ListenerInterfaceRequestTarget.processEvents(ListenerInterfaceRequestTarget.java:73) 
at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:91) 
at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1166) 
at org.apache.wicket.RequestCycle.step(RequestCycle.java:1243) 
at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1330) 
at org.apache.wicket.RequestCycle.request(RequestCycle.java:493) 
at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:358) 
at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:194) 
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) 
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) 
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) 
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 
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:616) 
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) 
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) 
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) 
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) 
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) 
at java.lang.Thread.run(Unknown Source) 

我的POM文件的要求

<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.dappercloud.wicket</groupId> 
<artifactId>wicket</artifactId> 
<packaging>war</packaging> 
<version>0.0.1-SNAPSHOT</version> 
<!-- TODO project name --> 
<name>quickstart</name> 
<description></description> 

<!-- TODO 
    <organization> 
    <name>company name</name> 
    <url>company url</url> 
    </organization> 
--> 

<licenses> 
    <license> 
     <name>The Apache Software License, Version 2.0</name> 
     <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> 
     <distribution>repo</distribution> 
    </license> 
</licenses> 

<dependencies> 
    <!-- WICKET DEPENDENCIES --> 

    <dependency> 
     <groupId>org.apache.wicket</groupId> 
     <artifactId>wicket</artifactId> 
     <version>${wicket.version}</version> 
    </dependency> 
    <!-- OPTIONAL 
     <dependency> 
     <groupId>org.apache.wicket</groupId> 
     <artifactId>wicket-extensions</artifactId> 
     <version>${wicket.version}</version> 
     </dependency> 
    --> 

    <!-- LOGGING DEPENDENCIES - LOG4J --> 

    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-log4j12</artifactId> 
     <version>1.4.2</version> 
    </dependency> 
    <dependency> 
     <groupId>log4j</groupId> 
     <artifactId>log4j</artifactId> 
     <version>1.2.14</version> 
    </dependency> 

    <!-- JUNIT DEPENDENCY FOR TESTING --> 
    <dependency> 
      <groupId>junit</groupId> 
      <artifactId>junit</artifactId> 
      <version>3.8.2</version> 
      <scope>test</scope> 
    </dependency> 

    <!-- JETTY DEPENDENCIES FOR TESTING --> 

    <dependency> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>jetty</artifactId> 
     <version>${jetty.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>jetty-util</artifactId> 
     <version>${jetty.version}</version> 
     <scope>provided</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>jetty-management</artifactId> 
     <version>${jetty.version}</version> 
     <scope>provided</scope> 
    </dependency> 

    <!-- MYSQL JDBC --> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.38</version> 
    </dependency> 

    <!-- JPA Hibernate --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>5.0.6.Final</version> 
    </dependency> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-entitymanager</artifactId> 
     <version>5.0.6.Final</version> 
    </dependency> 

</dependencies> 

<build> 
    <resources> 
     <resource> 
      <filtering>false</filtering> 
      <directory>src/main/resources</directory> 
     </resource> 
     <resource> 
      <filtering>false</filtering> 
      <directory>src/main/java</directory> 
      <includes> 
       <include>**</include> 
      </includes> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </resource> 
    </resources> 
    <testResources> 
     <testResource> 
      <filtering>false</filtering> 
      <directory>src/test/java</directory> 
      <includes> 
       <include>**</include> 
      </includes> 
      <excludes> 
       <exclude>**/*.java</exclude> 
      </excludes> 
     </testResource> 
    </testResources> 
    <plugins> 
     <plugin> 
      <groupId>org.mortbay.jetty</groupId> 
      <artifactId>maven-jetty-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 

<properties> 
    <wicket.version>1.3.2</wicket.version> 
    <jetty.version>6.1.4</jetty.version> 
</properties> 

+0

請出示您的pom.xml文件 –

回答

1
<dependency> 
    <groupId>javax.transaction</groupId> 
    <artifactId>jta</artifactId> 
    <version>1.0.1B</version> 
</dependency> 

needs to be added, also make sure that jar is in your class path. 
+0

是否有您選擇1.0.1B具體原因我得到一個錯誤,並研究它。我發現[鏈接] http://stackoverflow.com/questions/19086523/missing-artifact-javax-transactionjtajar1-0-1b-issue-was-different-as-you-m建議使用1.1。我做了,似乎都在工作 – nerdlyist

+0

很高興聽到問題得到解決。特定版本不是必需的。使用最新版本是好的。 –