我真的想知道更多有关更新,导出和可以提供给hibernate.hbm2ddl.auto
我需要知道何时使用更新的值的更多信息,何时不知道?还有什么选择?
这些是可能发生在DB上的变化:
在每种情况下,最佳解决方案是什么?
是否可以运行配置的Hibernate应用程序hbm2ddl.auto=update来更新生产环境中的数据库模式?
我正在查看Hibernate hbm2ddl.auto配置属性及其可能的值:
validateupdatecreatecreate-drop所有这些价值观做了什么?
在Hibernate参考文档只是简单地谈约create-drop,但并没有说明其他任何值:
hibernate.hbm2ddl.auto
SessionFactory创建时,自动验证或将架构DDL导出到数据库.使用时create-drop,将在SessionFactory显式关闭数据库模式时删除它.例如
validate|update|create|create-drop
我在这些Stack Overflow问题中找到了非常有用的解释:
但官方文档中仍然没有任何内容.
在Hibernate 4.x中,我曾经生成并导出了注释实体中定义的模式,如下所示(使用Spring在类路径上查找带注释的实体):
Connection connection =
DriverManager.getConnection("jdbc:h2:mem:jooq-meta-extensions", "sa", "");
Configuration configuration = new Configuration()
.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect");
// [...] adding annotated classes to Configuration here...
configuration.generateSchemaCreationScript(
Dialect.getDialect(configuration.getProperties()));
SchemaExport export = new SchemaExport(configuration, connection);
export.create(true, true);
Run Code Online (Sandbox Code Playgroud)
这在Hibernate 5.0中不再有效:
除了以下内容之外,我没有在迁移指南中找到任何明显的引用变化:
从配置中删除了相当多的方法
基于一组带注释的实体,使用Hibernate 5.0在现有JDBC连接上生成和导出数据库的正确方法是什么?(基于JPA的纯解决方案也很好)
(注意,只是删除呼叫generateSchemaCreationScript()似乎工作,但我宁愿确保这是正确的)
我正在尝试使用hbm2ddl.auto = update更新现有表.
在几个表中有几列,其中数据库列定义从实体中的声明更改.喜欢
@Column(name="mycolumn", nullable=false, length=10)
private Long mycolumn;
Run Code Online (Sandbox Code Playgroud)
和
'mycolumn'bigint(20)not null默认值为0
在MySQL中.
为什么hbm2ddl不更新这样的东西?是否有可能强制进行此类更新?我想说hbm2ddl删除列的默认值并更改类型的长度.
我感兴趣的是hibernate.hbm2ddl.auto = validate实际上是如何工作的,我很难找到全面的文档.
我们最近发现生产系统受到http://opensource.atlassian.com/projects/hibernate/browse/HHH-3532的影响(Hibernate在名称上匹配外键,而不是签名,所以会为你重新创建它们)和hibernate .hbm2ddl.auto =正在从我们的下一个版本中删除更新.
我很乐意完全摆脱hibernate.hbm2ddl.auto并自己管理我们的数据库.但是,并非所有同事都分享这个世界观,有些人热衷于在hibernate.hbm2ddl.auto = validate中添加.
我担心这会遇到同样的问题,我有兴趣找到有关此验证实际工作原理的更多文档.Hibernate社区文档(http://docs.jboss.org/hibernate/core/3.3/reference/en/html/session-configuration.html)实际上只是引用了这些值.
有没有人有任何好的文档指针,或在生产系统中使用验证的任何实际经验?
我想第一次在hibernate中创建数据库模式.而且,如果模式中有任何修改,例如添加新表或删除某些列,我想更新现有模式,保持以前的数据不变.
根据此问题给出的选项,看起来我可以创建模式破坏以前的数据,或者我可以更新模式.
有什么价值可以兼得吗?
引用自persistence.xml:
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.hbm2ddl.auto" value="create" />
...
</properties>
</persistence-unit>
Run Code Online (Sandbox Code Playgroud)
这是我在日志输出中看到的:
Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
Sep 30, 2010 12:03:43 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
Run Code Online (Sandbox Code Playgroud)
但我没有看到模式(SQL)导出自己.如何从Hibernate(3.5.6-Final)获取此信息?
在我的春季mvc应用程序中,我有以下对象.我试图devtool在我的应用程序中使用数据视觉.
@Entity
@Data
public class ConsultationRequest {
@Id
@GeneratedValue
private Long id;
private String name;
private String email;
private String purpose;
private String programme;
private int year;
private String language;
private String comments;
@Enumerated(EnumType.STRING)
private ConsultationStatus status;
}
Run Code Online (Sandbox Code Playgroud)
然后我使用jpa来制作实体:
@Repository
public interface ConsultationRequestRepository extends JpaRepository<ConsultationRequest, Long> {
}
Run Code Online (Sandbox Code Playgroud)
问题是当我加载我的应用程序时,我遇到了2个错误:
Unsuccessful: drop sequence hibernate_sequence
[36morg.hibernate.tool.hbm2ddl.SchemaExport Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
Run Code Online (Sandbox Code Playgroud)
然后,当我打开
http://localhost:8080/h2-console/
Run Code Online (Sandbox Code Playgroud)
我看不到桌子.似乎在启动过程中,表没有制作.