Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Jakub Liska
ServiceBuilder - many to many with mapping table as an associative entity
October 27, 2010 4:29 AM
Answer

Jakub Liska

Rank: Regular Member

Posts: 187

Join Date: March 25, 2010

Recent Posts

Hey,

have you noticed that mapping or linking table/entity of many2many rel. can be explicitly specified in service.xml with additional fields (not just two keys), but sql ddl script tables.sql gets generated with mapping table having only two mapping keys ?

In other words, you want rich mapping table with stuff like "orderDate", timestamps etc., but using servicebuilder you just can have only simple mapping / linking table. I don't get the point of it. If I define the mapping table explicitly with fields I want, all the code gets generated properly, I just need to add one2many relationships to mapping table from those 2 tables that are in many2many relationship so that code for getting the mapping table is generated and everything seems without a flaw.

The only flaw is DDL not creating the table according to my entity definition in service.xml.

If you look at the service.xml I attached, BID is rich mapping entity between translatorAccount and Order. Code is generated fine, but sql script contains :

1create table Translation_Bid (
2    translatorAccountId LONG not null,
3    orderId LONG not null,
4    primary key (translatorAccountId, orderId)
5);


What do you guys do when you need your linking table to have additional fields and want to use servicebuilder ?

Note: I found this thread later
Attachments: service.xml (3.3k)
Iván Rodríguez Bautista
RE: ServiceBuilder - many to many with mapping table as an associative enti
November 2, 2010 4:37 AM
Answer

Iván Rodríguez Bautista

Rank: Regular Member

Posts: 164

Join Date: January 25, 2010

Recent Posts

Hi Jakub,

I had to join lots of tables and access data throught Service Builder.
In that time, I did the next:

1- Create a view in your DB:
1
2CREATE VIEW example_view AS
3SELECT field1-1, field1-2, field2-1, field3-1...
4INNER JOIN table2 ON (...)
5INNER JOIN table3 ON (...)
6...
7FROM table1


2- Map this view in service.xml like it were a normal table
 1
 2<entity name="ExampleView" table="example_view" local-service="true" remote-service="false" cache-enabled="false">
 3    <column name="field1-1" type="long" primary="true" />
 4    <column name="field1-2" type="String" />
 5    <column name="field2-1" type="String" />
 6    <column name="field3-1" type="String" />
 7...
 8    <order .....>
 9    </order>
10    <finder ...>
11    </finder>
12</entity>


3- Build the classes throught "build-service" ant task
4- Refresh the project
5- Finally... lets fun!

May this helps you???

Greetings!!

(Sorry for my poor english...)