accountDetails.setAccountsId(Long.parseLong(account.getId()));
System.out.println("accountDetails.accoundId-->"+accountDetails.getAccountsId());
Session session = sessionFactory.openSession();
Query query = session.createQuery("from QBAccounts qba where qba.accountsId=:accId");
List<AccountDetails> queryList = query.setParameter("accId", accountDetails.getAccountsId()).list();
session.close();
Session session2 = sessionFactory.openSession();
// session.saveOrUpdate(accountDetails);
try{
if(queryList.size()>0){
session2 = sessionFactory.openSession();
session2.beginTransaction();
session2.update(accountDetails);
} else{
session2.beginTransaction();
session2.save(accountDetails);
}
DTO:
@Entity(name="QBAccounts")
@Table(name="sias_account")
public class AccountDetails implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "accounts_id")
private Long accountsId;
@Column(name = "subaccount")
private String subAccount;
SQL查询:
create table sias_account (accounts_id number(20), subaccount varchar(100))
输出:
accountDetails.accoundId - &gt; 53
但是当我在我的oracle db表中看到它时,它会打印序列号,即总是递增,而不是从UI到表格打印完整的accounts_id。
现在表中的数据是:2305并且它不断递增。
答案 0 :(得分:1)
@Id
@Column(name = "accounts_id")
private Long accountsId;
如果从用户界面提供了ID,那么您根本不需要@GeneratedValue,因为没有要生成的ID。