Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How map a bit type in Mysql to hibernate?

i use the reverse engeneering in my class and get this:

@Entity
@Table(name = "user", catalog = "bytecode", uniqueConstraints =
@UniqueConstraint(columnNames = "email"))
public class User implements java.io.Serializable {

    private Integer id;
    private String email;
    private String password;
    private boolean type;

Database:

CREATE TABLE  `bytecode`.`user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `email` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `type` bit(1) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `email` (`email`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;

But i don't want to set 'true' or 'false' in my attribute 'type' but 1 or 0. How can i do that in hibernate ?

Best regards, Valter Henrique.

like image 687
Valter Silva Avatar asked Apr 06 '11 13:04

Valter Silva


1 Answers

I had a similar problem. The following mapping in Java solved my problem:

@Column(name = "columnName", columnDefinition="BIT")
private Boolean columnVariable;
like image 128
Divya Rakshu Avatar answered Sep 24 '22 01:09

Divya Rakshu