mysql - how to apply one-many and many-one annotations(Java Persistence) -


i have 2 tables follows:

table1:

create table `product` (   `id` int(11) not null auto_increment,   `typename` varchar(255) default null,   `typecode` varchar(55) default null, ) engine=innodb auto_increment=396 default charset=latin1; 

table2:

create table measurements (     id int(11) not null auto_increment primary key,     age_group varchar(20) not null,     articletype not null,     dimension text ,     createdon int(11) not null,     updatedon int(11) not null,     createdby text not null, )engine=innodb auto_increment=396 default charset=latin1; 

now how can join 2 tables join column measurements.articletype = product.typename in java persistence.

i know concept of using 1 many , many 1 using foreign key(http://en.wikibooks.org/wiki/java_persistence/onetomany). above tables not have foreign key.

i'm here assuming want many-to-many. in java, if want bidirectional, use

@manytomany(mappedby = "products") public list<product> getproducts() { ... } 

and in product

@manytomany @jointable(name = "product_measurement") public list<measurement> getmeasurement() { ... } 

in sql :

create table product_measurement ( product_measurement_id int(11) not null, measurement_product_id int(11) not null, foreign key (measurement_product_id) references measurement (id), foreign key (product_measurement) references product (id) ); 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -