gpt4 book ai didi

java - 没有Spring,Hibernate可以生成表吗?

转载 作者:行者123 更新时间:2023-11-29 07:48:05 25 4
gpt4 key购买 nike

我的项目中有 Hibernate,

但还没有 Spring 。

我想知道是否:

问题一:

persistence.xml 中的Hibernate annotations 和dialect propert 是否足以让Hibernate 生成表?

问题二:另外我想,一定有像 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>

最佳答案

Hibernate annotations and dialect propert in persistence.xml is enough for Hibernate to generate tables?

是的,Hibernate 自己工作,Spring 只是帮助 Hibernate 提供数据源并帮助您访问 Hibernate API。

there must be something like Spring to look for annotations and fire a generation event and start some other things?

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

关于java - 没有Spring,Hibernate可以生成表吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23681532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com