Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the name of the self-referential many-to-many set using hibernate.reveng.xml?

I have a project using Hibernate on an Oracle database for which all entities are generated directly from Hibernate Tools under control of a hibernate.reveng.xml file.

I have one class which has a many-to-many relationship to itself using an intermediary table, like so:

PERSON:
  ID
  ...

PERSON_PERSON:
  PARENT_ID --> PERSON.ID
  CHILD_ID  --> PERSON.ID

Without any specific directives, Hibernate Tools will automatically generate a class that looks like this:

public class Person {
    private Long id;
    private Set<Person> personsForParentId = new HashSet<Person>(0);
    private Set<Person> personsForChildId = new HashSet<Person>(0);
}

Since that's not very helpful when coding to determine which is the parent set and which is the child set, I'd like to rename them as 'parents' and 'children'.

I've been editing the hibernate.reveng.xml to try to force it to rename that field, but I'm not able to find something that works. I'm not sure whether I'm specifying a change on the PERSON table, the PERSON_PERSON table, or both, and which attributes to change.

I'm used to setting these classes up manually, but on this project I don't have control over the build process, so I have to make do with what gets generated by Hibernate Tools, so I really just have to make Hibernate Tools to do what I want.

like image 922
Jon Avatar asked Nov 14 '22 06:11

Jon


1 Answers

on your hibernate.reveng.xml file try marking related columns like this;

<column name="personsForParentId" property="parents" />
like image 69
dursun Avatar answered Dec 10 '22 02:12

dursun