|
|
Inspections
Hibero adds over 60 code inspections and quick fixes. You'll find these inspections in
under the categories
Hibernate issues (Hibero) and EJB3 Persistence issues (Hibero).
A description of each inspection follows:
Hibernate issues (Hibero)
- Field Not Found
Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one,
one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array, primitive-array or
nested-composite-element tags, declared in a Hibernate mapping file, with access of type field,
but no field is found with such name in the corresponding class.
- Final Persistent Class
Reports any persistent final class, declared in a Hibernate mapping file, unless lazy fetching
is completely disabled or a proxy interface is explicitly specified.
- Getter Method Not Found
Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one,
one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array, primitive-array or
nested-composite-element tags, declared in a Hibernate mapping file, with access of type property,
but no getter method is found with such name in the corresponding class.
- Missing Identifier Type
Reports any identifier property, declared in a Hibernate mapping file, which doesn't explicitly
specifies the identifier type in the case that the name attribute is missing.
- Missing @CollectionOfElements Target Element
Reports any @CollectionOfElements annotation which does not specify
a target element and it cannot be inferred from the annotated field or property type
(i.e., Java generics are not used for collections).
- Persistent Class Name Differs From Mapping File Name
Reports any persistent class names which do not match the name of their containing
Hibernate mapping file. Although this isn't required by Hibernate, it is a convention
to give the file the same name as the persistent class, with the extension '.hbm.xml'.
- Persistent Class Without No-Arg Constructor
Reports any persistent class, declared in a Hibernate mapping file, which doesn't provide a default
no-argument constructor, unless a proxy interface is explicitly specified.
- Persistent Class With Private No-Arg Constructor
Reports any persistent class, declared in a Hibernate mapping file, which provides a default
no-argument constructor with private access, unless lazy fetching is completely disabled or
a proxy interface is explicitly specified.
- Proxy Must Be Interface Or Class Itself
Reports any proxy attribute, declared in a Hibernate mapping file, which isn't an interface
or the persistent class itself.
- Recomended Serializable Persistent Class
Reports any persistent class, declared in a Hibernate mapping file, that doesn't
implement java.io.Serializable interface. Although Hibernate doesn't require this,
serialization would be necessary when objects are stored in an HttpSession or passed by value using RMI.
- Required Comparator Implementor
Reports any sort attribute, declared in a Hibernate mapping file, which references a class
that doesn't implement java.util.Comparator interface.
- Required EntityPersister Implementor
Reports any persister attribute, declared in a Hibernate mapping file, which references a class
that doesn't implement org.hibernate.persister.entity.EntityPersister interface.
- Required IdentifierGenerator Implementor
Reports any generator attribute, declared in a Hibernate mapping file, which references a class
that doesn't implement org.hibernate.id.IdentifierGenerator interface.
- Required Overriden Equals HashCode
Reports any persistent class, composite-id class, composiste-element class, or composite-map-key,
declared in a Hibernate mapping file, that doesn't override equals()
and hashCode().
- Required PropertyAccessor Implementor
Reports any access attribute, declared in a Hibernate mapping file, which references a class
that doesn't implement org.hibernate.property.PropertyAccessor interface.
- Required Proxy Interface Implementor
Reports any persistent class, declared in a Hibernate mapping file, which references a class
that doesn't implement the interface specified by the proxy attribute (if any).
- Required Serializable Implementor
Reports any class referenced by a composite identifier, declared in a Hibernate mapping file,
that doesn't implement java.io.Serializable interface.
- Required UserCollectionType Implementor
Reports any collection-type attribute, declared in a Hibernate mapping file, which references a class
that doesn't implement org.hibernate.usertype.UserCollectionType interface.
- Setter Method Not Found
Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one,
one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array,
primitive-array or nested-composite-element tags, declared in a Hibernate mapping file, with access of
type property, but no setter method is found with such name in the corresponding class.
- Type Mismatch
Reports any type attribute of id, version, property or key-property, declared in a Hibernate mapping file,
that doesn't match the type declared in its associated field, getter or setter.
- Wrong Collection of Elements Type
Reports any field or property annotated with the @CollectionOfElements
annotation and whose type is not any of the following: array of Java primitive types;
collections or maps of core types (primitive wrapper types, java.lang.String,
java.math.BigInteger, java.math.BigDecimal,
java.util.Date, java.util.Calendar,
java.sql.Date, java.sql.Time, java.sql.Timestamp);
collections or maps of embeddable classes.
- Wrong Discriminator Type
Reports any discriminator type or meta-type attribute, declared in a Hibernate mapping file,
that is not any of the following: string, character,
integer, byte, short,
boolean, yes_no, true_false
or a custom UserType.
- Wrong Version Type
Reports 1) any version type attribute, declared in a Hibernate mapping file, that is not any of the following:
long, integer, short,
timestamp, calendar or a custom
UserVersionType; or 2) any @Version field or property
whose type is not any of the following: int, java.lang.Integer,
short, java.lang.Short, long,
java.lang.Long, java.sql.Timestamp or a custom
UserVersionType.
EJB3 Persistence issues (Hibero)
- Ambiguous Primary Key Definition
Reports any primary key of an entity class being defined as simple and composite
at the same time. A primary key must either be defined as simple or composite but not both.
- Composite Primary Key Field Or Property Type Mismatch
Reports any composite primary key field or property of an entity class,
defined with the @IdClass annotation, whose type
does not match to its corresponding field or property of the composite primary key class.
- Duplicate Primary Key
Reports any simple and/or composite primary key defined multiple times in an entity class.
A simple primary key must correspond to a single persistent field or property.
The @Id annotation is used to denote a simple primary key.
A composite primary key, when defined with the annotation @EmbeddedId,
must correspond to a single persistent field or property. There must be only one
@EmbeddedId annotation and no @Id annotation
when the @EmbeddedId annotation is used.
- Embeddable Class Must Be A Top-Level Class
Reports any embeddable class which isn't a top-level class.
- Embeddable Class Must Be Serializable
Reports any embeddable class which doesn't implement the java.io.Serializable
interface. This is a hard requirement only if the embeddable class is to be passed by value as a detached
object (e.g., through a remote interface).
- Embeddable Class Must Have A No-Arg Constructor
Reports any embeddable class which doesn't provide a default no-argument constructor.
- Embeddable Class Must Not Be Final
Reports any embeddable class declared final.
- Embeddable No-Arg Constructor Must Be Public Or Protected
Reports any no-arg constructor of an embeddable class not being declared
public or protected.
- EmbeddedId Composite Primary Key Class Must Be Embeddable
Reports any composite primary key defined with the EmbeddedId annotation
and mapped to a class not declared as embeddable.
- Entity Class Must Be A Top-Level Class
Reports any entity class which isn't a top-level class.
- Entity Class Must Be Serializable
Reports any entity class which doesn't implement the java.io.Serializable
interface. This is a hard requirement only if the entity class is to be passed by value as a detached
object (e.g., through a remote interface).
- Entity Class Must Have A No-Arg Constructor
Reports any entity class which doesn't provide a default no-argument constructor.
- Entity Class Must Not Be Final
Reports any entity class declared final.
- Entity No-Arg Constructor Must Be Public Or Protected
Reports any no-arg constructor of an entity class not being declared
public or protected.
- GeneratedValue May Be Defined In Primary Key Only
Reports any GeneratedValue annotation defined in a non-primary key.
The @GeneratedValue annotation may be applied to a primary key
property or field of an entity or mapped superclass in conjuntion with the
@Id annotation.
- Mapping Annotations Applied To Both Persistent Fields And Properties
Reports any entity class having mapping annotations applied to both persistent fields
and properties.
- Mapping Annotations Not Applicable To Setter Accessors
Reports any setter property accessors of an entity class having
object/relational mapping annotations. When property-based access is used,
the object/relational mapping annotations for the entity class annotate the
getter property accessors.
- Mapping Annotations Not Applicable To Transient Fields Or Properties
Reports any fields or properties of an entity class declared
transient or annotated @Transient
having object/relational mapping annotations. Mapping annotations cannot be applied to
fields or properties that are transient or
@Transient.
- Missing Composite Primary Key Class Persistent Fields Or Properties
Reports any entity class, having a composite primary key defined with the
@IdClass annotation, which does not map all the persistent
fields or properties of the composite primary key class.
All the persistent fields or properties (depending on the access type) of the composite
primary key class must be mapped to multiple fields or properties of the entity class.
- Missing Primary Key
Reports any root entity class not having defined a primary key. The primary key
must be defined on the entity that is the root of the entity hierarchy or on
a mapped superclass of the entity hierarchy.
- Missing Relationship Target Entity
Reports any many relationship modeling annotation (namely @OneToMany
and @ManyToMany) which does not specify a target entity and
it cannot be inferred from the annotated field or property type (i.e., Java generics are
not used for collections).
- Multiple Version Fields Or Properties
Reports multiple declarations of a @Version field or property
in an entity class. Only a single @Version field or property
should be used per class; applications that use more than one @Version
field or property will not be portable.
- Persistent Field Must Not Be Final
Reports any persistent field of an entity or embeddable class declared final.
- Persistent Field Must Not Be Public
Reports any persistent field of an entity or embeddable class declared public.
- Persistent Method Must Not Be Final
Reports any persistent method of an entity or embeddable class declared final.
- Primary Key Class Must Be Public
Reports any primary key class (for composite primary keys) not being declared public.
- Primary Key Class Must Be Serializable
Reports any primary key class (for composite primary keys) not being serializable
(i.e., implements java.io.Serializable).
- Primary Key Class Must Define equals() and hashCode()
Reports any primary key class (for composite primary keys) which does not override
equals() and hashCode().
The semantics of value equality for these methods must be consistent with the database
equality for the database types to which the key is mapped.
- Primary Key Class Must Have A No-Arg Constructor
Reports any primary key class (for composite primary keys) which doesn't provide a
default no-argument constructor.
- Primary Key Class No-Arg Constructor Must Be Public
Reports any no-arg constructor of a primary key class (for composite primary keys)
not being declared public.
- Primary Key Class Properties Must Be Public Or Protected
Reports any primary key class (for composite primary keys) properties not being
declared public or protected, when
property-based access is used.
- Primary Key Must Be Defined Exactly Once In The Entity Hierarchy
Reports any primary key not declared in a root entity or mapped superclass.
The primary key must be defined exactly once in an entity hierarchy (on the entity that is
the root of the entity hierarchy or on a mapped superclass of the entity hierarchy).
- Property Accessor Must Be Public Or Protected
Reports any property accessor of an entity class not being declared
public or protected.
- Redundant Relationship Target Entity
Reports any relationship modeling annotation which does specify a target entity and
it can be inferred from the annotated field or property type.
- Unknown Composite Primary Key Field Or Property
Reports any composite primary key field or property of an entity class,
defined with the @IdClass annotation, whose name
does not correspond to any field or property of the composite primary key class.
- Unresolved Symbol
Reports any EJB3 Persistence and Hibernate annotation member value (i.e., attribute value)
referencing a symbol which cannot be resolved (e.g., reference to an unknown package, class,
field, property, etc.).
- Wrong Composite Primary Key Definition
Reports any primary key field or property defined as composite with
@EmbeddedId in an entity class annotated with
@IdClass. A composite primary key must correspond to
either a single persistent field or property annotated with @EmbeddedId
or to a set of such fields or properties annotated with @Id used in conjuntion
with the @IdClass annotation.
- Wrong Composite Primary Key Type
Reports any field or property of an entity class, defined as a composite primary key (using
the @EmbeddedId annotation), whose type or returned type is not
a class. A primary key class must be defined to represent a composite primary key.
- Wrong Lob Type
Reports any @Lob field or property whose type is not any of the following:
byte[]; java.lang.Byte[]; char[];
java.lang.Character[]; java.lang.String;
java.sql.Blob; java.sql.Clob;
java.io.Serializable.
- Wrong Persistent Field Or Property Type
Reports any persistent field or property whose type is not any of the following: any Java
primitive type; any primitive wrapper type; java.lang.String;
java.math.BigInteger; java.math.BigDecimal;
java.util.Date; java.util.Calendar;
java.sql.Date; java.sql.Time;
java.sql.Timestamp; any user-defined serializable type;
byte[]; Byte[]; char[];
Character[]; enums; entity types and/or collections of entity types;
embeddable classes.
- Wrong Primary Key Type
Reports any primary key field or property whose type is not any of the following: any Java
primitive type; any primitive wrapper type; java.lang.String;
java.util.Date; java.sql.Date.
- Wrong Version Type
Reports any @Version field or property whose type is not any of the following:
int; java.lang.Integer; short;
java.lang.Short; long;
java.lang.Long; java.sql.Timestamp.
|