I want to change the name of the foreign key column generated by my Schema. Below is the schema configuration that I am using :
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
When I run the this configuration , I got 2 tables : 1. ActivityDim 2. ActivityFact ( ActivityDim Id as a foreign key with name activityDim_ActivityFact_Id)
I want to change the above generated name to the schema element name which is actvitiyDim in this case. I am not sure how to use the custom naming Strategy. I have tried to override foreignKeyColumnName method , but didn't work
public class ForeignKeyNamingStrategy extends ImprovedNamingStrategy {
private final static Logger logger = LoggerFactory.getLogger(ForeignKeyNamingStrategy.class);
@Override
public String foreignKeyColumnName(
String propertyName, String propertyEntityName, String propertyTableName, String referencedColumnName
) {
return propertyName;
}
I have also given this class reference in my persistence.xml
<persistence version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd
http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:orm="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<persistence-unit name="reportingData">
<!-- These properties are defined in persistence-model/src/main/resources/persistence.xml.
HyperJAXB3 merges them into its generated and final persistence.xml -->
<properties>
<property name="hibernate.ejb.naming_strategy"
value="com.namingStrategy.ForeignKeyNamingStrategy" /></properties>
</persistence-unit>
</persistence>
I am new to Hibernate , my understanding could be a bit disconnected. Can someone please suggest ?