| How to save data in different tables with one entity [message #650537] |
Tue, 25 January 2011 08:07  |
imran raza khan Messages: 18 Registered: January 2011 |
Junior Member |
|
|
Hi,
I have multiple tables with same columns like
id,mobilenumber,message
Now on the base of different body of message i have to save data in different tables.
Now if i create entity for each table then only change is table name.
is there any possibility that i save data with one entity? or i have to create entities?
Regards,
imran
|
|
|
| Re: How to save data in different tables with one entity [message #651037 is a reply to message #650537] |
Thu, 27 January 2011 09:32   |
James Sutherland Messages: 1844 Registered: July 2009 |
Senior Member |
|
|
You want a single Entity to be inserted into multiple duplicate tables?
You could you a multiple table descriptor and map the other table as @SecondaryTable, but this will join the table on reads, and require you have duplicate attributes or use a transformation mapping.
How do you want the Entity read, from which table?
You could use a @MappedSuperclas or TABLE_PER_CLASS inheritance and have a different subclass map each table. If you want the persist of one Entity to auto persist the others, you could do this in a prePersist event.
You could also maintain the other tables using a database trigger, this may make the most sense.
James : Wiki : Book : Blog
|
|
|
| Re: How to save data in different tables with one entity [message #651164 is a reply to message #651037] |
Fri, 28 January 2011 01:08  |
imran raza khan Messages: 18 Registered: January 2011 |
Junior Member |
|
|
Hi James,
Thanks for your reply, couple of more points to mention
1- My application is only inserting data in different tables.
2- Database trigger will not help me please see below example
I receive SMS from subscribers and my records will be like that
id, shorcode, mobilenumber, message
1, 321, 123456, b
2, 321, 123456, fm
3, 321, 123456, del
4, 321, 123456, add
Now what my application will do is that it check
if message equal to b
insert into billinfo table
if message equal to fm
insert into freemin table
if message equal to del
insert into deletion table
I hope now my requirements are more clear.
Regards,
imran
|
|
|
Powered by
FUDForum. Page generated in 0.02615 seconds