简体   繁体   English

如何在mysql中编写数据库视图的HQL查询

[英]How to write the HQL query for database view in mysql

I am using netbean and followed below steps to execute HQL query for table 我正在使用netbean并按照以下步骤执行表的HQL查询

  1. Did Reverse Engg Reverse Engg
  2. Generated mapping and POJO 生成的映射和POJO

     Query query = session.createQuery("from MasUser as masUser where masUser.userName = '" + userName + "'"); masUser = (masUser) query.uniqueResult(); 

Now I am able to execute and got result. 现在我能够执行并获得结果。


Then I have created view for this table 然后我为这个表创建了视图

  CREATE VIEW test_view AS SELECT user_name, address FROM mas_user

Now I need to execute test_view in hibernate HQL. 现在我需要在hibernate HQL中执行test_view。

Please provide the steps. 请提供步骤。

If you created the view in the database, the process of querying a view is exactly the same as working with a table. 如果在数据库中创建了视图,则查询视图的过程与使用表完全相同。 Simply create an entity (POJO) for the view, attach the mapping annotations and then create and execute a query. 只需为视图创建实体(POJO),附加映射注释,然后创建并执行查询。 Repeat the same process that you did for your MasUser table. 重复与MasUser表相同的过程。

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

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