Hi all, I have a problem and I hope you can help me.
I have a table called FAppDescriptor and another which name is FTheme. FTheme contains a list of themes, and FAppDescriptor must have which theme it has, and for it, I have created another table called FDesTheme.
The two first tables has been described as always, with it's own id, and all the attributes and a set parameter targeting to the FDesTheme table.
the FDesTheme table has the id for both tables as it's own id, it's a composite id. I have defined it as I have seen in several examples and tutorials in this case. I have defined a class called FDesThemeFK and FDesTheme on this way:
public class FDesTheme implements java.io.Serializable { private FDesThemeFK primary = new FDesThemeFK();
public FDesTheme(){ } public FDesTheme(FAppDescriptor fad,FTheme ft){ primary.setFAppDescriptor(fad); primary.setFTheme(ft); } public FDesThemeFK getPrimary() { return primary; }
public void setPrimary(FDesThemeFK primary) { this.primary = primary; } }
and now, the FDesThemeFK:
public class FDesThemeFK implements java.io.Serializable {
private FAppDescriptor FAppDescriptor; private FTheme FTheme; public FDesThemeFK(){ } public FAppDescriptor getFAppDescriptor(){ return this.FAppDescriptor; } public void setFAppDescriptor(FAppDescriptor FAppDescriptor){ this.FAppDescriptor=FAppDescriptor; } public FTheme getFTheme(){ return FTheme; } public void setFTheme(FTheme FTheme){ this.FTheme=FTheme; } //s'han d'implementar public boolean equals(Object other) { if (this == other) return true; if ( !(other instanceof FDesThemeFK) ) return false;
final FDesThemeFK cat = (FDesThemeFK) other;
if ( !cat.getFAppDescriptor().equals( getFAppDescriptor() ) ) return false; if ( !cat.getFTheme().equals( getFTheme() ) ) return false;
return true; }
public int hashCode() {
return (getFTheme()).hashCode(); } }
and the mapping file is:
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="com.alcatel.cdp.db.connector.orm.FDesTheme" table="f_destheme"> <composite-id name="primary" class="com.alcatel.cdp.db.connector.orm.FDesThemeFK"> <key-property name="FAppDescriptor" type="java.lang.Integer"/> <key-property name="FTheme" type="java.lang.String"/> </composite-id> </class> </hibernate-mapping>
I have tried several diferent things, but it doesn't work. When I insert it in the database, i do:
public FDesTheme insertOrUpdateFDesTheme(FDesTheme fdt,FDesThemeFK pk) throws HibernateException {
Session session = null; try { session = sessionFactory.openSession();
session.load(fdt,pk); session.saveOrUpdate(fdt); ... }
Doing this, he tries to select the table with the parameters I give him, he doesn't try to insert them, and I'm becoming crazy!!!!!
Please, if you have any idea what I do wrong or another way to do it, tell me.
Thank you,
David
|