gpt4 book ai didi

hibernate :- Could not execute JDBC batch update

转载 作者:行者123 更新时间:2023-12-04 02:42:39 37 4
gpt4 key购买 nike

我是 Hibernate 的新手,在尝试将 Friend_Job 对象保存到数据库时出现异常。

我从数据库中获取 Friend 和 Job 对象并创建新的 Frien_Job 对象。

测试.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)

引起:java.sql.BatchUpdateException:ORA-00932:不一致的数据类型:预期的 BINARY 得到 NUMBER

Friend_Job.java
public class Friend_Job {

private int primaryKey;
private String companyName;
private int salary = 0;
private Friend friend;
private Job job;

否则是 setter 和 getter。

如果需要更多信息,请告诉我......
提前致谢。

最佳答案

转至 hibernate.cfg.xml
查看<property name="hbm2ddl.auto">create</property>如果有创建,则更改为“更新”<property name="hbm2ddl.auto">update</property>

关于 hibernate :- Could not execute JDBC batch update,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9417818/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com