当前位置: 首页 > 知识库问答 >
问题:

执行持久化时,在此ResultSet中找不到列名“Column”

季博
2023-03-14

我在数据库中有以下内容:

CREATE SEQUENCE "MODEL_C_MODEL_seq"
  INCREMENT 1
  MINVALUE 1
  MAXVALUE 9223372036854775807
  START 93
  CACHE 1;
ALTER TABLE "MODEL_C_MODEL_seq"

CREATE TABLE "MODEL"
(
  "C_USER" character varying(10) NOT NULL,
  "C_MODEL" serial NOT NULL,
  "TP_MODEL" character(5) NOT NULL,
  "NM_MODEL" character varying(20) NOT NULL,
  CONSTRAINT "MODEL_PK" PRIMARY KEY ("C_MODEL" ),
  CONSTRAINT "MODEL_CUSER_FK" FOREIGN KEY ("C_USER")
      REFERENCES "USER" ("C_USER") MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "MODEL_TPMODEL_FK" FOREIGN KEY ("TP_MODEL")
      REFERENCES "ADM_TYPES" ("C_TYPE") MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION,
  CONSTRAINT "MODEL_CUSER_NMNAME_UNIQUE" UNIQUE ("C_USER" , "NM_MODEL" )
)
WITH (
  OIDS=FALSE
);

我的实体是:

public class Model implements Serializable {
    private static final long serialVersionUID = 1L;

    **@Id
    @SequenceGenerator(name="modelPKgen", sequenceName="MODEL_C_MODEL_seq")
    @GeneratedValue(generator="modelPKgen", strategy= GenerationType.IDENTITY)
    @Column(name = "\"C_MODEL\"", unique=true, insertable=false)    
    private int cModel;**

    @OneToMany(cascade = CascadeType.ALL,  fetch= FetchType.EAGER)//, mappedBy = "model", fetch= FetchType.EAGER)
    @JoinColumn(name= "`C_MODEL`")
    private Collection<State> stateCollection;

    @JoinColumn(name = "`C_USER`", referencedColumnName ="`C_USER`", updatable = false)
    @ManyToOne(optional = false)
    private User user;

    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(name = "\"NM_MODEL\"")
    private String nmModel;     

    @JoinColumn(name = "\"TP_MODEL\"")
    @ManyToOne(optional = false)
    private AdmTypes admTypes;
...

查看许多帖子,我似乎对cmodel字段有正确的注释。

Model dbModel = new Model(user.getCUser(), simModel.getName());
        AdmTypes dbAdm = new AdmTypes(simModel.getType());
        dbModel.setAdmTypes(dbAdm);

        **em.persist(dbModel);**
        em.flush();
Caused by: org.hibernate.exception.SQLGrammarException: The column name "C_MODEL" was not found in this ResultSet.
insert 
    into
        "MODEL"
        ("TP_MODEL", "NM_MODEL", "C_USER") 
    values
        (?, ?, ?)

更新(完成stacktrace):

javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: The column name "C_MODEL" was not found in this ResultSet.
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1367)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1295)
    at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1301)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:866)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.persist(EntityManagerWrapper.java:269)
    at com.librethinking.simmodsys.persistence.adapters.ModelConverter.SIMModelToModel(ModelConverter.java:65)
    at com.librethinking.simmodsys.ejb.ModelBean.saveSIMModel(ModelBean.java:72)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5366)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5338)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5326)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at $Proxy186.saveSIMModel(Unknown Source)
    at com.librethinking.simmodsys.ejb.__EJB31_Generated__ModelBean__Intf____Bean__.saveSIMModel(Unknown Source)
    at com.librethinking.simmodsys.web.ModelsController.saveModel(ModelsController.java:366)
    at com.librethinking.simmodsys.web.ModelsController.processRequest(ModelsController.java:104)
    at com.librethinking.simmodsys.web.ModelsController.doPost(ModelsController.java:181)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98)
    at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:725)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1019)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:225)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:722)
Caused by: org.hibernate.exception.SQLGrammarException: The column name "C_MODEL" was not found in this ResultSet.
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.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.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:108)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
    at $Proxy189.getInt(Unknown Source)
    at org.hibernate.id.IdentifierGeneratorHelper.get(IdentifierGeneratorHelper.java:152)
    at org.hibernate.id.IdentifierGeneratorHelper.getGeneratedIdentity(IdentifierGeneratorHelper.java:92)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:100)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2767)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3278)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:203)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:183)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:167)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:320)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:287)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:193)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
    at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:78)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:208)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:151)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:78)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:844)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:819)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:823)
    at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:860)
    ... 58 more
Caused by: org.postgresql.util.PSQLException: The column name "C_MODEL" was not found in this ResultSet.
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.findColumn(AbstractJdbc2ResultSet.java:2550)
    at org.postgresql.jdbc2.AbstractJdbc2ResultSet.getInt(AbstractJdbc2ResultSet.java:2414)
    at sun.reflect.GeneratedMethodAccessor93.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.hibernate.engine.jdbc.internal.proxy.AbstractResultSetProxyHandler.continueInvocation(AbstractResultSetProxyHandler.java:104)
    ... 83 more

共有1个答案

庄阿苏
2023-03-14

我突然想到几件事:

>

  • 创建序列生成器,然后通知id生成为generationtype.identity。我会尝试generationtype.sequencegenerationtype.auto。如果标识工作,我会感到惊讶,因为Hibernate文档说它适用于DB2、MySQL、MS SQL Server、Sybase和HypersonicSQL。

    我将从标识符的@column注释中删除insertable=false属性。我假设基于序列生成属性,Hibernate将选择序列值并将其插入:select currval(PG_GET_SERIAL_SELECENCE(...)),这只在insertable为true时才起作用。

  •  类似资料:
    • 除了去掉“D”之外,有没有办法。从第一个查询开始,使第一个代码段不抛出错误消息? 以下是源代码:

    • 问题内容: 我收到以下错误:org.postgresql.util.PSQLException:在此ResultSet中找不到列名usuario。 但是,我在适当的类中正确声明了以下usuario列! UsuariosGruposDAO.class UsuariosGrupos.class 错误出现在以下行: 我的List方法: 奇怪的是,当我分别测试我的列表时,数据表会显示适当的结果。但是,当我

    • 错误消息 线程“main”org.openqa.selenium.nosuchelementException:没有这样的元素:找不到元素:{“method”:“XPath”,“Selector”:“.//*[@id='TreeBox1']/div/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/table/tbody/tr[2]/td[2]/tab

    • 我正在使用网络逻辑10.3。我正在尝试配置一个持久订阅,其中包含由 jdbc 存储(在 Oracle DB 中)支持的持久消息。我有一个主题,MDB 正在作为持久订阅者侦听该主题。在场景-1下:如果我发送消息,它会命中MDB。 在场景2中:我挂起了MDB,希望发送到主题的消息只要不被MDB(它是唯一注册的持久订阅者)使用,就会一直存在。但是当我向主题发送消息时,它短暂地出现在那里,然后就消失了(我

    • 这是我的坚持课: 这是我的persistence.xml:

    • 我是框架新手(刚通过这门课),这是我第一次使用spring boot。 我正在尝试运行一个简单的Junit测试,看看我的CrudRepositories是否真的可以工作。 我不断得到的错误是: 找不到@SpringBootConfiguration,您需要使用@ContextConfiguration或@SpringBootTest(Classes=...)使用您的测试java.lang.Ille