/** * @author Deepak Kumar * * http://www.roseindia.net * Java Class to map to the datbase Contact Table */ public class Contact { private String firstName; private String lastName; private String email; private int id;
/** * @return First Name */ public String getFirstName() { return firstName; }
/** * @return Last name */ public String getLastName() { return lastName; }
/** * @param string Sets the Email */ public void setEmail(String string) { email = string; }
/** * @param string Sets the First Name */ public void setFirstName(String string) { firstName = string; }
/** * @param string sets the Last Name */ public void setLastName(String string) { lastName = string; }
/** * @return ID Returns ID */ public int getId() { return id; }
/** * @param l Sets the ID */ public void setId(int l) { id = l; }
}
table structure: id int 4 FIRSTNAME nvarchar(50) LASTNAME nvarchar(50) EMAIL nvarchar(50)
in eclipse, everything go right and the sql is shown correctly Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
in sql profiler, the statement is exec sp_executesql N'insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (@P1, @P2, @P3, @P4)', N'@P1 nvarchar(4000) ,@P2 nvarchar(4000) ,@P3 nvarchar(4000) ,@P4 int ', N'Deepak', N'Kumar', N'deepak_38@yahoo.com', 6
I try to run this statement in sql analyzer and it really can create a record. but if just run in eclipse, no exception, the sql is shown, but no record is added in the table!! what is the problem??
peter tong
Ranch Hand
Joined: Mar 15, 2008
Posts: 234
posted
0
I find the solution by myself finally. need to use transaction, seesion.flush is not enough!!