我在应用程序中使用spring boot和hibernate,下面是Model类中的配置。
@Id
@SequenceGenerator(name="SCHEMA1.INQUIRY_QUEUE_SEQ", sequenceName="SCHEMA1.INQUIRY_QUEUE_SEQ",allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SCHEMA1.INQUIRY_QUEUE_SEQ")
@Column(name="INQ_ID")
private Integer inquiryId;
以前,它是用于数据库映射的xml配置,如下所示。
<hibernate-mapping>
<class name="com.company.domain.model.AnalystInquiryForm" table="INQUIRY_QUEUE" schema="SCHEMA1">
<id name="inquiryId" type="java.lang.Integer">
<column name="INQ_ID"/>
<generator class="sequence">
<param name="sequence">SCHEMA1.INQUIRY_QUEUE_SEQ</param>
</generator>
</id>
<property name="transactionDate" type="java.sql.Timestamp">
<column name="INQ_ADD_DT" />
</property>
</class>
</hibernate-mapping>
得到以下错误
16:08:36.873 [http-nio-8551-exec-2] DEBUG org.hibernate.SQL - select schema1.inquiry_queue_seq.nextval from dual
16:08:37.419 [http-nio-8551-exec-2] WARN org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 942, SQLState: 42000
16:08:37.431 [http-nio-8551-exec-2] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - ORA-00942: table or view does not exist
16:36:23.977 [http-nio-8551-exec-2] ERROR com.company.user.controller.UserController - Error in processAnalystInquiry : could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet
我的Spring Boot配置如下。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath />
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>ojdbc</groupId>
<artifactId>ojdbc15</artifactId>
<version>11.2.0.2.0</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
</dependency>
而中间层是
@Autowired
private AnalystInquiryFormRepository analystInquiryFormRepository;
public void addToInquiryQueue(AnalystInquiryForm form) {
analystInquiryFormRepository.save(form);
}
我的资料库是..
import org.springframework.data.repository.CrudRepository;
import com.company.user.model.AnalystInquiryForm;
public interface AnalystInquiryFormRepository extends
CrudRepository<AnalystInquiryForm, Integer>{
}
最佳答案
您正在使用@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SCHEMA1.INQUIRY_QUEUE_SEQ")
这意味着DB应该有一个名为SCHEMA1.INQUIRY_QUEUE_SEQ的表。
如果该表已经存在,请确保与您一起访问该表的用户具有所有适当的权限。