Code That Made Me Cry, #CTMMC™

95% of all code makes me cry. The other 5% are white space.

SqlResultSetMapping for Pros (Java, #8 / 50)

// First, declare
@SqlResultSetMapping(
    name = "clientMapping",
    entities = {
        @EntityResult(
            entityClass = Client.class, 
            fields = {
                @FieldResult(name="id", column="id"),
                @FieldResult(name="uid", column="uid"),
                @FieldResult(name="name", column="name"),
                @FieldResult(name="addressId", column="address_id"),
                @FieldResult(name="companyId", column="company_id"),
                @FieldResult(name="contact", column="contact_id"),
            }
        )
    }
)

// ... and then try to apply the above to:
@Fetch(FetchMode.SUBSELECT)
private Collection aCustomerCollection;

@OneToMany(mappedBy = "destCustomerId")
@ManyToMany
@Fetch(FetchMode.SUBSELECT)
@JoinTable(
    name = "customer_dealer_map",
    joinColumns = {
        @JoinColumn(name = "customer_id", referencedColumnName = "id")
    },
    inverseJoinColumns = {
        @JoinColumn(name = "dealer_id", referencedColumnName = "id")
    }
)
private Collection dealers;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "customer_list_id", referencedColumnName = "id")
private CustomerList customerList;        

MichaelT is trying to combine the JPA @SqlResultSetMapping with other complex JPA annotations. Is anyone really enjoying writing all those annotations? Why do we Java developers keep pursuing these masochistic traits? I cannot imagine anything more complex to debug.

Source: http://stackoverflow.com/q/17491912/521799

comments powered by Disqus

Submit your own Code That Made You Cry

Send us your own example of code that made you cry! Please include:

Send the above to ctmmc@datageekery.com. All accepted submissions will be licensed as CC BY-SA 3.0. Submit only code of a compatible license.

Note that we may choose not to publish some submissions if we feel they're not appropriate. We hope you understand.

Don't let your SQL code make you cry!

Use jOOQ, instead of JDBC.

jOOQ generates Java code from your database and lets you build typesafe SQL queries through its fluent API.

Don't let your SQL code make you cry! Get back in control of your SQL with jOOQ.