Hi Bryan,

    Ok, I Agree. If it will be documented like you said, I think that there's no problem...

Regards,
Andrpe Faria

Bryan Noll escreveu:
Andre...

Thanks for pointing this out.  Although, in this case, this is a limitation I'm satisfied with.  I personally don't think it is a good idea to use a primitive as an identifier value.  The perfect example of why to me is that primary key columns are almost always not nullable, and must be unique by definition.  It is evident then (assuming your using a non-primitive type for an Id) that an entity whose id value is null is transient.  This is not obvious if its value is zero?  Although unlikely, who's to say that 0 isn't the actual unique id value from the database.  I know the JPA/EJB3 specification allows primitives for Id's, but I would rather intentionally 'not support' them (and document that of course) in appfuse as I feel it is a best practice to avoid their use.

I'm cc'ing the dev list on this one.  Dev folks, I would appreciate feedback on this concept.  If you disagree with my view here, please speak up.

André Faria wrote:
Hi All,

There is a problem in DaoJpa if you are using a primitive number (int, double, float, long) @Id the  method save always will call merge because the objId value will return 0, not null...
That's the solution that I finded


    Object objId = DaoUtils.getPersistentId(o);

        if (objId == null
                || (objId instanceof Integer && objId.equals(0))
                || (objId instanceof Long && objId.equals(0L))
                || (objId instanceof Float && objId.equals(0F))
                || (objId instanceof Double && objId.equals(0D))
) {
            this.entityManager.persist(o);
        } else {
            this.entityManager.merge(o);
        }
  


Regards,
André Faria

--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to