Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

View mapping using Eclipse

 
Regis Ramillien
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, thanks very much for this response.

I'll implement primary keys.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic