JPA: persisting object, parent is ok but child not updated
Posted
by James.Elsey
on Stack Overflow
See other posts from Stack Overflow
or by James.Elsey
Published on 2010-03-27T18:49:19Z
Indexed on
2010/03/27
18:53 UTC
Read the original article
Hit count: 222
Hello,
I have my domain object, Client
, I've got a form on my JSP that is pre-populated with its data, I can take in amended values, and persist the object.
Client
has an abstract entity called MarketResearch
, which is then extended by one of three more concrete sub-classes.
I have a form to pre-populate some MarketResearch
data, but when I make changes and try to persist the Client
, it doesn't get saved, can someone give me some pointers on where I've gone wrong?
My 3 domain classes are as follows (removed accessors etc)
public class Client extends NamedEntity
{
@OneToOne
@JoinColumn(name = "MARKET_RESEARCH_ID")
private MarketResearch marketResearch;
...
}
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class MarketResearch extends AbstractEntity
{
...
}
@Entity(name="MARKETRESEARCHLG")
public class MarketResearchLocalGovernment extends MarketResearch
{
@Column(name = "CURRENT_HR_SYSTEM")
private String currentHRSystem;
...
}
This is how I'm persisting
public void persistClient(Client client)
{
if (client.getId() != null)
{
getJpaTemplate().merge(client);
getJpaTemplate().flush();
} else
{
getJpaTemplate().persist(client);
}
}
To summarize, if I change something on the parent object, it persists, but if I change something on the child object it doesn't. Have I missed something blatantly obvious?
Thanks
© Stack Overflow or respective owner