PreUpdate called but child collection entity not storedPreUpdate not firing when adding to a collectionWhat is the best way to filter a Java Collection?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopHow do I call one constructor from another in Java?PreUpdate not firing when adding to a collectionIs null check needed before calling instanceof?hibernate exception: org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEViewCreate the perfect JPA entityJPA Key generation in the class of the many sideJPA/Hibernate: detached entity passed to persistJPA @PreUpdate not called on all entities

Should I mention being denied entry to UK due to a confusion in my Visa and Ticket bookings?

Pressure inside an infinite ocean?

How to write a 12-bar blues melody

Will 700 more planes a day fly because of the Heathrow expansion?

In Russian, how do you idiomatically express the idea of the figurative "overnight"?

How can internet speed be 10 times slower without a router than when using a router?

Can my company stop me from working overtime?

Do publishers care if submitted work has already been copyrighted?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

Why are prions in animal diets not destroyed by the digestive system?

How can I support myself financially as a 17 year old with a loan?

Identifying characters

I need a disease

How did the Venus Express detect lightning?

Where are the "shires" in the UK?

Manager is threatening to grade me poorly if I don't complete the project

Word meaning as function of the composition of its phonemes

How can I get a job without pushing my family's income into a higher tax bracket?

Why are UK Bank Holidays on Mondays?

Why does this derived table improve performance?

What are the differences between credential stuffing and password spraying?

ZSPL language, anyone heard of it?

Can a Tiefling have more than two horns?

Point of the Dothraki's attack in GoT S8E3?



PreUpdate called but child collection entity not stored


PreUpdate not firing when adding to a collectionWhat is the best way to filter a Java Collection?Iterating through a Collection, avoiding ConcurrentModificationException when removing objects in a loopHow do I call one constructor from another in Java?PreUpdate not firing when adding to a collectionIs null check needed before calling instanceof?hibernate exception: org.hibernate.AnnotationException: No identifier specified for entity: com..domain.idea.MAE_MFEViewCreate the perfect JPA entityJPA Key generation in the class of the many sideJPA/Hibernate: detached entity passed to persistJPA @PreUpdate not called on all entities






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a Spring project that uses lombok and a JPA annotated class defined this way:



@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity(name = "workflow_step")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name = "workflow_step_type")
@SuperBuilder
public abstract class BaseWorkflowStep extends BaseEntity {

@OneToMany(mappedBy = "step", cascade = CascadeType.PERSIST)
protected List<WorkflowEvent> events = Collections.synchronizedList(new ArrayList());

@PreUpdate
public void onPreUpdate()
if (completed == true)
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.STEP_COMPLETED).build());

if (workflow.isCompleted())
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.COMPLETED)
.build());




On my tests, the PreUpdate method is always called, but for some reason, when I debug it, it actually generates the inserts into the event table like this:



Hibernate: 
/* insert eu.hnpgroup.icare.model.WorkflowEvent
*/ insert
into
workflow_event
(created, by_id, event_type, step_id, text, workflow_id)
values
(?, ?, ?, ?, ?, ?)


But when I just run it, it doesn't and the table is kept clean.



In both cases, the output is printed, but only when debugging it actually works.



Already have checked PreUpdate not firing when adding to a collection and similar posts, but in my case, the method is actually called, only that it doesn't store anything.



One thing worth mentioning is that I have another entity with a similar collection only that it stores the value on a prePersist and it works as expected










share|improve this question
























  • Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

    – Harshana
    Mar 23 at 0:04











  • Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

    – Camilo Casadiego
    Mar 23 at 0:11











  • Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

    – crizzis
    Mar 24 at 10:17











  • @crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

    – Camilo Casadiego
    Mar 24 at 11:53

















0















I have a Spring project that uses lombok and a JPA annotated class defined this way:



@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity(name = "workflow_step")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name = "workflow_step_type")
@SuperBuilder
public abstract class BaseWorkflowStep extends BaseEntity {

@OneToMany(mappedBy = "step", cascade = CascadeType.PERSIST)
protected List<WorkflowEvent> events = Collections.synchronizedList(new ArrayList());

@PreUpdate
public void onPreUpdate()
if (completed == true)
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.STEP_COMPLETED).build());

if (workflow.isCompleted())
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.COMPLETED)
.build());




On my tests, the PreUpdate method is always called, but for some reason, when I debug it, it actually generates the inserts into the event table like this:



Hibernate: 
/* insert eu.hnpgroup.icare.model.WorkflowEvent
*/ insert
into
workflow_event
(created, by_id, event_type, step_id, text, workflow_id)
values
(?, ?, ?, ?, ?, ?)


But when I just run it, it doesn't and the table is kept clean.



In both cases, the output is printed, but only when debugging it actually works.



Already have checked PreUpdate not firing when adding to a collection and similar posts, but in my case, the method is actually called, only that it doesn't store anything.



One thing worth mentioning is that I have another entity with a similar collection only that it stores the value on a prePersist and it works as expected










share|improve this question
























  • Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

    – Harshana
    Mar 23 at 0:04











  • Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

    – Camilo Casadiego
    Mar 23 at 0:11











  • Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

    – crizzis
    Mar 24 at 10:17











  • @crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

    – Camilo Casadiego
    Mar 24 at 11:53













0












0








0








I have a Spring project that uses lombok and a JPA annotated class defined this way:



