This issue can't be edited

Because it belongs to an archived project. Jira admins can restore projects from the archive.

Embedded annotation should support a column prefix

Description

It's useful to allow a column prefix to be specified for @Embedded objects. Right now, if I need to set a prefix (to differentiate between same-type columns in an entity), I have to do this:

@Embedded
@AttributeOverrides( {
@AttributeOverride(name="zip", column = @Column(name="billingaddress_zip") ),
@AttributeOverride(name="state", column = @Column(name="billingaddress_state") )
} )
public Address getBillingAddress {
return this.billingAddress;
}

@Embedded
@AttributeOverrides( {
@AttributeOverride(name="zip", column = @Column(name="homeaddress_zip") ),
@AttributeOverride(name="state", column = @Column(name="homeaddress_state") )
} )
public Address getHomeAddress {
return this.homeAddress;
}

etc...

The main problem with this approach is that any column changes in the underlying Embedded component propagate to the objects that use them. With a prefix is far easier to separate the different embedded components, like this:

@Embedded(prefix="billingaddress")
public Address getBillingAddress {
return this.billingAddress;
}

@Embedded(prefix="homeaddress")
public Address getHomeAddress {
return this.homeAddress;
}

Environment

None

Activity

Show:

Michael Newcomb March 9, 2006 at 9:28 PM

I did not really see the resolution to this. But to get this behavior, do the following:

In the properties of the persistence unit in the persistence.xml file:

<properties>
<property name="hibernate.ejb.naming_strategy"
value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy"/>
</properties>

Thanks,
Michael

Leonardo Quijano November 23, 2005 at 4:42 AM

Hey you have a typo in the AssertionFailure winking face

public String foreignKeyColumnName(String propertyName, String propertyTableName, String referencedColumnName) {
String header = propertyName != null ? addUnderscores( propertyName ) : propertyTableName;
if (header == null) throw new AssertionFailure("NammingStrategy not properly filled");
return columnName( header + "_" + referencedColumnName );
}

Emmanuel Bernard November 15, 2005 at 2:07 AM

Done in org.hibernate.test.annotations.strategy.DefaultComponentSafeNamingStrategy

Leonardo Quijano October 7, 2005 at 1:51 AM

If we're implementing this with Naming Strategy, can at least we reopen this issue so we don't forget about it? I think in that issue it's not clear this prefix_need is going to be solved. Just in case any of you guys would forget about this.

Rejected

Details

Assignee

Reporter

Participants

Emmanuel Bernard
Leonardo Quijano
Michael Newcomb

Affects versions

Priority

Created September 27, 2005 at 5:24 PM
Updated March 9, 2006 at 9:28 PM
Resolved October 6, 2005 at 3:53 PM