Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hi,
I have an object Answer with the field answerID(BigDecimal). The corresponding table has answerId Number as the primary key.
Can somebody guide me how to use id generator=auto for objects of Answer (with primary key as a BigDecimal)? When I use id generate= auto, it throws an exception which says that hibernate can only generate ids of int, long etc and not Big decimal.
public class Answer implements java.io.Serializable {
private BigDecimal answerId;
private Question wilCddQuestion;
private String text;
public Answer() {
}
public BigDecimal getAnswerId() {
return this.answerId;
}
public void setAnswerId(BigDecimal answerId) {
this.answerId = answerId;
}
}
public Question getQuestion() {
return this.Question;
}
public void setQuestion(Question Question) {
this.Question = Question;
}
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
}
Hibernate version:3.0
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 18, 2008 11:13:26 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="com.Answer" table="ANSWER" >
<id name="answerId" type="big_decimal">
<column name="ANSWER_ID" precision="22" scale="0" />
<generator class="auto" />
</id>
<many-to-one name="Question" class="com.Question" fetch="select">
<column name="QUESTION_ID" precision="22" scale="0" />
</many-to-one>
<property name="text" type="string">
<column name="TEXT" length="1000" />
</property>
</class>
</hibernate-mapping>
Full stack trace of any exception that occurs:
The error is :
When I try to use generator=auto in the mapping file for answer id, It says hibernate can only generate ids of int, long etc and not Big decimal.
Name and version of the database you are using:
Oracle 9i