• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

View mapping using Eclipse

 
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,
 
Ranch Hand
Posts: 820
IntelliJ IDE VI Editor Tomcat Server
  • 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.

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!