File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes View mapping using Eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "View mapping using Eclipse" Watch "View mapping using Eclipse" New topic
Author

View mapping using Eclipse

Regis Ramillien
Greenhorn

Joined: Feb 19, 2010
Posts: 3
Hello,

I'm new to JPA.

I have a database with views.
I'd like to use JPA to easily access them.
Therefore, I assumed that JPA allowed me to have some sorts of "read-only" entities.

I used Eclipse to generate entities from my database, but on the entities generated for the views, I've got the following error:
Entity "NameOfTheEntity" has no Id or EmbeddedId
It seems normal because a view don't have primary keys.

So, my question is, how can I access my views using JPA ?

Best regards,
Tim McGuire
Ranch Hand

Joined: Apr 30, 2003
Posts: 820

Regis Ramillien wrote:Hello,
but on the entities generated for the views, I've got the following error:
Entity "NameOfTheEntity" has no Id or EmbeddedId
It seems normal because a view don't have primary keys.

So, my question is, how can I access my views using JPA ?


Section 2.4 of JPA 2.0 specifications:

All entities must have a primary key.

this includes views, if you choose to map them.

There was an earlier thread on javaranch:
http://www.coderanch.com/t/217228/Object-Relational-Mapping/java/JPA-DB-Views

summary:
either don't map the view OR treat it like an Entity and fix the view definition so it has a primary key.
Regis Ramillien
Greenhorn

Joined: Feb 19, 2010
Posts: 3
Ok, thanks very much for this response.

I'll implement primary keys.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: View mapping using Eclipse