i am new in Hibernate, i am getting exception when trying to save Friend_Job object on database.
I am getting Friend and Job object from database and creating new Frien_Job object.
Test.java
SessionFactory sessionFectory = new Configuration().configure().buildSessionFactory();
Session session = sessionFectory.openSession();
Transaction transaction = session.beginTransaction();
Friend friend= (Friend) session.load(Friend.class, new Integer(1));
Job job = (Job) session.load(Job.class, new Integer(3));
Friend_Job friend_Job = new Friend_Job();
friend_Job.setFriend(friend);
friend_Job.setJob(job);
friend_Job.setCompanyName(job.getCompanyName());
session.save(friend_Job);
transaction.commit(); //Exception here
Friend_Job.hbm.xml
<hibernate-mapping>
<class name="hibernateTest.Friend_Job" table="FRIEND_JOB">
<id name="primaryKey" column="PRIMARY_KEY">
<generator class="increment"/>
</id>
<property name="companyName" type="string" column="COMPANY_NAME"/>
<property name="salary" column="SALARY"/>
<many-to-one name="friend" class="hibernateTest.Friend" cascade="none" column="FK_FRIEND_ID"/>
<many-to-one name="job" class="hibernateTest.Job" cascade="none" column="FK_JOB_ID"/>
</class>
</hibernate-mapping>
Exception :-
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:90)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:365)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137)
at hibernateTest.Test.main(Test.java:20)
Caused by: java.sql.BatchUpdateException: ORA-00932: inconsistent datatypes: expected BINARY got NUMBER
Friend_Job.java
public class Friend_Job {
private int primaryKey;
private String companyName;
private int salary = 0;
private Friend friend;
private Job job;
and else are setter and getter.
Please let me know if more info required.... Thanks in advance.
Go to hibernate.cfg.xml
Check<property name="hbm2ddl.auto">create</property>
If there is create then change to "update"<property name="hbm2ddl.auto">update</property>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With