我如何复制“SHOW TABLES”在休眠? [英] How can I replicate "SHOW TABLES" in Hibernate?

查看:96
本文介绍了我如何复制“SHOW TABLES”在休眠?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图迭代所有的表,以便截断每一个表(在每个JBehave测试的开始处)。

I'm trying to iterate over all of my tables so I can truncate each one (at the beginning of each of my JBehave tests).

我以为我将能够:

I thought I would be able to:

List<String> allTables = session.createSQLQuery("SHOW TABLES").list();

但是hibernate抛出一个SQLGrammarException,抱怨没有找到列'TABLE_NAME'。

But hibernate throws a SQLGrammarException, complaining that "Column 'TABLE_NAME' not found."

我猜这是因为show tables查询实际上并没有返回一个字符串列表。是否有另一种方法来获取我所有使用Hibernate的表的列表?

I guess this is because the "show tables" query doesn't actually return a list of strings. Is there another way to get a list of all my tables using Hibernate?

推荐答案

试试这样:

Try something like this:

SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE();

对于列(与Hibernate相同的情况),请尝试:

For columns (same situation with Hibernate) try:

SELECT column_name FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME=YOUR_TABLE_NAME

这篇关于我如何复制“SHOW TABLES”在休眠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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