[英]Hibernate many-to-one
I have to tables Usuario_tbl and RolUsuario_tbl. 我必须表Usuario_tbl和RolUsuario_tbl。 I generate java model with hibernate reverse engineering having this .hbm.xml
我使用具有此.hbm.xml的休眠逆向工程生成Java模型
<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>
and 和
<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>
When I try to save one RolUsuarioTbl using getHibernateTemplate().save(rolUsuarioTbl)
hibernate tells me that needs all the UsuarioTbl
properties but I only has setting the login in UsuarioTbl. 当我尝试使用
getHibernateTemplate().save(rolUsuarioTbl)
保存一个RolUsuarioTbl时,hibernate告诉我需要所有UsuarioTbl
属性,但我只在UsuarioTbl中设置了登录名。
How can I save RolUsuarioTbl
having only login property in UsuarioTbl? 如何在UsuarioTbl中保存
RolUsuarioTbl
具有登录属性的RolUsuarioTbl?
多对一关系必须由两个表的代码组成,否则休眠将无法识别父表的子级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.