表不是由Hibernate创建的 [英] Table not created by Hibernate

查看:80
本文介绍了表不是由Hibernate创建的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注释了一堆POJO,所以JPA可以使用它们在Hibernate中创建表。看起来,除了一个名为Revision的非常中心的表之外,所有表格都被创建。 Revision类有一个 @Entity(name =RevisionT)注释,所以它将被重命名为RevisionT,所以不会与MySQL中的任何保留字发生冲突数据库)。



我删除整个数据库,重新创建它并基本打开和关闭JPA会话。所有的表似乎都没有问题重新创建。



为什么创建的模式中缺少单个表?什么仪器可以用来查看什么Hibernate产生和哪些错误?

谢谢。



更新:I试图创建一个Derby数据库,它是成功的。但是,其中一个字段的名称是索引。我使用 @ org.hibernate.annotations.IndexColumn 将名称指定为保留字以外的名称。但是,该列在创建时总是被称为索引。



以下是可疑注释示例。

  
@ManyToOne
@JoinColumn(name =MasterTopID)
@IndexColumn(name =Cx3tHApe)
protected MasterTop MASTERTOP;

而不是创建 MasterTop.Cx3tHApe 作为字段,它会创建 MasterTop.Index 。为什么名称被忽略?

解决方案

回答您的问题(可以使用哪些工具来查看Hibernate正在生成的内容以及哪些错误?)



您可以 org.hibernate.tool.hbm2ddl.SchemaExport 来生成您的表格。

  AnnotationConfiguration conf =(new AnnotationConfiguration())。configure(); 
新的SchemaExport(conf).create(showHql,run);

第一个参数允许您查看该命令生成的哪个HQL( CREATE TABLE s等)。第二个是它是否应该实际执行任何修改(即false =干运行)。

因此,使用(true,false) 会向你显示Hibernate会对你的表做些什么,而不会改变任何东西。


I annotated a bunch of POJO's so JPA can use them to create tables in Hibernate. It appears that all of the tables are created except one very central table called "Revision". The Revision class has an @Entity(name="RevisionT") annotation so it will be renamed to RevisionT so there is not a conflict with any reserved words in MySQL (the target database).

I delete the entire database, recreate it and basically open and close a JPA session. All the tables seem to get recreated without a problem.

Why would a single table be missing from the created schema? What instrumentation can be used to see what Hibernate is producing and which errors?

Thanks.

UPDATE: I tried to create as a Derby DB and it was successful. However, one of the fields has a a name of "index". I use @org.hibernate.annotations.IndexColumn to specify the name to something other than a reserved word. However, the column is always called "index" when it is created.

Here's a sample of the suspect annotations.


    @ManyToOne
    @JoinColumn(name="MasterTopID")
    @IndexColumn(name="Cx3tHApe")
    protected MasterTop masterTop;

Instead of creating MasterTop.Cx3tHApe as a field, it creates MasterTop.Index. Why is the name ignored?

解决方案

Answer to your side question (What instrumentation can be used to see what Hibernate is producing and which errors?)

You can org.hibernate.tool.hbm2ddl.SchemaExport to generate your tables.

AnnotationConfiguration conf = (new AnnotationConfiguration()).configure();
new SchemaExport(conf).create(showHql, run);

The first argument allows you to see which HQL this command generates (CREATE TABLEs etc). The second one is whether it should actually perform any modifications (ie false = dry-run).

So running it with (true, false) will show you exactly what Hibernate would do to your tables, without changing anything.

这篇关于表不是由Hibernate创建的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