Annotatiomania™, next level. JPA and JAXB combined

This is a very nice specimen of annotatiomania in the wild. When people not only confuse OO with relational, but also with XML. The “OOXMLational” model class, so to speak. Check this out:

@Entity
@Table(name = "Person", catalog = "TestDB", schema = "dbo")
@XmlRootElement
@NamedQueries({
    @NamedQuery(
        name = "Person.findAll", 
        query = "SELECT p FROM Person p"),
    @NamedQuery(
        name = "Person.findByPersonId", 
        query = "SELECT p FROM Person p WHERE p.personId = :pId"),
    @NamedQuery(
        name = "Person.findByPersonName", 
        query = "SELECT p FROM Person p WHERE p.personName = :pName"),
    @NamedQuery(
        name = "Person.findByPersonFamily", 
        query = "SELECT p FROM Person p WHERE p.personFamily = :pFamily"),
    @NamedQuery(
        name = "Person.findByPersonReference", 
        query = "SELECT p FROM Person p WHERE p.personReference = :pRef")})
public class Person implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "person_id", nullable = false)
    private Integer personId;

    @Size(max = 50)
    @Column(name = "person_name", length = 50)
    private String personName;

    @Size(max = 50)
    @Column(name = "person_family", length = 50)
    private String personFamily;

    @Column(name = "person_reference")
    private Integer personReference;

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "person1", 
              fetch = FetchType.LAZY)
    private Person person;

    @JoinColumn(name = "person_id", referencedColumnName = "person_id", 
                nullable = false, insertable = false, updatable = false)
    @OneToOne(optional = false, fetch = FetchType.LAZY)
    private Person person1;

After years of fun with “Where’s Waldo”, we have a new game: “Where’s the Java Code”? Seen in the wild here:

https://groups.google.com/forum/#!topic/querydsl/4lgLx3QQqBA.

7 thoughts on “Annotatiomania™, next level. JPA and JAXB combined

  1. I’m not sure it is possible to simultaneously confuse OO with both XML and relational as they are very different paradigms. Rather I would say an object model with both JAXB and JPA annotations supports the Java EE goal of enabling programmers to work in an object oriented way.

    1. The above example is both an @Entity, and an @XmlRootElement, so the OP of the aforementioned forum might indeed have some very interesting ideas about how to map things… :-)

      But you’re right. That’s what Java EE was designed for. Sometimes it works out nicely, I guess…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.