我有两个表,一个是名为 TRANSACTION 的主表,第二个是该表称为 TRANSACTION_RECORD 的事务记录。
交易
CREATE TABLE `e3_transaction` (
`transactionid` bigint(20),
`transactiontype` varchar(10),
`transactionstatus` varchar(10),
PRIMARY KEY (`transactionid`)
);
TRANSACTION_RECORD
CREATE TABLE `e3_as2805msg4` (
`transectionid` bigint(20),
`messageType` int(4),
`cardAcceptorName` varchar(40),
`adNational` varchar(1000),
`adPrivate` varchar(1000),
KEY `transectionidFK` (`transectionid`),
CONSTRAINT `transectionidFK` FOREIGN KEY (`transectionid`) REFERENCES `e3_transaction` (`transactionid`)
);
它将在交易和交易记录之间进行一对一的映射。这意味着一笔交易只能有一条记录。由于某些原因,我将这张表分开保存。所以我的课看起来像这样:
@Entity
@Table(name = "e3_transaction")
public class Transaction {
@Id
@GeneratedValue(generator = "assigned-by-code")
@GenericGenerator(name = "assigned-by-code", strategy = "assigned")
@Column(name = "transactionid", unique = true, nullable = false)
private Long transactionid;
@Column(name = "transactiontype", nullable = false, length = 10)
private String transactiontype;
@Column(name = "transactionstatus", nullable = false, length = 10)
private String transactionstatus;
@oneToOne
private TransactionRecord record;
}
我想同时保留两个对象。当我坚持一个 TRANSACTION 时,TRANSACTION_RECORD 应该坚持在它的表中。有没有办法做到这一点?如果需要,您可以更改表结构。我唯一需要的是两张桌子。