Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » EclipseLink: Constructor & Query Results Cache
EclipseLink: Constructor & Query Results Cache [message #1725257] Wed, 02 March 2016 07:50 Go to next message
Rainer Schmand is currently offline Rainer SchmandFriend
Messages: 4
Registered: March 2016
Junior Member
how do i combine 2n-level-caching with queries that use a constructor-call?

1. cache activated, works.
   @NamedQueries({
          @NamedQuery(
		        name = "countryNamesByCode", 
		  query = "SELECT c FROM Country c WHERE c.isoCode = :paramIsoCode",
		  hints={ 
			 @QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE)					
		 }
		)
        })
        @Entity
        public class Country extends AbstractEntity {
	
        	//...
	
        	public static List<Country> getCountries(final String isoCode) {
		      final Query userQuery =     getEntityManager().createNamedQuery("countryNamesByCode");
      		  userQuery.setParameter("paramIsoCode", isoCode);
		      return (List<Country>) userQuery.getResultList();
     	    }
        }




2. does not work. database is hit every time

  @NamedQueries({
	     @NamedQuery(				 
			name = "getProductsByLanguage", 
			query = "SELECT NEW de.markets.products.entity.Product(p.id, t.contentText)"
				 + " FROM Translations t, Product p"
				 + " WHERE t.translationId = p.categoryName"
				 + " AND t.languageId =:language",
			hints={ 
					@QueryHint(name = QueryHints.QUERY_RESULTS_CACHE, value = HintValues.TRUE)					
				    }
	      )
        })
          @Entity
         public class Product extends AbstractEntity {
	
	     public static List<Product> getAllProductsByLanguage(final int languageID) {
		     final Query userQuery = getEntityManager().createNamedQuery("getProductsByLanguage");
		     userQuery.setParameter("language", languageID);		
		     return (List<Product>) userQuery.getResultList();
	     }


Re: EclipseLink: Constructor & Query Results Cache [message #1725330 is a reply to message #1725257] Wed, 02 March 2016 15:28 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1379
Registered: July 2009
Senior Member
You cannot as constructor queries construct java objects, not managed entities.
Previous Topic:Excluding specific fields when using OptimisticLockingType.CHANGED_COLUMNS
Next Topic:eclipselink history policy: history records with null id
Goto Forum:
  


Current Time: Thu Feb 25 08:54:44 GMT 2021

Powered by FUDForum. Page generated in 0.01495 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top