ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Chew <chew.a...@gmail.com>
Subject Re: Association/Inbed Object question
Date Sat, 26 Nov 2005 07:46:28 GMT
If this enough?

POJO:
public class Account implements Serializable {
 private Long id;
 private String name;
 private Double deposit;
 private User handleby;
}

 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
account.setHandleby(user);
AccountService.createNewAccount(account);

Mime
View raw message