告诉hibernate hbm2ddl不要创建单独的表 [英] Tell hibernate hbm2ddl not create individual table

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

问题描述

有没有办法告诉hibernate的hbm2ddl不要创建特定的表,但仍然可以通过Hibernate识别模型。



问题是模型映射到我想有一个内存数据库(启动时为空,终止时删除),因此,有2组映射是不可能的。

解决方案

好的,这并不能完全回答这个问题(目前的版本可能没有办法),但它确实解决了问题。



因此,最后我让hibernate创建表,但后来强行删除它并放入我自己的 create view 语句中。看来有两种方法可以做到。



第一种方法是使用< database-object> 元素,特别是名为< create> 的子元素,如下所示:

 < class table =MY_VIEW>< / class> 
< database-object>
< create>
drop table MY_VIEW;
创建视图MY_VIEW等等;
< / create>
< / database-object>

另一种方法是在import.sql中输入相同的东西。这件事没有记录。 我不知道为什么,也许它已被弃用。我认为它是如此,因此我不会在这里放置太多细节。它不被弃用,但是我发现前面的方法不那么痛苦(创建视图是几行)。

Is there a way to tell hibernate's hbm2ddl to not create specific table but still have the model be recognized by Hibernate.

The thing is that the model map to a view and I want to have an in-memory database (empty on startup and deleted on termination) for testing, hence, having 2 sets of mapping is out of the question.

解决方案

Okay, this doesn't exactly answer the question (there's probably no way to do it with current version) but it does solve the issue at hand.

So, in the end I let hibernate create the table but later on forcefully drop it and put in my own create view statement. It seems that there are 2 ways to do it.

The first way is by using the <database-object> element, specifically the child element called <create>, like so:

<class table="MY_VIEW"></class>
<database-object>
  <create>
    drop table MY_VIEW;
    create view MY_VIEW etc etc;
  </create>
</database-object>

The other way is by entering the same thing in the import.sql. This thing is undocumented. I don't know why, perhaps it's deprecated. I assume it is so, hence I won't put too much detail here. It's not deprecated, but I find the previous method less painful (the create view is several lines long).

这篇关于告诉hibernate hbm2ddl不要创建单独的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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