IntelliJ Java IDE
The moose likes Object Relational Mapping and the fly likes JPA and DB Views Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "JPA and DB Views" Watch "JPA and DB Views" New topic
Author

JPA and DB Views

Mohammad Jaber
Ranch Hand

Joined: Apr 10, 2006
Posts: 46
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


OCP , SCJP 5.0
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mohammad Jaber
Ranch Hand

Joined: Apr 10, 2006
Posts: 46
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

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Apr 10, 2006
Posts: 46
i already considered that option but i was thinking that JPA might provide us of something iam not aware of , Thank you very much
 
IntelliJ Java IDE
 
subject: JPA and DB Views
 
Threads others viewed
Exception Handling: where?
Lot of annotations for O/R mapping.
View mapping using Eclipse
URLs in a Portlet
Relationship between Model, View and Controller
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture