Reputation: 9943
I have a base class entity that looks like this:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "IDTYPE",
discriminatorType = DiscriminatorType.STRING,
length = 12)
public class ProtoObject implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
private String idtype;
// more columns
I have a number of sub-classes of this that I build and persist. However I have found that even though idtype column gets set to what I would expect in the data base (checking with a separate DB browser tool) the Java objects idtype property does not get set for those object that the EntityManager has in its cache.
If I do a find of objects through the EntityManager, the most recently persisted objects appear to have idtype blank! If I close the application and re-open it the data appears OK.
This is a JSF 2 application using EclipseLink 2.3.2.v20111125-r1046.
Is this a known problem and can anyone suggest a work-around?
Upvotes: 4
Views: 2816
Reputation: 4200
You can update cache after persisting:
this.entityManager.persist(protoObject);
this.entityManager.flush();
this.entityManager.refresh(protoObject);
Upvotes: 2
Reputation: 21145
You didn't set the attribute when you created the object to reflect what you wanted pushed to the database. You need to set the field to keep it consistent in the cache as JPA Entities are treated as regular java objects and won't fix things for you. Or after persist you can flush the changes them refresh the object to have the field populated with what is in the DB
Upvotes: 1