{"action":"created","issue":{"url":"https://api.github.com/repos/theupswell/appengine-counter/issues/21","labels_url":"https://api.github.com/repos/theupswell/appengine-counter/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/theupswell/appengine-counter/issues/21/comments","events_url":"https://api.github.com/repos/theupswell/appengine-counter/issues/21/events","html_url":"https://github.com/theupswell/appengine-counter/issues/21","id":78458871,"number":21,"title":"Cast exception when calling increment","user":{"login":"billy1380","id":1329727,"avatar_url":"https://avatars.githubusercontent.com/u/1329727?v=3","gravatar_id":"","url":"https://api.github.com/users/billy1380","html_url":"https://github.com/billy1380","followers_url":"https://api.github.com/users/billy1380/followers","following_url":"https://api.github.com/users/billy1380/following{/other_user}","gists_url":"https://api.github.com/users/billy1380/gists{/gist_id}","starred_url":"https://api.github.com/users/billy1380/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/billy1380/subscriptions","organizations_url":"https://api.github.com/users/billy1380/orgs","repos_url":"https://api.github.com/users/billy1380/repos","events_url":"https://api.github.com/users/billy1380/events{/privacy}","received_events_url":"https://api.github.com/users/billy1380/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-05-20T09:59:32Z","updated_at":"2015-05-22T18:23:01Z","closed_at":null,"body":"I am getting a cast exception when calling the increment method in some instances\r\n\r\n``` java\r\njava.lang.ClassCastException: com.google.appengine.api.datastore.Entity cannot be cast to com.theupswell.appengine.counter.data.CounterData\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl$3.run(ShardedCounterServiceImpl.java:904)\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl$3.run(ShardedCounterServiceImpl.java:900)\r\n\tat com.googlecode.objectify.impl.TransactorYes.transact(TransactorYes.java:102)\r\n\tat com.googlecode.objectify.impl.ObjectifyImpl.transact(ObjectifyImpl.java:178)\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl.getOrCreateCounterData(ShardedCounterServiceImpl.java:899)\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl$IncrementShardWork.run(ShardedCounterServiceImpl.java:447)\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl$IncrementShardWork.run(ShardedCounterServiceImpl.java:412)\r\n\tat com.googlecode.objectify.impl.TransactorNo.transactOnce(TransactorNo.java:118)\r\n\tat com.googlecode.objectify.impl.TransactorNo.transactNew(TransactorNo.java:95)\r\n\tat com.googlecode.objectify.impl.TransactorNo.transact(TransactorNo.java:85)\r\n\tat com.googlecode.objectify.impl.ObjectifyImpl.transact(ObjectifyImpl.java:178)\r\n\tat com.theupswell.appengine.counter.service.ShardedCounterServiceImpl.increment(ShardedCounterServiceImpl.java:389)\r\n```"},"comment":{"url":"https://api.github.com/repos/theupswell/appengine-counter/issues/comments/104736867","html_url":"https://github.com/theupswell/appengine-counter/issues/21#issuecomment-104736867","issue_url":"https://api.github.com/repos/theupswell/appengine-counter/issues/21","id":104736867,"user":{"login":"sappenin","id":323659,"avatar_url":"https://avatars.githubusercontent.com/u/323659?v=3","gravatar_id":"","url":"https://api.github.com/users/sappenin","html_url":"https://github.com/sappenin","followers_url":"https://api.github.com/users/sappenin/followers","following_url":"https://api.github.com/users/sappenin/following{/other_user}","gists_url":"https://api.github.com/users/sappenin/gists{/gist_id}","starred_url":"https://api.github.com/users/sappenin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sappenin/subscriptions","organizations_url":"https://api.github.com/users/sappenin/orgs","repos_url":"https://api.github.com/users/sappenin/repos","events_url":"https://api.github.com/users/sappenin/events{/privacy}","received_events_url":"https://api.github.com/users/sappenin/received_events","type":"User","site_admin":false},"created_at":"2015-05-22T18:23:01Z","updated_at":"2015-05-22T18:23:01Z","body":"Hi, thanks for following up on this issue.  Yes, as you pointed out, currently appengine-counter doesn't automatically register its entities for you.  You'll need to manually register them along with your other entities -- a factory like you indicated is the ideal place.  Motomapia (created by Jeff, the creator of objectify) provides a good example: \r\n\r\nhttps://github.com/stickfigure/motomapia/blob/master/src/main/java/com/motomapia/OfyFactory.java\r\n\r\nWe don't want ShardedCounterServiceImpl to accept an ObjectifyService in the constructor because this might cause problems.  See here for more details:\r\n\r\n[Can I use Dependency Injection with Objectify](https://github.com/objectify/objectify/wiki/FrequentlyAskedQuestions#can-i-use-dependency-injection-spring-guice-weld-with-objectify)\r\n\r\nHowever, thinking about this more, it seems like there's only ever a single ObjectifyFactory floating around, which is where these entities would be registered, so it might make sense to add another constructor to ShardedCounterServiceImpl that requires an ObjectifyFactory.  That way, when you construct the ShardedCounterService (or when you DI system does) appengine-counter could auto-register the entities.  I'll experiment with that to see if it can work."}}