Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Entity is not updated
Entity is not updated [message #1707046] Tue, 01 September 2015 19:39 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 225
Registered: July 2009
Senior Member
Hi all,
I've an abstract Document entity which has a "deleted" attribute:

@Entity()
@Table(name = "FKT_DOCUMENT")
@Inheritance(strategy = InheritanceType.JOINED)
@EntityListeners(value = { EntityListener.class })
public abstract class Document extends ModelObject implements IEntity,
Serializable {

@Basic()
@Column(name = "DELETED")
private Boolean deleted = Boolean.FALSE;

public Boolean getDeleted() {
return deleted;
}

public void setDeleted(Boolean newDeleted) {
firePropertyChange("deleted", this.deleted, newDeleted);
deleted = newDeleted;
}

// ... some additional getters and setters
}

Another class inherits from this entity:

@Entity()
@Table(name = "FKT_INVOICE")
@PrimaryKeyJoinColumns({ @PrimaryKeyJoinColumn(name =
"INVOICE_PARENT_ID") })
public class Invoice extends Document {
// ...some other getters and setters
}

Now, if I set the "deleted" attribute to another value and call save()
(or update()) with EntityManager, the entity is not updated (it seems
that the trigger for putting the object in the changeSet from
EclipseLink isn't called). There's no Exception or other error. The
update method is as follows:

EntityTransaction trx = getEntityManager().getTransaction();
trx.begin();
object = getEntityManager().merge(object);
getEntityManager().persist(object);
trx.commit();


This method works fine with other (non-abstract) entities. I don't have
any idea what's wrong with it.

Any hints are appreciated.

Ralf.
Re: Entity is not updated [message #1707353 is a reply to message #1707046] Thu, 03 September 2015 22:49 Go to previous messageGo to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 225
Registered: July 2009
Senior Member
Am 01.09.2015 um 21:39 schrieb Ralf Heydenreich:
> Hi all,
> I've an abstract Document entity which has a "deleted" attribute:

> [...]

> Now, if I set the "deleted" attribute to another value and call save()
> (or update()) with EntityManager, the entity is not updated (it seems
> that the trigger for putting the object in the changeSet from
> EclipseLink isn't called). There's no Exception or other error. The
> update method is as follows:
>
> EntityTransaction trx = getEntityManager().getTransaction();
> trx.begin();
> object = getEntityManager().merge(object);
> getEntityManager().persist(object);
> trx.commit();
>


Ok, found it by myself. The problem was that "object" was a detached
entity. Now, if you simply "merge" this entity into persistence context
then no changes are recognized. Thus, you have to read (or refresh) the
object _before_ doing any changes to it and then you can update it.
That's all :-)

Regards,
Ralf.
Re: Entity is not updated [message #1707416 is a reply to message #1707353] Fri, 04 September 2015 15:03 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1380
Registered: July 2009
Senior Member
If the object is detached, how was it initially read in? EclipseLink should handle the merge correctly, so if refresh is required in your situation, then it must be that your detached object is not as detached as you may think. The only way for this to occur that I can think of is if you read your object from the shared cache, as a read-only instances are not cloned and not meant to be used for changes. The read-only instance is used underneath merges to build the managed instance to merge into.

[Updated on: Fri, 04 September 2015 15:08]

Report message to a moderator

Previous Topic:Descriptor for class was not found in the project"
Next Topic:Hung threads
Goto Forum:
  


Current Time: Tue Mar 09 07:44:21 GMT 2021

Powered by FUDForum. Page generated in 0.01443 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top