• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Alternative for union in Hibernate

 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All ,

I have 2 table of same contents but with no links between them and both table don't have PK .

I have to get records which are uion of both tables . How can I do this ?

Please help me on this issue .

Thanks .
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gireesh,

Hibernate is used for object-relational mapping. If your tables have no primary key, your data are not relational, and so not adapted to be used with Hibernate.

Regards,
Ramon
 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Ramon ,

Thank you for your reply . I am using rowid column as a primary key . This database is too old which i can't modify ....


Any idea about usage of union ?
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gireesh,

it depends. Would you please post exactly what you like to do? Table structure or pseudo code ...

Regards,
Ramon
 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Ramon ,

In SQL , the query will be :

select C1,C2 from table1
union
select C1,C2 from table2

How to do this in Hibernate ?
 
Ramon Anger
Ranch Hand
Posts: 56
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gireesh,

as you may have notized, there is no UNION construct in Hibernate.
Why not using a native sql query?

See http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/query_native.html

Regards,
Ramon
 
Gireesh Mulage
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Ramon . Will use native SQL query .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic