Win a copy of Svelte and Sapper in Action this week in the JavaScript 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Can a JPA entity have a field not mapped to a DB column?

 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is it possible for a JPA entity to have a field which is not mapped to any column in the data base table. Basically I need to store some additional data on my front end but I do not want to create an extra column in the table for this. Right now if I just add the field to the JPA entity like this...



It gives a DB error...



-206 means the column is unknown to the DB.

Thanks for any help.



 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Write the @Transient in the "get" method of your field.
 
Ranch Hand
Posts: 171
Hibernate Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is not a good practice to use the Entity as view Object. will suggest you to have them separately as Objects fetched from database will be attached entities.
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Herbert,

Thank you for your response.

I tried what you said but it still is not working. First I tried putting the transient annotation above the getter, then I put it above the field and the getter, and both times it gives the same error...



It seems to be happening when it is running a query, meaning it is putting this extra field in the query. Does transient also prevent the field from being included in queries...



Thanks.
 
Hebert Coelho
Ranch Hand
Posts: 754
Eclipse IDE Java
 
Jehan Jaleel
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hebert,

Your suggestion worked. I just had to restart my tomcat for it to pick up the change.

Thanks again.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic