sql - JPA-how to Add record to master table and child table? -


i having 2 tables 1 master table called transaction , second record of transaction table called transaction_record.

transaction

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`) ); 

it have 1 one mapping between transaction , transaction record. means 1 transaction can have 1 record. have kept table separately reasons. class this:

@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; } 

i want persist both objects @ same time. when persist transaction, transaction_record should persist in it's table. there way ? can change table structure if want. thing need 2 tables.

works with

    @onetoone(cascade=cascadetype.all)     @mapsid     private transactionrecord record; 

transactionrecord must have @id of same type transaction no value generation.

tried hibernate jpa 2.0-provider.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -