XPath examples – Hibernate java mapping

By , last updated November 1, 2014

Those who use hibernate for database access know that you need to provide an information that this object is a hibernate object. To do so you typically need to annotate your object with @Entity. It’s not a problem although if we speak about some large system. In large systems we have typically a number of instances of the same object that represent the same table in different contexts and packages. And here we need this: to give each object unique name.
Example:

@Entity(name="person.usa")
class Person {
   ...
}

This PMD rule shows how to check if a hibernate object have a name.

<![CDATA[
     //Annotation/NormalAnnotation[
     (
           Name/@Image='Entity'
           and
           not
           (
                 MemberValuePairs/MemberValuePair/@Image='name'
                 and
                 //PrimaryExpression/PrimaryPrefix[contains(Literal/@Image,'.')]
           )
     )
]]]>

Senior Software Engineer developing all kinds of stuff.

Comments

Be the first to comment.

Leave a Reply


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*