ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sheshadri Patel <meeturpa...@gmail.com>
Subject Re: Association/Inbed Object question
Date Sat, 26 Nov 2005 08:38:18 GMT
On 11/26/05, Alex Chew <chew.alex@gmail.com> 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.

Mime
View raw message