Search code examples
javahibernatestrutshibernate-mapping

Hibernate Annotations, Create 3rd entity from existing two entities without annotating the already annotated table


I have two tables named USER and ROLE with entities as USER and ROLE resply. Now I want to create one more entity by using these above entity so that I can fetch datas of both tables.

One more table is there named USER_ROLE which contain two fields "user_id" and "role_id".

I have to accomplish these thing using hibernate annotations.

I tried by creating third entity with annotated table as USER table and properties are some USER table fields and Collection set of ROLE table. But here's the mistake is I annotated the third entity with USER table which is already annotated with User entity.

So now I have to make that third entity without annotating any table, has to access the two entities which are already accessing the table .

how can i accomplish these using hibernate annotations.

kindly help me on this issue

thanks, rajNaveen


Solution

  • As far as I understand what are you looking for can be found in this tutorial. Just see how @JoinTable is used.

    Hope that helps !!!