小编iLu*_*ode的帖子

休眠“列---不能为空

我将 Hibernate 与 phpmyadmin (MySQL) 结合使用。最近我发现了一个非常奇怪的错误。每当我尝试插入新行 (.persist) 时,都会出现以下错误:

com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'user_id' cannot be null
Run Code Online (Sandbox Code Playgroud)

错误真的很明显。但奇怪的是,这个错误无处不在。我完全确定属性 userId(映射到“user_id”)不为空。我测试了几次。这是映射部分:(在@manytoone 部分)。

  <property name="userId" update="false" insert="false" column="user_id" type="java.lang.Long" />
Run Code Online (Sandbox Code Playgroud)

OneToMany 部分不是我猜的问题。

所以这里的问题是,我 100% 确定该值不为空,但 Hibernate 仍将其作为空值传递给 MySQL。(Getter 确实有效)。

更新

@ManyToOne 端,导致错误

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="xx.xx.xx.AlarmEntity" table="alarms">
        <meta attribute="class-description">
            Hierin staan de object properties van de alarm entiteit.
        </meta>
        <id name="id" type="java.lang.Long" column="id">
            <generator class="native"/>
        </id>
        <property name="keepsRunning"  type="java.lang.Boolean">
            <column name="keeps_running" sql-type="int"></column>
        </property>
        <property name="userId" update="false" insert="false" …
Run Code Online (Sandbox Code Playgroud)

java mapping hibernate jersey-2.0

6
推荐指数
1
解决办法
8633
查看次数

标签 统计

hibernate ×1

java ×1

jersey-2.0 ×1

mapping ×1