1

Testing in ObjectDB explorer while running query:

SELECT FROM Post p
WHERE id=:id

with parameter id set to 3007120 gives me this result: Result for Post id 3007120

But running a query:

SELECT p.id FROM Post p
WHERE id=:id

with the same parameter id of 3007120 returns an integer. Result for a second query

The weird part is, other entities, stored at basically the same time, from exactly the same source, with the very same process, return Long and long respectively.

Checking the Database schema in ObjectDB explorer tells me that the field is supposed to be long. In my Entity class the field is annotated with just ID and has only standard get/set methods

 @Id private long id;

Tried whatever I could think of and just cant figure this one out.

EDIT: As an additional question, why does it say long - the primitive type, when I retrieve the whole Entity but shows Long/Integer when i retrieve just the id?

Community
  • 1
  • 1
MIeraK
  • 23
  • 1
  • 7
  • When you query entity JPA engine converts properties to types defined in your Java class – Ivan Nov 07 '18 at 21:16
  • Is it possible that this specific id field changed its type from int to long and that the specific entity object was stored in the database before the change? – ObjectDB Nov 07 '18 at 21:17
  • @ObjectDB No its not, this very database is hours old - I am still in early development. I deleted the whole database file and everything was resaved again(the source data is a JSON API) after making some changes to the code, but no changes were done to the Post entity class anyway. – MIeraK Nov 07 '18 at 21:27
  • @Ivan I have troubles understanding your comment. Since the source entity is Post with id defined as primitive long and when I issue query to the DB it again creates a Post entity with id field as primite long - there shouldnt be any conversion happening?. Also if I just query the DB in my program to select the whole Post the ID in the Post instance is yet again, long. – MIeraK Nov 07 '18 at 21:39
  • This is regarding your **EDIT** part of the question. Since your entity `id` property defined as `long` (primitive) you will always see `long` when querying entity – Ivan Nov 07 '18 at 21:43
  • So you mean that the underlying persisted field is indeed Integer and when I query for the whole entity it gets converted to long, but when I query just the ID it doesnt do that because its not trying to create the Post entity? – MIeraK Nov 07 '18 at 21:48
  • You may want to post a complete small runnable test case that demonstrates the issue. See https://www.objectdb.com/database/post for a template test case that you can start with. – ObjectDB Nov 07 '18 at 23:04
  • I will try to isolate the problem, the project is not that small. – MIeraK Nov 08 '18 at 00:48

0 Answers0