2016-03-13 57 views
0

这是我的代码,我在eclipse中创建了一个动态web项目,并编写了持久化类和下面的代码。我也在MySQL中创建数据库,但我没有得到这个自动表创建。我在普通的Java项目中获得了它,但是在动态Web项目中,我得到了“请求的资源不可用”。当我运行Test.java时,是否应该在web.xml或index.jsp中写入任何内容?如何在spring动态web项目中创建自动表格

<hibernate-configuration> 
     <session-factory> 
     <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/studentdb </property> 
     <property name="hibernate.connection.username">studb</property> 
     <property name="hibernate.connection.password">12345</property> 
    <property name="connection.pool_size"> 1</property> 

     <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> 
     <property name="hbm2ddl.auto">create</property> 
     <property name="show_sql">true</property> 


     <!-- List of XML mapping files --> 
     <mapping resource="student.hbm.xml"/> 

     </session-factory> 
    </hibernate-configuration> 

Test.java

public class Test { 

    public static void main(String[] args) { 
     Configuration cfg=new Configuration(); 
     cfg.configure("hibernate.cfg.xml"); 
     cfg.buildSessionFactory(); 
    } 

} 

student.hbm.xml

<hibernate-mapping> 
    <class name="com.javathub.Student" table="stu_details"> 
    <id name="id"> 
    <generator class="assigned"></generator> 
    </id> 
    <property name="name"></property> 
    <property name="branch"></property> 
    <property name="fee"></property> 
    </class> 
    </hibernate-mapping> 

的web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 
    <display-name>Univerysity</display-name> 
    <welcome-file-list> 

    <welcome-file>index.jsp</welcome-file> 

    </welcome-file-list> 
</web-app> 

回答

0

您需要使用hibernate.hbm2ddl.auto而不是hbm2ddl.auto。你可以看到documentation了解更多信息。