0

I have a requirement to implement cache, with that cache it will execute Hibernate query.

I want to fetch the value(option_key) from the cache.xml, that loaded value should be placed in the SQL query. Later hibernate will execute that query. Is there any way I can do like that.

cache.xml

<section name="system_configuration">
<entry key="option_key"  value="some_value" />

MyCache.java

public List getList()
{
    String mysqlquery = "SELECT OPTION_SETTING FROM CONFIGURATION WHERE"
        + " OPTION_NAME='some_column_name' AND OPTION_KEY='value_from_cache.xml'";
    Session ses= sessionFactory.openSession();
    Query query = ses.createSQLQuery(mysqlquery);
    List result = query.list();
    return result;
}
veljkost
  • 1,748
  • 21
  • 25
Arvind Katte
  • 995
  • 2
  • 10
  • 20
  • Do you need a own implementation? Please add a question with details. Investigate https://commons.apache.org/proper/commons-configuration/ – Vitalii Pro Nov 23 '16 at 13:51
  • Ya, It's, own implementation.Hibernate performance issue is their, so we are using caching for performance. – Arvind Katte Nov 23 '16 at 13:56
  • Hibernate can use second level cache. http://stackoverflow.com/questions/7058843/when-and-how-to-use-hibernate-second-level-cache – Vitalii Pro Nov 23 '16 at 14:52

1 Answers1

0

First of you would need to read that xml file to get the desired value, as a reference you could use this: https://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/

Then use that value to place it in the query.

Flakron Bytyqi
  • 3,234
  • 20
  • 20