• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JPA and DB Views

 
Mohammad Jaber
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,
How can i treat the Database views on JPA , should i represent them as "Entities" and if so how should i handle the "@Id" since View Does not have one , is there any JPA specific handlation of this , Thanks
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPA is typically there for CRUD operations. Views (unless they are updatable) are usually only read operations. They are also specific queries for existing entities, rather than seperate entities themselves. I wouldn't map them at all.
 
Mohammad Jaber
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are right , it does not make sense as a "Entity" but if you don't want to go "Native" you should perform your queries on "Entity" Type , how can i perform that if i didn't define my Views as entities ???

Regards,
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you must involve them in your domain model you can just map them as distinct entities. If your view doesn't have a primary key then add a surrogate key to your view definition.
 
Mohammad Jaber
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i already considered that option but i was thinking that JPA might provide us of something iam not aware of , Thank you very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic