0

My java application is using hibernate with Oracle 10g as the database. I have landed into an issue and not able to proceed and i need your help here. Below is the issue that i am facing.

I have a Column in one of my Oracle table which has a datatype of Varchar2(1 byte). I want to know the proper dataype that i need to use in my pojo class. Also in the hibernate mapping file what should be the datatype for the same property. when i am running the file hibernate keeps on giving error like cannot do a conversion. below are my pojo and .hbm file

public class destination implements Serializable{

    private String configId;        
    private String isCurrent;        
    //other properties and getter, setters

}

destination.hbm.xml

<class name="com.testing" table="configuration">
    <id name="configID" type="java.lang.Integer">
        <column name="configuration_id" />
        <generator class="identity" />
    </id>
   <property name="isCurrent" type="Not-SURE">
        <column name="is_current" not-null="true" />
    </property>

The column i am talking about is the isCurrent property in the pojo and .hbm.xml file. Its defined as Varchar2(1 byte) in the db. I ma not sure about the datatype and marked it a String but the issue still persists.

I have searched the net but have not got any proper solution for this issue.

Can you please help me here as its really eating my head a lot.

2
  • It would help if you posted the exact error message. Commented Aug 10, 2012 at 18:59
  • hi gotuskar, I have tried String, Char and Byte as the datatype for isCurrent property in the pojo class but no luck. Also my main concern is the mapping in the hbm.xml file. here also tried but same issue. Hey Arron, i dont have the exact error message with me now but hibernate is trying t do a conversion for the isCurrent field by using the mapping in the hbm file. Commented Aug 10, 2012 at 19:15

2 Answers 2

1

I would focus on the configId you declared it as String in the class but as Integer in the xml.

<id name="configID" type="java.lang.Integer">
Sign up to request clarification or add additional context in comments.

2 Comments

sorry om its just a typo. its a Integer value in the pojo class.
Hi orn thanks.As i said the configId property that you pointed out above was a typo.and i don't know if i would have posted the entire hbm.xml and pojo class files you guys would have definitely found out what mistake i had committed. well in the remainder of the hbm.xml file there was a property which i had mapped to a different data type in the pojo class. after going through each and every property i found out what blunder i had done. my advice to other guys please post the entire hbm.xml and pojo classes when u ask questions. somebody might just find it out what the mistake is..
0

Im guessing you want to store current flag on the record. In that case you can do

public class destination implements Serializable{

    private String configId;        
    private boolean current;        

    public boolean isCurrent() {
        return current;
    } 

}

and hbm mapping like

<property name="current" type="yes_no">
        <column name="is_current" not-null="true" />
    </property>

2 Comments

Thanks manko. Yes i need t store Y/N value for isCurrent in the column but the column datatype is Varchar2(1 byte) in Oracle.I have already tried this option but hibernate gives a topluizer error telling that "Cannot find the getter for isCurrent property". i am not sure if its some sort of mapping issue or a datatype issue.
manko your solution also works if i convert the datatype of the property to boolean. well there was a different property which i had mapped wrongly. thanks to yoou also.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.