| 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
|
 |
 |
|
|
subject: JPA and DB Views
|
|
|