Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

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:
https://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.

 
A sonic boom would certainly ruin a giant souffle. But this tiny ad would protect it:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!