Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 2.1.6
Mapping documents: Persona.hbm.xml, Privilegio.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="it.crisaune.db.Persona" table="persona">
<id name="id" type="integer" unsaved-value="null">
<column name="id_persona" not-null="true"/>
<generator class="native"/>
<!--use-in-equals/-->
</id>
<property name="nome" column="nome" type="string"/>
<property name="cognome" column="cognome" type="string"/>
<property name="dataRegistraz" column="data_reg_pers" type="date"/>
<set name="privilegi" table="autorizzazioni" lazy="false"><!-- order-by="priorita asc"-->
<key column="persona"/>
<many-to-many column="privilegio" class="it.crisaune.db.Privilegio"/>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="it.crisaune.db.Privilegio" table="privilegio">
<id name="nome" type="string" unsaved-value="null">
<column name="nome_priv" not-null="true"/>
<generator class="assigned"/>
</id>
<property name="priorita" column="priorita" type="integer"/>
<property name="azione" column="azione" type="string"/>
<set name="persone" table="autorizzazioni" lazy="false" inverse="true">
<key column="privilegio"/>
<many-to-many column="persona" class="it.crisaune.db.Persona"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Set elenco = new HashSet();
Iterator it = privilegi.iterator();
while (it.hasNext()) {
Object o = it.next();
o = ((SelectItem)o).getValue();
o = session.load(Privilegio.class, (String)o);
Privilegio p = (Privilegio) o;
elenco.add(p);
}
value = (Persona) session.load(Persona.class, value.getId());
/*
The problem is here!!! because next update don't make persistent the change made by setPrivilegi(...)!!
*/
value.setPrivilegi(elenco);
session.update(value);
Full stack trace of any exception that occurs:no exceptions.
Name and version of the database you are using:Code:
MySQL 4.1
Tables created by schemaexport ant-task
Code:
CREATE TABLE `persona` (
`id_persona` int(11) NOT NULL auto_increment,
`nome` varchar(255) default NULL,
`cognome` varchar(255) default NULL,
`data_reg_pers` date default NULL,
PRIMARY KEY (`id_persona`),
) TYPE=MyISAM AUTO_INCREMENT=9 ;
-- --------------------------------------------------------
CREATE TABLE `privilegio` (
`nome_priv` varchar(255) NOT NULL default '',
`priorita` int(11) default NULL,
`azione` varchar(255) default NULL,
PRIMARY KEY (`nome_priv`)
) TYPE=MyISAM;
-- --------------------------------------------------------
CREATE TABLE `autorizzazioni` (
`persona` int(11) NOT NULL default '0',
`privilegio` varchar(255) NOT NULL default '',
PRIMARY KEY (`privilegio`,`persona`),
) TYPE=MyISAM;
The problem is that the collection is not made persistent on the database.
thanx....
cloud