Hibernate可以在没有Spring的情况下生成表吗?

mer*_*esi 1 java spring hibernate jpa

我的项目有Hibernate,

但还没有春天.

我怀疑是否:

问题1:

persistence.xml中的Hibernate注释和方言属性足以让Hibernate生成表吗?

问题2:我猜也是,必须有类似Spring的东西来寻找注释并解雇生成事件并开始其他一些事情吗?

编辑:

我的persistence.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
    <persistence-unit name="Kutuphane2" transaction-type="RESOURCE_LOCAL">
        <non-jta-data-source>kutuphaneDS</non-jta-data-source>
        <properties>
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/kutuphane"/>
            <property name="javax.persistence.jdbc.user" value="root"/>
            <property name="javax.persistence.jdbc.password" value="root"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="create"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
        </properties>
    </persistence-unit>
</persistence>
Run Code Online (Sandbox Code Playgroud)

Lui*_*oza 5

persistence.xml中的Hibernate注释和方言属性足以让Hibernate生成表吗?

是的,Hibernate独立工作,Spring只是帮助Hibernate提供数据源并帮助您访问Hibernate API.

必须有类似Spring的东西来寻找注释并解雇生成事件并开始其他一些事情吗?

不,这也是Hibernate的工作,只需添加hibernate.hbm2ddl.auto属性即可.这在这里解释: