Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多对一休眠_Java_Hibernate_Orm - Fatal编程技术网

Java 多对一休眠

Java 多对一休眠,java,hibernate,orm,Java,Hibernate,Orm,我得去上Usuario和Rolusario。我使用hibernate反向工程生成java模型,其中包含这个.hbm.xml <hibernate-mapping> <class name="co.ejemplo.modelo.UsuarioTbl" table="usuario_tbl" catalog="structse_db"> <id name="idUsuario" type="java.lang.Integer">

我得去上Usuario和Rolusario。我使用hibernate反向工程生成java模型,其中包含这个.hbm.xml

<hibernate-mapping>
    <class name="co.ejemplo.modelo.UsuarioTbl" table="usuario_tbl" catalog="structse_db">
        <id name="idUsuario" type="java.lang.Integer">
            <column name="id_usuario" />
            <generator class="identity" />
        </id>
        <property name="login" type="string">
            <column name="login" length="50" not-null="true" unique="true" />
        </property>
        <property name="clave" type="string">
            <column name="clave" not-null="true" />
        </property>
        <property name="habilitado" type="byte">
            <column name="habilitado" not-null="true" />
        </property>
        <property name="fechaAlta" type="timestamp">
            <column name="fecha_alta" length="19" />
        </property>
        <property name="fechaBaja" type="timestamp">
            <column name="fecha_baja" length="19" />
        </property>
        <set name="rolUsuarioTbls" table="rol_usuario_tbl" inverse="true" lazy="true" fetch="select">
            <key>
                <column name="login" not-null="true" />
            </key>
            <one-to-many class="co.ejemplo.modelo.RolUsuarioTbl" />
        </set>
    </class>
</hibernate-mapping>


当我尝试使用
getHibernateTemplate().save(RolUsuarioTbl)
hibernate保存一个RolUsuarioTbl时,hibernate告诉我需要所有
UsuarioTbl
属性,但我只有在UsuarioTbl中设置登录名


如何保存USUARITBL中只有登录属性的
RolUsuarioTbl

多对一关系必须由两个表的代码决定,否则hibernate将无法识别父表的子表

<hibernate-mapping>
    <class name="co.ejemplo.modelo.RolUsuarioTbl" table="rol_usuario_tbl" catalog="structse_db">
        <id name="idUsuarioRol" type="java.lang.Integer">
            <column name="id_usuario_rol" />
            <generator class="identity" />
        </id>
        <many-to-one name="usuarioTbl" class="co.ejemplo.modelo.UsuarioTbl" fetch="select">
            <column name="login" not-null="true" />
        </many-to-one>
        <property name="rol" type="string">
            <column name="rol" length="50" not-null="true" />
        </property>
    </class>
</hibernate-mapping>