No,Patel
     that is not what i want.
     I dont like to get handleby user id manually , you know , handleby attribute of Account is type of User, not Long or Integer.
    i'd like to use my pojo in oo way ,not face to persistent field directly. 
    what i want to know is whether ibatis can work just like OGNL ,and this still is the key point, does #handleby.id# will be auto unwrapped in getHandleby().getId() way.
 
thanks anymore.
 
is cliniton there? show me the way please.

 
On 11/26/05, Sheshadri Patel <[EMAIL PROTECTED]> wrote:


On 11/26/05, Alex Chew <[EMAIL PROTECTED] > wrote:
If this enough?
 
POJO:
public class Account implements Serializable {
 private Long id;
 private String name;
 private Double deposit;
 private User handleby; Ur wrong here

}  

 public class User implements Serializable {
 private Long id;
 private String username;
 private String password;
}

 SQL:
 <insert id="insertAccount" parameterClass="account">
insert into ACCOUNT (ID,NAME, DEPOSITE, FK_HANDLEBY)
values (#id#, #name#, #deposit#, #handleby.id#)
</insert>
 
 <insert id="insertUser" parameterClass="user">
insert into USER(ID,NAME, PASSWORD)
values (#id#, #name#, #password#)
</insert>
 
DDL(MySQL):
CREATE TABLE USER (
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
PASSWORD VARCHAR(255)
);
 
CREATE TABLE ACCOUNT(
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
DEPOSIT DOUBLE,
FK_HANDLEBY BIGINT
);
 
DAO:
AccountDao:
createAccount(Account account)
{
  //get id and set to account
  insert("insertAccount",account);
}
 
UserDao:
createUser(User user)
{
  //get id and set to user
  insert("insertUser",user);
}
 
Service:
AccountService:
createNewAccount(Account account)
{
  //transaction ignored
  DaoManager.getAccountDao().createAccount(account);
}
 
Client Call sample (planned):
 
Account account = new Account();
account.setName("testAccount");
account.setDeposit(new Double(0.0));
User user = UserService.getUserByID(new Long(1));//get prepared user object------Ur wrong here
account.setHandleby(user);
AccountService.createNewAccount(account);
 
 
 
Hi Alex,

 
POJO:
public class Account implements Serializable {
 private Long id;
 private String name;
 private Double deposit;
 private int handleby; //modified

}  

 public class User implements Serializable {
 private Long id;
 private String username;
 private String password;
}

 SQL:
 <insert id="insertAccount" parameterClass="account">
insert into ACCOUNT (ID,NAME, DEPOSITE, FK_HANDLEBY)
values (#id#, #name#, #deposit#, #handleby#)
</insert>
 
 <insert id="insertUser" parameterClass="user">
insert into USER(ID,NAME, PASSWORD)
values (#id#, #name#, #password#)
</insert>
 
DDL(MySQL):
CREATE TABLE USER (
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
PASSWORD VARCHAR(255)
);
 
CREATE TABLE ACCOUNT(
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
DEPOSIT DOUBLE,
FK_HANDLEBY BIGINT
);
 
DAO:
AccountDao:
createAccount(Account account)
{
  //get id and set to account
  insert("insertAccount",account);
}
 
UserDao:
createUser(User user)
{
  //get id and set to user
  insert("insertUser",user);
}
 
Service:
AccountService:
createNewAccount(Account account)
{
  //transaction ignored
  DaoManager.getAccountDao().createAccount(account);
}
 
Client Call sample (planned):
 
Account account = new Account();
account.setName("testAccount");
account.setDeposit(new Double(0.0));
 
int handlebyid = UserService.getUserByID();
account.setHandleby(handlebyid );
AccountService.createNewAccount(account);
 
Now it'll works.
 
 
Tx,
 
Patel.
 
 



--
借鉴/思考/执行/检验/推广

Reply via email to