Win a copy of Transfer Learning for Natural Language Processing (MEAP) 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
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

How JPA persist a boolean

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is a quite simple mapping question. I have an oracle database and i'm using toplink as jpa implementation. I want to persist a pojo that contains a boolean. In fact the toplink dialect will create NUMBER column with two possible values 1 or 0.
But is there a standard way to force a different representation like the @Temporal(TemporalType.DATE) or the @Enumerated(EnumType.STRING).

Thanks in advance
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The boolean type, like the other Java primitive types, is mapped with the optional @Basic annotation.
[ May 11, 2007: Message edited by: Edvins Reisons ]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello that's not exactly what i try to ask:
Imagine you have an existing database where a column of a table represent a Boolean value with Varchar2(1). Which can be 'Y' or 'N'.

Is there a simple way to create an jpa mapping that will map this column to a boolean?
Thanks in advance
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My understanding is that this customization can be done at the persistence provider level (I've seen similar customization options in Hibernate), rather than in JPA.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

the JPA specification itself does not specify how a boolean field is mapped to / represented in the database. You will have to look at your JPA implementation's documentation for vendor-specific extensions.

Having had the, err, opportunity to use TopLink (pre-JPA) in a previous life, I'd be surprised if TopLink didn't allow you to customize the mapping.

Cheers,
Oliver
 
Saloon Keeper
Posts: 21975
150
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know TopLink, but in Kodo JDO, it could be done either by defining fixed values in the vendor mapping support files (both for booleans and for enumerations) OR if you preferred, you could define a custom mapping class and bind it to the field.
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic