Hi, I have a problem insering in a table. I have two tables, one called FAppDescriptor and another called FTheme. FTheme has a list of themes, and FAppDescriptor must have which of them he has, and can have more than one, so I have created another table called FDesTheme, which relation them. I put the classes and it's mapping
FAppDescriptor (there are more parameters, but I have deleted to simplify the post)
Code:
public class FAppDescriptor implements java.io.Serializable {
// Fields
....
private Set FTheme;
// Constructors
/** default constructor */
public FAppDescriptor() {
}
public Set getFTheme() {
return FTheme;
}
public void setFTheme(Set theme) {
FTheme = theme;
}
}
The mapping class
Code:
<?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.FAppDescriptor" table="f_appdescriptor" >
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
...
<set name="FTheme" table="com.alcatel.cdp.db.connector.orm.FDesTheme">
<key column="appId"/>
<many-to-many column="themeId" class="com.alcatel.cdp.db.connector.orm.FTheme"/>
</set>
</class>
</hibernate-mapping>
FTheme
Code:
public class FTheme implements java.io.Serializable {
// Fields
private Integer id;
private String theme;
private Set FAppDescriptor;
// Constructors
/** default constructor */
public FTheme() {
}
/** minimal constructor */
public FTheme(String theme) {
this.theme = theme;
}
public String getTheme() {
return this.theme;
}
public void setTheme(String theme) {
this.theme = theme;
}
public Set getFAppDescriptor() {
return FAppDescriptor;
}
public void setFAppDescriptor(Set appDescriptor) {
FAppDescriptor = appDescriptor;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
The mapping class
Code:
<?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.FTheme" table="f_theme">
<id name="id" type="java.lang.Integer">
<column name="id" />
<generator class="identity" />
</id>
<property name="theme" type="java.lang.String">
<column name="theme" length="45" not-null="true" />
</property>
<set name="FAppDescriptor" table="com.alcatel.cdp.db.connector.orm.FDesTheme">
<key column="themeId"/>
<many-to-many column="appId" class="com.alcatel.cdp.db.connector.orm.FAppDescriptor"/>
</set>
</class>
</hibernate-mapping>
FDesTheme
Code:
public class FDesTheme implements java.io.Serializable {
private FAppDescriptor FAppDescriptor;
private FTheme FTheme;
public FDesTheme(){
}
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;
}
}
The mapping class
Code:
<?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>
<key-property name="FAppDescriptor" type="com.alcatel.cdp.db.connector.orm.FAppDescriptor"/>
<key-property name="FTheme" type="com.alcatel.cdp.db.connector.orm.FTheme"/>
</composite-id>
</class>
</hibernate-mapping>
Here I put how I save to the data base
Code:
Set<FDesTheme> temes=new HashSet<FDesTheme>();
FTheme ft;
ft=CdpDBConnector.selectFTheme(theme.get(i));//to get the themes
FAppDescriptor fap=new FAppDescriptor();
fdt.setFAppDescriptor(fap);//fill the FDesTheme parameters
fdt.setFTheme(ft);
temes.add(fdt);
fap.setFTheme(temes);//give it to the FAppDescriptor
fap=CdpDBConnector.insertOrUpdateFAppDescriptor(fap);//insering to the database
The error it gives to me
Code:
Hibernate: insert into com.alcatel.cdp.db.connector.orm.FDesTheme (appId, themeId) values (?, ?)
12/14 13:17:51,375 ERROR [property.BasicPropertyAccessor] http-0.0.0.0-8081-2: IllegalArgumentException in class: com.alcatel.cdp.db.connector.orm.FTheme, getter method of property: id
12/14 13:17:51,375 ERROR [.AbstractFlushingEventListener] http-0.0.0.0-8081-2: Could not synchronize database state with session
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.alcatel.cdp.db.connector.orm.FTheme.id
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3256)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2982)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
...
Please, if ther's someone who could help me, I'll apreciate it, I have tried several thinks, and nothing worked..
Thanks in advance
David