Configure orphanRemoval=true in Generate Entities of Table - JPA Tools - Eclipse

Asked

Viewed 139 times

0

I’m having trouble every time I need to use JPA Tools' Generate Entities of Table (use Eclipse Neon.3). I run entities with the Generate Entities of Table command from JPA Tools. In the code of a class in the annotation of a relationship I add the code orphanRemoval=true and save everything right. When I need to use the Generate Entities of Table command again, when I will look at the same class I entered the orphanRemoval=true no longer exists.

How do I set up Jpatools (on the Generate Custom Entities screens) to insert orphanRemoval=true in a relationship, so that it is stored and every time you need to use the command to generate table entities it automatically inserts orphanRemoval? Just like you select Cache on the Generate Custom Entities screen and it keeps it memorized.

See the case code snippet below:

When I Gero the entity with JPA Tools:

@OneToMany(mappedBy="pessoa", cascade={CascadeType.ALL})
    private Set<PessoaContato> listaPessoaContato;

I manually enter the orphanRemoval and saved code:

@OneToMany(mappedBy="pessoa", cascade={CascadeType.ALL},orphanRemoval=true)
    private Set<PessoaContato> listaPessoaContato;

When I need to regenerate, jpa tools overwrites all classes by deleting everything that is entered manually, so the code snippet gets rewritten:

@OneToMany(mappedBy="pessoa", cascade={CascadeType.ALL})
    private Set<PessoaContato> listaPessoaContato;
  • Hello, Fredebr. Welcome to [en.so]! Unfortunately I don’t know how to answer the question (because I haven’t used Eclipse for years). However, I want to warn those who voted to close that the question is perfectly clear: the questioner is using a code generation tool in the Eclipse editor and needs the generated code to have a certain feature. Whether or not it is possible to customize the tool I do not know, but it is a perfectly valid question.

1 answer

1

The only direct reference to such an option which I found is from many years ago and basically it was said that it was not supported and there were no plans for this.

The reason, I believe, is because the tool of generating entities based on tables is an initial help and does not intend to automate the evolution of classes by regenerating them in each bank change.

I did a search to see if there was a way to turn on such an option by default or overwrite the annotation externally, regardless of the field annotation, but found no results.

The best solution would be to use the tool only to generate only the classes referring to the new tables, without overwriting the existing ones.

An alternative would be to create a tool to process the generated classes and add information where convenient automatically.

  • Actually, JPA Tools unfortunately does not have this option and had already seen this reference you quoted. I found it interesting that in the screens of Generate Custom Entities it gives options of you to define the type of Scade, fetch and memorize this information because if you regenerate the entities in these screens will be shown the settings that you defined earlier. I opted for manual insertion even through the JPA Diagram Editor. Let’s see if in the future the project’s staff will implement. Thanks for the return.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.