Jpa 重命名使用自定义命名策略生成的外键列
我想更改架构生成的外键列的名称。下面是我正在使用的架构配置:Jpa 重命名使用自定义命名策略生成的外键列,jpa,hibernate-mapping,hyperjaxb,Jpa,Hibernate Mapping,Hyperjaxb,我想更改架构生成的外键列的名称。下面是我正在使用的架构配置: <xs:complexType name="ActivityFact"> <xs:sequence> <!-- Other Element Declaration --> </xs:sequence> <xs:attribute name="id" type="xs:long" /&g
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
我还在persistence.xml中给出了此类引用
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
<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>
我刚开始冬眠,我的理解可能有点脱节。有人能提出建议吗?免责声明:我是Hyperjaxb的作者
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
这是一个初步答案,我们以后可能需要对其进行改进
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
首先,请显示包含ActivityDim和ActivityFact的完整模式片段以及生成的内容。你在这里有多对一、多对多或一对多的关系吗
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
下一步,检查。据我所知,您可能需要自定义外键列的名称。这在OOTB中应该是可能的,而无需实施定制的namin策略。假设你在这里有一对多的关系,这将是某个地方。这是用于自定义的。我认为您需要在此处自定义联接列的名称,因此我的猜测如下:
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
<hj:one-to-many>
<orm:join-column name="actvitiyDim"/>
</hj:one-to-many>
:
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
可能和你的情况很接近
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
现在,命名策略
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
命名策略与Hibernate或JPA无关。命名策略是一个内部组件,Hyperjaxb3在模式编译期间使用它来生成表、列等的名称,因此它实际上是非常低级的
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>
如果出于某种原因需要不同的命名,可以编写和配置自己的命名策略实现。例如,见。但它不再是定制,而是扩展了Hyperjaxb。您基本上可以重写Hyperjaxb的一部分。例如,如果希望更改默认情况下所有FK名称的生成方式,则可以执行此操作。我不确定这是您想要的。您想更改所有外键的命名策略,还是只更改此外键的命名策略?非常感谢,我可以自定义外键列名。我是否也可能只在一个地方写一条规则,使外键名与模式元素名相似。所有外键生成都是如此?@priyas如果您想定制FK名称生成,那么它实际上是一种自定义命名策略。您可能需要覆盖。
<xs:complexType name="ActivityFact">
<xs:sequence>
<!-- Other Element Declaration -->
</xs:sequence>
<xs:attribute name="id" type="xs:long" />
</xs:complexType>