如何将creationUserID从用户实体设置为帐户实体



在我的应用程序中,当用户创建帐户时,它会传递用户详细信息。ACCOUNT表中的creationUserID是User表的userId。下面是JSON请求结构。

{
"accountNo":1001,
"balance":4000,    
"ownerOfTheAccount" : {
"userID": 4,
"fName" : "Dan",
"lName":"Brown",
"email" :"dan@brown"
}
}

我想将creationUserID设置为accounts实体。创建用户ID需要取自用户实体。在我的示例中,如何将userID=4设置为ACCOUNT实体中的creationUserID字段?我是JPA的新手。

create table ACCOUNT (
account_number int (10) not null primary key,
balance float (20) not null,
user_id  varchar_ignorecase (25) not null,
creation_date AS CURRENT_TIMESTAMP(),

constraint fk_account_customer foreign key(user_id) references USERS(user_id)
);

用户实体和帐户实体具有OneToOne映射。

我不得不手动设置它。我不确定是否有一种方法可以在实体bean本身中设置它。但我在服务层手动设置了它。

最新更新