• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How JPA persist a boolean

 
Anonymous
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
 
Edvins Reisons
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.
 
Oliver Kamps
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
 
Tim Holloway
Saloon Keeper
Posts: 18367
56
Android Eclipse IDE 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic