hibernate存储过程查询缓存(hibernate stored procedure query cache)
我们使用hibernate将存储过程结果映射到java对象。 它使用hibernate 4.1.x在SQL Server 2008上执行
@XmlRootElement(name = "hotel") @Entity @NamedNativeQuery(name = "fetchHotel", query = "{ call usp_iconnect_dashboard_gethotels(:screenname) }", resultSetMapping = "hotel-data", hints = {@QueryHint(name = "org.hibernate.callable", value = "true") } ) @SqlResultSetMapping(name = "hotel-data", entities = @EntityResult(entityClass = Hotel.class)) @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public class Hotel { /** * Unique hotel code. */ @Id @Column(name = "hotelcode") private String code; /** * Hotel name. */ @Column(name = "hotel") private String name; /** * Indicates if user belongs to hotel. * Y - if it is default hotel. * N - if it is not default hotel. */ @Column(name = "is_default") private String isDefault; /** * @return the code */ public final String getCode() { return code; } /** * @param code the code to set */ public final void setCode(final String code) { this.code = code; } /** * @return the name */ public final String getName() { return name; } /** * @param name the name to set */ public final void setName(final String name) { this.name = name; } /** * @return the isDefault */ public final String getIsDefault() { return isDefault; } /** * @param isDefault the isDefault to set */ public final void setIsDefault(final String isDefault) { this.isDefault = isDefault; } }
它可以很好地获取结果。
但是当启用二级缓存(ehcache)和查询缓存时。
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${dialect}</prop> <prop key="hibernate.show_sql">${showSQL}</prop> <prop key="format_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.connection.release_mode">on_close</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property>
它的工作正常,可以添加查询缓存。 但是在几次通话之后,它给出的错误如下。
DEBUG StandardQueryCache - Checking cached query results in region: DailyExpire DEBUG EhcacheGeneralDataRegion - key: sql: { call usp_iconnect_dashboard_gethotels(?) }; parameters: ; named parameters: {screenname=dhulipah}; transformer: org.hibernate.transform.CacheableResultTransformer@110f2 DEBUG StandardQueryCache - Checking query spaces are up-to-date: [Hotel] DEBUG EhcacheGeneralDataRegion - key: Hotel DEBUG EhcacheGeneralDataRegion - Element for key Hotel is null DEBUG StandardQueryCache - Returning cached query results Hibernate: select hotel0_.hotelcode as hotelcod1_1_0_, hotel0_.is_default as is2_1_0_, hotel0_.hotel as hotel3_1_0_ from Hotel hotel0_ where hotel0_.hotelcode=? WARN SqlExceptionHelper - SQL Error: 208, SQLState: S0002 ERROR SqlExceptionHelper - Invalid object name 'Hotel'. INFO DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: Invalid object name 'Hotel'. Jul 22, 2013 3:25:39 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container org.hibernate.exception.SQLGrammarException: Invalid object name 'Hotel'.
与上面的日志日志一样,它在一段时间后尝试获取SELECT查询而不是存储过程调用。
知道为什么会这样发生吗? 因此,查询缓存不能用于在hibernate中缓存存储过程。 是否有任何其他方法可以将缓存用于存储过程结果?
提前感谢您的帮助。
We are using hibernate to map stored procedure result to java object. Its using hibernate 4.1.x for executing on SQL server 2008
@XmlRootElement(name = "hotel") @Entity @NamedNativeQuery(name = "fetchHotel", query = "{ call usp_iconnect_dashboard_gethotels(:screenname) }", resultSetMapping = "hotel-data", hints = {@QueryHint(name = "org.hibernate.callable", value = "true") } ) @SqlResultSetMapping(name = "hotel-data", entities = @EntityResult(entityClass = Hotel.class)) @Cache(usage = CacheConcurrencyStrategy.READ_ONLY) public class Hotel { /** * Unique hotel code. */ @Id @Column(name = "hotelcode") private String code; /** * Hotel name. */ @Column(name = "hotel") private String name; /** * Indicates if user belongs to hotel. * Y - if it is default hotel. * N - if it is not default hotel. */ @Column(name = "is_default") private String isDefault; /** * @return the code */ public final String getCode() { return code; } /** * @param code the code to set */ public final void setCode(final String code) { this.code = code; } /** * @return the name */ public final String getName() { return name; } /** * @param name the name to set */ public final void setName(final String name) { this.name = name; } /** * @return the isDefault */ public final String getIsDefault() { return isDefault; } /** * @param isDefault the isDefault to set */ public final void setIsDefault(final String isDefault) { this.isDefault = isDefault; } }
Its working fine to fetch results.
However when enabled second level cache (ehcache) and query cache.
<property name="hibernateProperties"> <props> <prop key="hibernate.dialect">${dialect}</prop> <prop key="hibernate.show_sql">${showSQL}</prop> <prop key="format_sql">true</prop> <prop key="hibernate.current_session_context_class">thread</prop> <prop key="hibernate.connection.release_mode">on_close</prop> <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop> <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop> <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop> <prop key="hibernate.cache.use_second_level_cache">true</prop> <prop key="hibernate.cache.use_query_cache">true</prop> </props> </property>
Its working fine to add query cache. However after couple of calls, its giving error as below.
DEBUG StandardQueryCache - Checking cached query results in region: DailyExpire DEBUG EhcacheGeneralDataRegion - key: sql: { call usp_iconnect_dashboard_gethotels(?) }; parameters: ; named parameters: {screenname=dhulipah}; transformer: org.hibernate.transform.CacheableResultTransformer@110f2 DEBUG StandardQueryCache - Checking query spaces are up-to-date: [Hotel] DEBUG EhcacheGeneralDataRegion - key: Hotel DEBUG EhcacheGeneralDataRegion - Element for key Hotel is null DEBUG StandardQueryCache - Returning cached query results Hibernate: select hotel0_.hotelcode as hotelcod1_1_0_, hotel0_.is_default as is2_1_0_, hotel0_.hotel as hotel3_1_0_ from Hotel hotel0_ where hotel0_.hotelcode=? WARN SqlExceptionHelper - SQL Error: 208, SQLState: S0002 ERROR SqlExceptionHelper - Invalid object name 'Hotel'. INFO DefaultLoadEventListener - HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: Invalid object name 'Hotel'. Jul 22, 2013 3:25:39 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container org.hibernate.exception.SQLGrammarException: Invalid object name 'Hotel'.
As in log log above, its trying to fetch as SELECT query instead of stored procedure call after some time.
Any idea why is it happening like this ? Due to this, query cache can't be used for caching stored procedure in hibernate. Is there is any other way to use caching for stored procedure results ?
Thank you in advance for help.
原文:https://stackoverflow.com/questions/17792067
最满意答案
1)每个可编写脚本的应用程序都固有地记录在案。 在AppleScript编辑器中,从“文件”菜单中选择“打开字典...”并选择该应用程序。
2)不,您无法使用Spotify的脚本界面修改播放列表。
1) Every single scriptable app is inherently documented. In AppleScript Editor, choose Open Dictionary… from the File menu and choose the app.
2) No, you can't modify playlists using Spotify's scripting interface.
相关问答
更多-
显然, snapshot.toArray()元素与snapshot.ref(index) 。 更新:参考文档让我理解这一点 - https://developer.spotify.com/docs/apps/api/1.0/api-models-reference.html Apparently elements of snapshot.toArray() are not the same as snapshot.ref(index). Update: reference documentation tha ...
-
首先,如果你想创建一个私人播放列表,或者只是创建一个公共协作播放列表,你必须得到一个令牌(就像这里: http : //developers.deezer.com/api/explorer )(所以人们可以添加曲目到你的播放列表)。 您要做的第一件事是通过POST调用user / me | [您的用户ID] /播放列表( http://developers.deezer.com/api/user/playlists )和访问令牌来创建播放列表。 然后你只需对/ playlyst [你的播放列表的ID] / ...
-
看看AppleScript编辑器中的文档。 Track和context都是URI。 Spotify上下文是一个容器,客户端默认使用该曲目的专辑。 所以,举个例子,这两个都会在专辑的背景下播放曲目(它们在功能上是相同的): tell application "Spotify" play track "spotify:track:5Up9Lj7QWudEfMc0ve5qWW" end tell tell application "Spotify" play track "spotify:t ...
-
Spotify + AppleScript:将当前曲目添加到播放列表(Spotify + AppleScript: Add current track to playlist)[2023-10-13]
1)每个可编写脚本的应用程序都固有地记录在案。 在AppleScript编辑器中,从“文件”菜单中选择“打开字典...”并选择该应用程序。 2)不,您无法使用Spotify的脚本界面修改播放列表。 1) Every single scriptable app is inherently documented. In AppleScript Editor, choose Open Dictionary… from the File menu and choose the app. 2) No, you can ... -
{“error”:{“status”:403,“message”:“此请求需要用户身份验证。” }} 您要创建的将音轨添加到播放列表的请求需要连接到用户的访问令牌。 您使用的访问令牌可以来自三种不同的oAuth 2.0流程。 其中一个流程即客户端凭证流程返回匿名访问令牌。 或者更确切地说,访问简单地不连接到任何用户的令牌。 阅读“ 授权指南”中有关流程的更多信息。 对于某些端点,使用匿名访问令牌很好。 就像检索播放列表一样。 但是很多操作(如添加曲目,关注艺术家以及保存曲目)都需要用户给予您的应用程序明确许 ...
-
附加到Spotify播放列表(Append to Spotify playlist)[2023-05-08]
那么,根据文档,我的代码应该工作。 但是,我忽略了Collection的add方法。 感谢irc上的ocip。 Well, based on the documentation, my code should work. However, I overlooked the add method of Collection. Thanks to ocip on irc. -
https://github.com/plamere/spotipy/blob/master/examples/user_playlists_contents.py def show_tracks(results): for i, item in enumerate(tracks['items']): track = item['track'] print(" %d %32.32s %s" % (i, track['artists'][0]['name'], track['name']) ...
-
我的代码的另一部分导致了这种意外行为的错误。 上面的代码工作正常。 I had a mistake in another part of my code that was causing this unintended behavior. The above code works fine.
-
您可以将曲目添加到现有播放列表中。 请记住,您需要先加载曲目,否则曲目将不会出现在播放列表对象上。 require(['$api/models'], function(models) { models.Playlist.fromURI('spotify:user:thelinmichael:playlist:4GiqW15bSO7K6MLFVRVh4z').load('tracks').done(function(playlist) { track = models.Track.fr ...
-
使用Spotify Apps API从给定播放列表中的特定曲目开始(Start at specific track in given playlist with Spotify Apps API)[2022-04-17]
playContext文档声明该方法有四个参数,第二个是索引。 要播放的上下文中的第一项。 这必须是一个正数。 如果省略,则上下文中的第一个可播放项目将开始播放。 使用您的代码段: require(['$api/models'], function(models) { var index = 2; models.player.playContext(models.Playlist.fromURI('spotify:user:cevil:playlist:5f4EBgrnSf86Hr86kL4S90' ...