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 accountinsert("insertAccount",account);}UserDao:createUser(User user){//get id and set to userinsert("insertUser",user);}Service:AccountService:createNewAccount(Account account){//transaction ignoredDaoManager.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 hereaccount.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 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>
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 USER (
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
PASSWORD VARCHAR(255)
);
CREATE TABLE ACCOUNT(
ID BIGINT NOT NULL,
NAME VARCHAR(255) ,
DEPOSIT DOUBLE,
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.
