package org.mifos.application.messagecustomizer;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.NamedNativeQuery;

@NamedQueries( {
	  @NamedQuery(
			    name="allMessages",
			    query="from CustomizedText"
			  ),
	  @NamedQuery(
	          name = "findCustomMessageByOldMessage",
	          query = "from CustomizedText message where message.originalText=:originalText"
	  )	  
})

	  @NamedNativeQuery(
	    name="allMessagesNative",
	    cacheable=true,
	    query="select * from customized_text order by char_length(original_text) desc",
	    resultClass = CustomizedText.class
	  )

@Entity
@Table(name = "customized_text")
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CustomizedText {

    @Id
	private String originalText;
	private String customText;
	
	protected CustomizedText() {}
	
	public CustomizedText(String originalText, String customText) {
		super();
		this.originalText = originalText;
		this.customText = customText;
	}

	public String getOriginalText() {
		return originalText;
	}

	public void setOriginalText(String originalText) {
		this.originalText = originalText;
	}

	public String getCustomText() {
		return customText;
	}

	public void setCustomText(String customText) {
		this.customText = customText;
	}
	

}

@@ -108,14 +108,14 @@
 nce.
-Column
+Entity
 ;%0Aim
@@ -129,38 +129,34 @@
 vax.persistence.
-Entity
+Id
 ;%0Aimport javax.p
@@ -170,51 +170,24 @@
 nce.
-GeneratedValue;%0Aimport javax.persistence.Id
+NamedNativeQuery
 ;%0Aim
@@ -256,24 +256,60 @@
 NamedQuery;%0A
+import javax.persistence.QueryHint;%0A
 import javax
@@ -453,36 +453,22 @@
 ate.
-annotations.NamedNativeQuery
+ejb.QueryHints
 ;%0A%0A@
@@ -730,19 +730,16 @@
 xt%22%0A%09  )
-%09  
 %0A%7D)%0A%0A%09  
@@ -792,29 +792,8 @@
 e%22,%0A
-%09    cacheable=true,%0A
 %09   
@@ -912,16 +912,90 @@
 xt.class
+,%0A%09    hints = %7B @QueryHint(name=QueryHints.HINT_CACHEABLE,value=%22true%22) %7D
 %0A%09  )%0A%0A@
@@ -1204,17 +1204,16 @@
 omText;%0A
-%09
 %0A%09protec
@@ -1236,17 +1236,16 @@
 xt() %7B%7D%0A
-%09
 %0A%09public
@@ -1680,13 +1680,12 @@
 ext;%0A%09%7D%0A
-%09
 %0A%0A%7D%0A

use javax.persistence.NativeNamedQuery with vender specific caching settings