users@jpa-spec.java.net

[jpa-spec users] Feature request - support adding a prefix to the mapping of all properties of an embedded object

From: <anthonygerrard+java.net_at_gmail.com>
Date: Wed, 10 Oct 2012 08:32:47 +0000 (GMT)

Hi,

When using embeddable objects I have often found myself having to
override the default mapping to make the column names understandable or
to avoid collisions by adding a prefix to every column name for the
embedded object.

One example if for a debit card:

@Embeddable
class DateOnCard {
    private int month;
    private int year;
}

class PaymentCard {
    @AttributeOverrides({
        @AttributeOverride(name="month", column = @Column(name =
"startmon")),
        @AttributeOverride(name="year", column = @Column(name =
"startyear"))
    })
    private DateOnCard startDate;
    @AttributeOverrides({
        @AttributeOverride(name="month", column = @Column(name =
"expmon")),
        @AttributeOverride(name="year", column = @Column(name =
"expyear")),
    })
    private DateOnCard expiryDate;
}

I propose that support is added for specifying a prefix for column
names of embedded objects or to instruct it use the property name as
the prefix. I'm not sure what the best way to achieve this would be.
You could add an attribute to the Emdedded or AttributeOverrides
annotation or possibly look at Hibernate's NamingStrategy
functionality.