What I have:
a web form with an editable grid that contains that is bound to non-updatable view data (i.e., readonly) and updatable data from one other table. My entity bean is as follows:
Code:
@Entity
@IdClass(TblloanviewPK.class)
@Name("loanview")
public class Tblloanview implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
.
.
@OneToOne(cascade=CascadeType.ALL)
@PrimaryKeyJoinColumns(
{
@PrimaryKeyJoinColumn(name = "CASENUMBER", referencedColumnName = "CASENUMBER"),
@PrimaryKeyJoinColumn(name = "LOANNUMBER", referencedColumnName = "LOANNUMBER")
})
public Tblloannumbers lnnum;
@Id
@Column(insertable=false, updatable=false)
public Long casenumber;
@Id
@Column(insertable=false, updatable=false)
public String loannumber;
@Column(name = "LOAN_NUMBER13", insertable=false, updatable=false)
public String loanNumber13;
.
.
Code:
@Entity
@IdClass(TblloanviewPK.class)
public class Tblloannumbers implements Serializable {
@Id
public Long casenumber;
@Id
public String loannumber;
public String fhacasenum;
public Date firstpmtdate;
public String dealid;
.
.
Notice that I have set all view fields to be isnertable = false, updatable = false.
I may or may not have a row in the OneToOne association - optional = true by default (I think). Here are my questions:
1) I want to persist a row to the associated table (Tblloannumbers) if data was entered into the updatable fields in the table. But how does this work? If no fields are edited, then I do not want a row created in tblloannumbers. If a field was edited, then I do want a row persisted into the associated table. Do I have the right mapping for this? Is there code I have to write or will hibernate determine if a row changed in the grid and persist a new row to the table?
The behavior I am seeing is the following
.I persist tblloanview
.there is no assocated record in tblloannumbers
.I entered data into the grid I want persisted to tblloannumbers
.I get a null pointer exception because there is no associated record
Is there someway to do this in hibernate so that I do not have to add logic that says "If you have a field that has changed, check if the row exists, if yes, update, else instantiate an entity and isnert it. if fields do not have changes, ignore"[/code]