-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: newbie - need advice on best approach
PostPosted: Tue Dec 18, 2007 1:33 pm 
Newbie

Joined: Tue Dec 18, 2007 1:04 pm
Posts: 1
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]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.