cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lucas Holt <>
Subject Strange Cayenne problem
Date Fri, 18 Jun 2010 20:15:10 GMT
Earlier today, I was writing some unit tests and stumbled onto a strange 
problem with some existing code we have.  A result is getting returned 
for something that does not exist in the database.

I've included the method that's getting called below.  Given a specific 
input, we get a valid object even though there is nothing close to it.

We have a system with a "publications" table and a publication editions 
table.  The latter is an instance of a publication typically used when 
we have a newsletter from a specific date.  If we use today's date and a 
publication name we'll call A, we get a PublicationEditions object for 
publication B on a different date from last year.  The primary key is 
different as is all the other meta data for the PublicationEditions 
object (a cayenne generated class).

The only possibility I've come up with is that there is some hash used 
in the system and we happened to hit a collision.  Is this a 
possibility?  We've been using Cayenne's LRU algorithm, but I've tried 
switching to oscache today as well with the same results (also LRU).

Lucas Holt

  public lookup(final String 
publicationName, final Date date)
             throws IllegalArgumentException, ModelException { pe = null;

         if (publicationName == null || publicationName.length() > 255
                 || publicationName.length() < 1) {
             throw new IllegalArgumentException("Invalid publication name");

         if (date == null) {
             throw new IllegalArgumentException("Invalid date");

         try {
             Expression qualifier =
Expression.fromString("publicationEditionsPublication.publicationName = 
$pn and publicationEditionDate=$date");
             final HashMap<String, Object> map = new HashMap<String, 
             map.put("pn", publicationName);
             map.put("date", date);
             qualifier = qualifier.expWithParameters(map);
             final SelectQuery query = new 
SelectQuery(, qualifier);

             final List<> editions = 
             logger.debug( "Number of found items is " + editions.size());
             if (!editions.isEmpty()) {
                 pe = editions.get(0);
                 logger.debug(pe.getPublicationEditionsId() + ", " + 
         } catch (CayenneRuntimeException ce) {
             logger.error("Cayenne error looking up edition: " + 
             throw new ModelException("Could not lookup edition");

         return pe;

View raw message