nikel
nikel

Reputation: 3564

Generate entities with cascade delete

I am generating entities for our large database via JBoss hibernate reverse engineering. I was hoping to see cascade annotations in entities, but did not see them on generation.

Is there a way to direct hibernate to consider foreign keys and generate entities with cascade annotations?

Upvotes: 1

Views: 742

Answers (1)

Guillaume Husta
Guillaume Husta

Reputation: 4385

Unfortunately, it hasn't been documented although this is possible. It should have been documented at 6.2.4.3. foreign-key.

Look at hibernate-reverse-engineering-3.0.dtd, there's a cascade attribute in elements :

  • foreign-key/many-to-one
  • foreign-key/one-to-one
  • foreign-key/inverse-one-to-one
  • foreign-key/set

The code is the truth ! Looking at it (hibernate-tools branch 5.2), we can see the possible values of cascade :

For Hibernate in org.hibernate.tool.hbm2x.pojo.EntityPOJOClass#getHibernateCascadeTypeAnnotation : https://github.com/hibernate/hibernate-tools/blob/5.2/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java#L497
Values are [ all-delete-orphan, delete-orphan, save-update, replicate, lock, evict ] (multiple accepted).
The enum type used is org.hibernate.annotations.CascadeType.

For JPA in org.hibernate.tool.hbm2x.pojo.EntityPOJOClass#getCascadeTypes : https://github.com/hibernate/hibernate-tools/blob/5.2/src/java/org/hibernate/tool/hbm2x/pojo/EntityPOJOClass.java#L421
Values are [ persist, merge, delete, refresh, all ] (multiple accepted).
The enum type used is javax.persistence.CascadeType.

Upvotes: 2

Related Questions