简体   繁体   English

查询NHibernate中的临时表

[英]Querying a Temporary Table in NHibernate

I have a process which generates a result set for me and stores it in a temporary table.我有一个为我生成结果集并将其存储在临时表中的过程。 I have the name of the temporary table.我有临时表的名称。 I am trying to find a way, using NHibernate, to create a DetachedCriteria against the temporary table.我试图找到一种方法,使用 NHibernate 针对临时表创建 DetachedCriteria。 To put it another way, I have a table [Book] which has a column, [BookId] .换句话说,我有一个表[Book] ,其中有一列[BookId] I have a temporary table [TempTableName] , which has a column [TempId] .我有一个临时表[TempTableName] ,其中有一列[TempId] I want to create a DetachedCriteria for the [Book] table, wherein all the [Book] s with [BookId] in [TempTableName] .我想为[Book]表创建一个 DetachedCriteria ,其中[TempTableName]中所有带有[BookId][Book ] 。 [TempId] are returned. [TempId]被返回。 Is there any way to do this, preferably with the Criteria API?有什么方法可以做到这一点,最好使用标准 API? Especially given that the name of the temp table itself may vary from run to run?特别是考虑到临时表本身的名称可能因运行而异?

Hm, I'd say it should be possible and maybe even without extending/changing Hibernate/NHibernate.嗯,我想说这应该是可能的,甚至可能不需要扩展/更改 Hibernate/NHibernate。

You could introduce a class that maps the temporary table, but that table would only exist (sometimes) at runtime, so Hibernate's validation would probably complain at startup, unless you disable it, which is possible as far as i recall.您可以引入一个映射临时表的 class,但该表仅在运行时(有时)存在,因此 Hibernate 的验证可能会在启动时抱怨,除非您禁用它,据我记得这是可能的。

Have you tried mapping a class to a temporary table?您是否尝试过将 class 映射到临时表? The naming scheme of the temporary tables might be problematic in query generation.临时表的命名方案可能在查询生成中存在问题。 They will probably be specific to your RDBMS.它们可能特定于您的 RDBMS。

I guess that all these things can be solved by extending some Hibernate classes, but I have not tried.我想所有这些事情都可以通过扩展一些 Hibernate 类来解决,但我没有尝试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM