Skip to content

Commit

Permalink
Merge pull request #75 from OsgiliathEnterprise/embeddedid
Browse files Browse the repository at this point in the history
Add mapsid on composite keys
  • Loading branch information
Tcharl authored Aug 5, 2024
2 parents 2b71806 + 30b2797 commit e0c92b0
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,49 @@
</fileset>
</replaceregexp>
</target>


<!-- I hope noone will have a composite key containing 5 foreign keys -->
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
</project>
20 changes: 2 additions & 18 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,8 @@ yet.
To fix that bad behavior, you have to add a `@MapsId("name of the field in the composite key")"` on your Entity
relationship.

Example:

```
@AttributeOverrides({
@AttributeOverride(name = "nodeId", column = @Column(name = "NODE_ID", precision = 19, scale = 0)),
@AttributeOverride(name = "origin", column = @Column(name = "ORIGIN", length = 64))})
public StatsRemoteId getId() {
return this.id;
}
@JsonIgnore
@ManyToOne(fetch = FetchType.LAZY)
@MapsId("nodeId")
@JoinColumn(name = "NODE_ID")
public Nodes getNodes() {
return this.nodes;
}
```
The build.xml containing the hack only contains 5 entries rewritten, If you need more you'll have to add
new `<replaceregexp` entries.

## Mimicking the behavior of XX2PG

Expand Down
2 changes: 1 addition & 1 deletion report-aggregate/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.osgiliath.datamigrator</groupId>
<artifactId>data-migrator</artifactId>
<version>1.66-SNAPSHOT</version>
<version>1.67-SNAPSHOT</version>
</parent>

<artifactId>report-aggregate</artifactId>
Expand Down
46 changes: 46 additions & 0 deletions sample-mono/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,51 @@
<include name="**/*.java"/>
</fileset>
</replaceregexp>


<!-- I hope noone will have a composite key containing 5 foreign keys -->
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>
<replaceregexp flags="gm">
<regexp pattern="(@AttributeOverride\(name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;, .*name\s*=\s*&quot;((?:(?!&quot;).)+)&quot;(?:(?!^\s+@JoinColumn)[^£])*)(^\s*\@JoinColumn\(name\s*=\s*&quot;\3)"/>
<substitution expression="\[email protected](&quot;\2&quot;) \4"/>
<fileset dir="${maven.project.build.directory}">
<include name="**/*.java"/>
</fileset>
</replaceregexp>

</target>
</project>
4 changes: 2 additions & 2 deletions sample-mono/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>net.osgiliath.datamigrator</groupId>
<artifactId>data-migrator</artifactId>
<version>1.66-SNAPSHOT</version>
<version>1.67-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>net.osgiliath.datamigrator.sample</groupId>
Expand Down Expand Up @@ -154,7 +154,7 @@
</goals>
<configuration>
<files>
<file>${basedir}/database.properties</file>
<file>${project.basedir}/database.properties</file>
</files>
</configuration>
</execution>
Expand Down

0 comments on commit e0c92b0

Please sign in to comment.