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;
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
add a comment |
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
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
add a comment |
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
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
java hibernate jpa orm
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Mar 24 at 11:55
crizziscrizzis
3,60211523
3,60211523
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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