Hi, i'm newbie with HB, and i have problems to understand foreign mappings.
Now, i can mapping one "one-to-one" relation.
My three MySQL DB tables
Code:
`jforum_users` (
`user_id` int(11) NOT NULL auto_increment,
`user_active` tinyint(1) default NULL,
`username` varchar(50) NOT NULL default '',
`user_password` varchar(32) NOT NULL default '',
`user_session_time` bigint(20) default '0',
`user_session_page` int(11) NOT NULL default '0',
`user_lastvisit` datetime default NULL,
`user_regdate` datetime default NULL,
`user_level` tinyint(4) default NULL,
`user_posts` int(11) NOT NULL default '0',
`user_timezone` varchar(5) NOT NULL default '',
`user_style` tinyint(4) default NULL,
`user_lang` varchar(255) NOT NULL default '',
`user_dateformat` varchar(20) NOT NULL default '%d/%M/%Y %H:%i',
`user_new_privmsg` int(11) NOT NULL default '0',
`user_unread_privmsg` int(11) NOT NULL default '0',
`user_last_privmsg` datetime default NULL,
`user_emailtime` datetime default NULL,
`user_viewemail` tinyint(1) default '0',
`user_attachsig` tinyint(1) default '1',
`user_allowhtml` tinyint(1) default '0',
`user_allowbbcode` tinyint(1) default '1',
`user_allowsmilies` tinyint(1) default '1',
`user_allowavatar` tinyint(1) default '1',
`user_allow_pm` tinyint(1) default '1',
`user_allow_viewonline` tinyint(1) default '1',
`user_notify` tinyint(1) default '1',
`user_notify_always` tinyint(1) default '0',
`user_notify_text` tinyint(1) default '0',
`user_notify_pm` tinyint(1) default '1',
`user_popup_pm` tinyint(1) default '1',
`rank_id` int(11) default '0',
`user_avatar` varchar(100) default NULL,
`user_avatar_type` tinyint(4) NOT NULL default '0',
`user_email` varchar(255) NOT NULL default '',
`user_icq` varchar(15) default NULL,
`user_website` varchar(255) default NULL,
`user_from` varchar(100) default NULL,
`user_sig` text,
`user_sig_bbcode_uid` varchar(10) default NULL,
`user_aim` varchar(255) default NULL,
`user_yim` varchar(255) default NULL,
`user_msnm` varchar(255) default NULL,
`user_occ` varchar(100) default NULL,
`user_interests` varchar(255) default NULL,
`user_biography` text,
`user_actkey` varchar(32) default NULL,
`gender` char(1) default NULL,
`themes_id` int(11) default NULL,
`deleted` tinyint(1) default NULL,
`user_viewonline` tinyint(1) default '1',
`security_hash` varchar(32) default NULL,
`user_karma` double default NULL,
`user_authhash` varchar(32) default NULL,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
rc_rompecabezas` (
`id` int(10) unsigned NOT NULL auto_increment,
`nombre` varchar(45) NOT NULL,
`fecha_creacion` datetime NOT NULL,
`n_preguntas` int(10) unsigned NOT NULL,
`tipo` varchar(15) NOT NULL,
`descripcion` text,
`estado` tinyint(1) NOT NULL,
`ganador` varchar(45) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
`rc_usuario_rompecabezas` (
`id_usuario` int(11) NOT NULL,
`id_rompecabezas` int(10) unsigned NOT NULL,
`n_preguntas` int(10) unsigned NOT NULL,
KEY `FK_rc_usuario_rompecabezas_1` (`id_usuario`),
KEY `FK_rc_usuario_rompecabezas_2` (`id_rompecabezas`),
CONSTRAINT `FK_rc_usuario_rompecabezas_1` FOREIGN KEY (`id_usuario`) REFERENCES `jforum_users` (`user_id`),
CONSTRAINT `FK_rc_usuario_rompecabezas_2` FOREIGN KEY (`id_rompecabezas`) REFERENCES `rc_rompecabezas` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Hibernate mapping for `rc_usuario_rompecabezas` table
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
[b]<hibernate-mapping>
<class name="com.destrozatumente.utils.objetos.UsuarioRompecabezas" table="rc_usuario_rompecabezas">
<one-to-one name="idUsuario" class="com.destrozatumente.utils.objetos.Usuario" />
<one-to-one name="idRompecabezas" class="com.destrozatumente.utils.objetos.Rompecabezas" />
<property column="n_preguntas" name="nPregunta" not-null="true" type="integer" />
</class>
</hibernate-mapping>[/b]
And her Java class
Code:
public class UsuarioRompecabezas {
private int idUsuario;
private int idRompecabezas;
private int nPregunta;
public int getIdUsuario() {
return idUsuario;
}
public void setIdUsuario(int idUsuario) {
this.idUsuario = idUsuario;
}
public int getIdRompecabezas() {
return idRompecabezas;
}
public void setIdRompecabezas(int idRompecabezas) {
this.idRompecabezas = idRompecabezas;
}
public int getnPregunta() {
return nPregunta;
}
public void setnPregunta(int nPregunta) {
this.nPregunta = nPregunta;
}
}
Output Java console sais me the next error:
"
org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/destrozatumente/utils/objetos/UsuarioRompecabezas.hbm.xml"
Where is the problem? Thanks.
"