gpt4 book ai didi

java - Hibernate:线程 "main"org.hibernate.exception.SQLGrammarException 中出现异常: 'DTYPE' 中的未知列 'field list'

转载 作者:行者123 更新时间:2023-12-01 15:00:31 25 4
gpt4 key购买 nike

当我尝试运行我的代码时,它会生成以下异常。

INFO: HHH000397: Using ASTQueryTranslatorFactory
Hibernate: select sequence_next_hi_value from hibernate_sequences where sequence_name = 'Ancestor' for update
Hibernate: insert into hibernate_sequences(sequence_name, sequence_next_hi_value) values('Ancestor', ?)
Hibernate: update hibernate_sequences set sequence_next_hi_value = ? where sequence_next_hi_value = ? and sequence_name = 'Ancestor'
Hibernate: insert into Ancestor (nationality, DTYPE, id) values (?, 'Ancestor', ?)
Dec 05, 2012 1:14:43 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 1054, SQLState: 42S22
Dec 05, 2012 1:14:43 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Unknown column 'DTYPE' in 'field list'
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Unknown column 'DTYPE' in 'field list'
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDeleg ate.java:122)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy10.executeUpdate(Unknown Source)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2859)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3300)
at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:275)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1214)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:403)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at com.mappings.util.HibernateUtil.commitTransaction(HibernateUtil.java:70)
at com.mappings.main.MappingsTest.main(MappingsTest.java:33)
Caused by: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'DTYPE' in 'field list'
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 17 more

当我尝试将数据插入表中时,代码生成异常。我无法理解为什么会生成此异常。以下是我的代码:-

@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
public class Ancestor {
private int id;
private String nationality;

@Id
@GeneratedValue(strategy=GenerationType.TABLE)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNationality() {
return nationality;
}
public void setNationality(String nationality) {
this.nationality = nationality;
}
}

@Entity
public class Parent extends Ancestor{
private String firstName;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}
}

@Entity
public class Child extends Parent{
private String lastName;

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}
}


public class MappingsTest {
public static void main(String[] args) {
HibernateUtil.recreateDatabase();
Ancestor ancestor = new Ancestor();
ancestor.setNationality("Indian");

Ancestor ancestor1 = new Ancestor();
ancestor1.setNationality("Indian");

Parent parent = new Parent();
parent.setNationality("India");
parent.setFirstName("Harmeet Singh");

Child child = new Child();
child.setNationality("Indian");
child.setFirstName("Harmeet Singh");
child.setLastName("Kalra");

Session session = HibernateUtil.beginTransaction();
session.saveOrUpdate(ancestor);
session.saveOrUpdate(parent);
session.saveOrUpdate(child);
session.saveOrUpdate(ancestor1);
HibernateUtil.commitTransaction();
}
}

最佳答案

您的架构缺少用于区分多态实体类型(AncestorParent)的鉴别器列(DTYPE 是其默认名称) .

如果您手动创建架构,则需要添加该列(您可以使用 @DiscriminatorColumn 配置其名称),或者让 Hibernate 生成新架构。

关于java - Hibernate:线程 "main"org.hibernate.exception.SQLGrammarException 中出现异常: 'DTYPE' 中的未知列 'field list',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13718612/

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