|
|
One-to-One Mapping Probelm
Hi,
I need help with a problem I am facing. I am currently getting an error when attempting to save an object with a one-to-one mapping. Below is the exception I am getting:Code:
Exception in thread quot;mainquot; org..orm.hibernate3.HibernateSystemException: attempted to assign id from null one-to-one property: KMS
My Mapping files are as follows:
Code:
lt;?xml version=quot;1.0quot;?gt;
lt;!DOCTYPE hibernate-mapping PUBLIC quot;-//Hibernate/Hibernate Mapping DTD 3.0//ENquot;
quot;hibernate-mapping-3.0.dtdquot;gt;
lt;!-- Generated Sep 11, 2007 3:40:08 PM by Hibernate Tools 3.2.0.b9 --gt;
lt;hibernate-mappinggt; lt;class name=quot;com.t.KMSquot; table=quot;KMSquot;gt; lt;id name=quot;instrumentquot; type=quot;big_decimalquot; gt; lt;column name=quot;INSTRUMENTquot; precision=quot;22quot; scale=quot;0quot; not-null=quot;truequot;/gt;lt;generator class=quot;com.t.IDGeneratorquot; /gt; lt;/idgt; lt;property name=quot;tableIdquot; type=quot;stringquot;gt;lt;column name=quot;TABLE_IDquot; length=quot;20quot; not-null=quot;truequot; /gt; lt;/propertygt; lt;property name=quot;creatorquot; type=quot;big_decimalquot;gt;lt;column name=quot;CREATORquot; precision=quot;22quot; scale=quot;0quot; not-null=quot;truequot; /gt; lt;/propertygt; lt;property name=quot;createTimequot; type=quot;datequot;gt;lt;column name=quot;CREATE_TIMEquot; length=quot;7quot; not-null=quot;truequot; /gt; lt;/propertygt; lt;property name=quot;instrgroupquot; type=quot;stringquot;gt;lt;column name=quot;INSTRGROUPquot; length=quot;20quot; /gt; lt;/propertygt; lt;property name=quot;actorquot; type=quot;stringquot;gt;lt;column name=quot;ACTORquot; length=quot;30quot; /gt; lt;/propertygt; lt;one-to-one name=quot;ESIquot; class=quot;com.t.ESIquot; cascade=quot;allquot; /gt; lt;/classgt;
lt;class name=quot;com.t.ESIquot;
table=quot;ESIquot;gt;
lt;id name=quot;instrumentquot; column=quot;INSTRUMENTquot; gt;
lt;generator class=quot;foreignquot;gt;
lt;param name=quot;propertyquot;gt;KMSlt;/paramgt;
lt;/generatorgt;
lt;/idgt; lt;one-to-one name=quot;KMSquot; class=quot;com.t.KMSquot; constrained=quot;truequot; /gt;
lt;property name=quot;wknquot; type=quot;stringquot;gt;
lt;column name=quot;WKNquot; length=quot;12quot; /gt;
lt;/propertygt;
lt;property name=quot;updateUserquot; type=quot;big_decimalquot;gt;
lt;column name=quot;UPDATE_USERquot; precision=quot;22quot; scale=quot;0quot;
not-null=quot;truequot; /gt;
lt;/propertygt;
lt;property name=quot;updateTimequot; type=quot;datequot;gt;
lt;column name=quot;UPDATE_TIMEquot; length=quot;7quot; not-null=quot;truequot; /gt;
lt;/propertygt;
lt;/classgt;
lt;/hibernate-mappinggt;
The IDGenerator is simply a class that returns an ID of type BIG_DECIMAL.Code:
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Properties;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;
public class IDGenerator implements IdentifierGenerator{public Serializable generate(SessionImplementor sessionImplementor, Object object)
throws HibernateException {
Session session=sessionImplementor.getFactory().openSession();
String SQL_QUERY=quot;SELECT MAX(instrument)+1 AS instrument FROM KMS quot;
+ quot; WHERE instrument gt; 100000000 AND instrument lt; 150000000quot;;
Query query=session.createQuery(SQL_QUERY);
BigDecimal instrumentId=(BigDecimal)query.iterate().next();
return instrumentId;
}
}
Could someone please point me in the right direction as to what is wrong?
the mappings are worng
each property one-to-one mapping name must has the property of the other class, and the inverse way from the other class to the first
i suggest that should see hibernate documentation, the examples code are very nice
let me know your advance
regards
I am having the same problem. Can somebody shed some light here.....
Thanks in advance
Visit this link to for one to one mapping error :
2009/01...ols-error.html
Hope this helps |
|