cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Huss (JIRA)" <>
Subject [jira] [Commented] (CAY-2558) cgen: primitives for mandatory properties
Date Tue, 16 Apr 2019 21:41:00 GMT


John Huss commented on CAY-2558:

Currently if an attribute is defined in modeler with type "java.lang.Integer", if the property
is mandatory the instance variable will have type "int". While that probably improves memory
usage it does seem to go against the user's stated desire to use java.lang.Integer not just
for the type of the getter and setter but also for storage. So yeah, I think the instance
variable's type should match what is declared in modeler. Then again, you can always make
your own templates. 

If you were going to add a setting it would be a checked-by-default one called "Use primitive
instance variables for mandatory attributes". Of course, many mandatory attributes don't even
have a primitive representation, so that is an inconsistency too.

The changes in 4.1 do change the behavior where before even if your mandatory attribute was
declared as type "int" you would still get validation errors if you forgot to set it to a
value since everything was stored in a HashMap. I do see the problems with just ending up
with zero instead. But that is really a different problem.

Honestly, the real solution here would be to support simple validation rules, ala CoreData
models which have a configurable "Default", "Minimum" and "Maximum". So in the end I would
vote to keep it as is and someday add that validation instead.

> cgen: primitives for mandatory properties
> -----------------------------------------
>                 Key: CAY-2558
>                 URL:
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: cgen
>    Affects Versions: 4.1.B1
>            Reporter: Ilya Vasiuk
>            Priority: Major
> Would be cool to have possibility to not use primitives in object entities for mandatory
> Case: Somebody can forget to init some mandatory int field. And they'll get a lot of
rows with zeros instead of exception. This is not convenient imo.

This message was sent by Atlassian JIRA

View raw message