This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
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 Java 8 in Action this week in the Java 8 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.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: View mapping using Eclipse
 
Similar Threads
eclipse JPA - recreating JPA Entities re-writes classes - is there an alternative?
Auto code Generation tool for entity classes
Does the persistence layer know when the database has changed?
how to install database in eclipse indigo ?
JPA and DB Views