JPA/Hibernate preUpdate doesn't update parent object

前端 未结 2 1128
执念已碎
执念已碎 2021-01-06 04:41

In my application I defined following classes:

@Entity
@Table(name = \"forums\")
public class Forum {
    @Id
    @GeneratedValue(generator = \"system-uuid\"         


        
相关标签:
2条回答
  • 2021-01-06 04:54

    post.merge() has no use here. post is clearly attached to the session already.

    Make sure you've got the content attribute mapped to a column, if it is not, Hibernate has no way of telling if the entity is dirty, and therefore flush the changes to the DB.

    0 讨论(0)
  • 2021-01-06 04:59

    It is not bug, even that with a fast try this worked for me way you expected. Negative news is that it is not guaranteed to work, because of:

    From page 93 in JPA 2.0 specification:

    In general, the lifecycle method of a portable application should not invoke EntityManager or Query operations, access other entity instances, or modify relationships within the same persistence context.[43] A lifecycle callback method may modify the non-relationship state of the entity on which it is invoked.

    And page 95:

    It is implementation-dependent as to whether callback methods are invoked before or after the cascading of the lifecycle events to related entities. Applications should not depend on this ordering.

    0 讨论(0)
提交回复
热议问题