How map a bit type in Mysql to hibernate?

前端 未结 4 1617
情书的邮戳
情书的邮戳 2021-01-04 14:20

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

@Entity
@Table(name = \"user\", catalog = \"bytecode\", uniqueConstraints =
@UniqueConstraint(columnN         


        
相关标签:
4条回答
  • 2021-01-04 14:44

    Do you have to have it as a bit type in MySQL? The easiest solution would be to change the data type in MySQL to tinyint(1).

    Otherwise you should be able to map your entity type to an integer using annotations; Not sure about this, have to look it up

    ...
    @Column(nullable=false)
    @Type(type="org.hibernate.type.BooleanType")
    private short type;
    
    0 讨论(0)
  • 2021-01-04 14:52

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

    @Column(name = "columnName", columnDefinition="BIT")
    private Boolean columnVariable;
    
    0 讨论(0)
  • 2021-01-04 14:53

    Hibernate has a special numeric_boolean type for this kind of mapping. You can configure it as follows:

    @Type(type = "numeric_boolean")
    private boolean type;  
    

    See also:

    • 6.1.1. Basic value types
    0 讨论(0)
  • 2021-01-04 15:06

    http://bugs.mysql.com/bug.php?id=28422 suggests it is a bug. http://www.xaprb.com/blog/2006/04/11/bit-values-in-mysql/ suggests it would be wise to skip it. But of course you can't tell the DBA to not use a bit column in MySQL - meaning either we need to use and older version of MySQL (< 5.0.3) or not use MySQL's bit + Hibernate at all.

    0 讨论(0)
提交回复
热议问题