无法使用Hibernate 4.3.0在MySQL中插入布尔类型

时间:2016-01-03 10:18:21

标签: java mysql hibernate

人!

我正在用MySQL学习Hibernate。我创建了这个模型(用葡萄牙语写的):

//imports
@Entity
@Table(name = "alunos", schema = "progweb")
public class Aluno {
    @Id
    @GeneratedValue
    private Long id;
    @Column(name = "nome")
    private String nome;
    @Column(name = "email")
    private String email;
    @Column(name = "endereco")
    private String endereco;
    @Column(name = "formado")
    private Boolean formado;

    //getters and setters
}

我已经创建了一个类来测试它:

//imports
public class CriaAluno {
public static void main(String[] args) {
    Aluno aluno1 = new Aluno();

    aluno1.setNome("Jack");
    aluno1.setEmail("jack@gmail.com");
    aluno1.setEndereco("Av. dos Estados, 5001");
    aluno1.setFormado(true);
    System.out.println(aluno1.isFormado());

    // gravando registro
    EntityManagerFactory factory = Persistence
            .createEntityManagerFactory("aluno");
            EntityManager manager = factory.createEntityManager();
            manager.getTransaction().begin();
            manager.persist(aluno1);
            manager.getTransaction().commit();
            manager.close();
            System.out.println("Adicionado");

    }
}

除布尔类型外,一切正常;我在我的MySQL数据库中得到了这个:

mysql> select * from alunos;
+----+----------------+-----------------------+---------+------+
| id | email          | endereco              | formado | nome |
+----+----------------+-----------------------+---------+------+
|  3 | jack@gmail.com | Av. dos Estados, 5001 |         | Jack |
+----+----------------+-----------------------+---------+------+
1 row in set (0.00 sec)

我的数据库中有一个空值。

0 个答案:

没有答案