[hibernate-dev] Issue a warning if field and getter annotation styles are mixed?

Hardy Ferentschik hardy at hibernate.org
Tue Jan 12 06:49:06 EST 2016


Hi,

> Would it be feasible to raise a warning or error in cases where
> mapping annotations are given on an element not matching the default
> access type for that entity and @Access has not been given explicitly
> either?

Sure, but I think it would need some doing. AFAIR the code determines the access type
and from then on just reflects on either fields or methods. Maybe as a performance 
optimisation as well. Not sure. I agree having some warning for the case you describe 
is a good idea, but don't expect this to be a one lines in the code.

That said, things would be easier with Jandex. There it would be easier to determine 
inconsistent configuration. I seem to vaguely recall that I might even have done though
when working in the metamodel branch. 

Personally I'd probably address this in conjunction with a re-write of the mapping code
and switch to Jandex. I think that is still somewhere on the horizon.

If not, it is for sure feasible, just take quite some effort.

> The most common case of this issue which I saw several times happen is
> where @Id is given at the field level but some other mapping
> annotations are given on property getters

Right, that's a usual mistake.

> for those not super-deep into the details of access type retrieval.

I don't think you need to be super-deep into ORM/JPA to understand that.
There are warnings and notes about this everywhere.

> A warning might help them.

For sure, but as said, I'd tackle this as part of a bigger refactoring. 

--Hardy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 496 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/hibernate-dev/attachments/20160112/163c1eb5/attachment.bin 


More information about the hibernate-dev mailing list