@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity(name = "workflow_step")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name = "workflow_step_type")
@SuperBuilder
public abstract class BaseWorkflowStep extends BaseEntity {

@OneToMany(mappedBy = "step", cascade = CascadeType.PERSIST)
protected List<WorkflowEvent> events = Collections.synchronizedList(new ArrayList());

@PreUpdate
public void onPreUpdate()
if (completed == true)
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.STEP_COMPLETED).build());

if (workflow.isCompleted())
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.COMPLETED)
.build());




On my tests, the PreUpdate method is always called, but for some reason, when I debug it, it actually generates the inserts into the event table like this:



Hibernate: 
/* insert eu.hnpgroup.icare.model.WorkflowEvent
*/ insert
into
workflow_event
(created, by_id, event_type, step_id, text, workflow_id)
values
(?, ?, ?, ?, ?, ?)


But when I just run it, it doesn't and the table is kept clean.



In both cases, the output is printed, but only when debugging it actually works.



Already have checked PreUpdate not firing when adding to a collection and similar posts, but in my case, the method is actually called, only that it doesn't store anything.



One thing worth mentioning is that I have another entity with a similar collection only that it stores the value on a prePersist and it works as expected










share|improve this question
















I have a Spring project that uses lombok and a JPA annotated class defined this way:



@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity(name = "workflow_step")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(name = "workflow_step_type")
@SuperBuilder
public abstract class BaseWorkflowStep extends BaseEntity {

@OneToMany(mappedBy = "step", cascade = CascadeType.PERSIST)
protected List<WorkflowEvent> events = Collections.synchronizedList(new ArrayList());

@PreUpdate
public void onPreUpdate()
if (completed == true)
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.STEP_COMPLETED).build());

if (workflow.isCompleted())
System.out.println("Event added!!!nnnnnn");
events.add(WorkflowEvent.builder().workflow(workflow).step(this).eventType(WorkflowEventType.COMPLETED)
.build());




On my tests, the PreUpdate method is always called, but for some reason, when I debug it, it actually generates the inserts into the event table like this:



Hibernate: 
/* insert eu.hnpgroup.icare.model.WorkflowEvent
*/ insert
into
workflow_event
(created, by_id, event_type, step_id, text, workflow_id)
values
(?, ?, ?, ?, ?, ?)


But when I just run it, it doesn't and the table is kept clean.



In both cases, the output is printed, but only when debugging it actually works.



Already have checked PreUpdate not firing when adding to a collection and similar posts, but in my case, the method is actually called, only that it doesn't store anything.



One thing worth mentioning is that I have another entity with a similar collection only that it stores the value on a prePersist and it works as expected







java hibernate jpa orm






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 0:13







Camilo Casadiego

















asked Mar 22 at 23:34









Camilo CasadiegoCamilo Casadiego

4002621




4002621












  • Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

    – Harshana
    Mar 23 at 0:04











  • Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

    – Camilo Casadiego
    Mar 23 at 0:11











  • Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

    – crizzis
    Mar 24 at 10:17











  • @crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

    – Camilo Casadiego
    Mar 24 at 11:53

















  • Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

    – Harshana
    Mar 23 at 0:04











  • Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

    – Camilo Casadiego
    Mar 23 at 0:11











  • Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

    – crizzis
    Mar 24 at 10:17











  • @crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

    – Camilo Casadiego
    Mar 24 at 11:53
















Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

– Harshana
Mar 23 at 0:04





Why is that the entity name is workflow_step? @Entity(name = "workflow_step")

– Harshana
Mar 23 at 0:04













Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

– Camilo Casadiego
Mar 23 at 0:11





Just convention, you think it has something to do? Because inserts works just fine, and I also have a prepersist on other entity that works just fine

– Camilo Casadiego
Mar 23 at 0:11













Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

– crizzis
Mar 24 at 10:17





Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity. Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. You have been warned

– crizzis
Mar 24 at 10:17













@crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

– Camilo Casadiego
Mar 24 at 11:53





@crizzis you are totally right, if you want you can add the answer, all I had to do was to add the code inside the listener to the serviceImpl and it started working :)

– Camilo Casadiego
Mar 24 at 11:53












1 Answer
1






active

oldest

votes


















1














Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity.



Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. Do not expect authoritative answers on why your specific case does not work either, since trying to add entities in a listener is already sort of a hack and not guaranteed to work.



You have been warned.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309086%2fpreupdate-called-but-child-collection-entity-not-stored%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity.



    Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. Do not expect authoritative answers on why your specific case does not work either, since trying to add entities in a listener is already sort of a hack and not guaranteed to work.



    You have been warned.






    share|improve this answer



























      1














      Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity.



      Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. Do not expect authoritative answers on why your specific case does not work either, since trying to add entities in a listener is already sort of a hack and not guaranteed to work.



      You have been warned.






      share|improve this answer

























        1












        1








        1







        Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity.



        Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. Do not expect authoritative answers on why your specific case does not work either, since trying to add entities in a listener is already sort of a hack and not guaranteed to work.



        You have been warned.






        share|improve this answer













        Note that, according to the JPA spec, you should only use entity listeners to modify the non-relationship state of an entity.



        Trying to do anything other than that results in undefined behavior. It may or may not work, and it may also break at any time. Do not expect authoritative answers on why your specific case does not work either, since trying to add entities in a listener is already sort of a hack and not guaranteed to work.



        You have been warned.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 11:55









        crizziscrizzis

        3,60211523




        3,60211523





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309086%2fpreupdate-called-but-child-collection-entity-not-stored%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현