我正在使用 Spring Boot 创建类(class)和主题数据库。一旦我对类(class)类(class)进行了更改,就会出现一堆错误,我遇到了麻烦。我不确定出了什么问题。以下是错误消息:
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: alter table course drop constraint FKokaxyfpv8p583w8yspapfb2ar
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : Schema 'SA' does not exist
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: drop table course
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : Schema 'SA' does not exist
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000389: Unsuccessful: drop table topic
ERROR 1136 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : Schema 'SA' does not exist
WARN 1136 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Warning Code: 10000, SQLState: 01J01
WARN 1136 --- [ main] o.h.engine.jdbc.spi.SqlExceptionHelper :
未创建数据库“memory:testdb”,而是连接到现有数据库。
另外,这是我的类(class)代码,我认为主题代码没问题,但我遇到了麻烦。我正在使用内部数据库。
包装...
@Entity
public class Course {
// here generate constructors and getters/setters
@Id
private String id;
private String Name;
private String description;
@ManyToOne
private Topic topic; //use it to tie this class to the Topic class, to make it easier for the user
public Topic getTopic() {
return topic;
}
public void setTopic(Topic topic) {
this.topic = topic;
}
public Course() {
}
public Course(String id, String name, String description, String topicId) {
super();
this.id = id;
Name = name;
this.description = description;
this.topic = new Topic(topicId,"","");
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return Name;
}
public void setName(String name) {
Name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
也是我的 Controller :
@RestController() //makes anything a rest controller, every time you build a class and add this on top of it
public class CourseController {
@Autowired // it marks the courseService as something that needs dependency inj.
private CourseService courseService;// To create a service you need a private courseService variable
//GETALL
@RequestMapping("/topics/{id}/courses")
public List<Course> getAllcourses(@PathVariable String id){
return courseService.getAllCourses(id); //getAllCourses for the topic ID
}
//GET
@RequestMapping("/topics/{topicId}/courses/{id}")
public Course getCourse(@PathVariable String id) {
return courseService.getCourse(id);
}
//POST
@RequestMapping(method = RequestMethod.POST, value = "/topics/{topicId}/courses")
public void addCourse(@RequestBody Course course, @PathVariable String topicId) {
course.setTopic(new Topic(topicId, "", ""));
courseService.addCourse(course);
}
//PUT
@RequestMapping(method = RequestMethod.PUT, value = "/topics/{topicId}/courses/{id}")
public void updateCourse(@RequestBody Course course, @PathVariable String id, @PathVariable String topicId) {
course.setTopic(new Topic(topicId, "", ""));
courseService.updateCourse(course);
}
//DELETE
@RequestMapping(method = RequestMethod.DELETE, value = "/topics/{topicId}/courses/{id}")
public void deletecourse(@PathVariable String id, @PathVariable String topicId) {
courseService.deleteCourse(id);
}
}
最后是我的服务类:
package io.msela.springbootstarter.course;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class CourseService {
@Autowired // it injects the courseRepository as it's initialized
private CourseRepository courseRepository;
public List<Course> getAllCourses(String topicId){ //getting all is not good!
List<Course> courses = new ArrayList<>() ;
courseRepository.findByTopicId(topicId).forEach(courses::add);
return courses;
}
public Course getCourse(String id) {
return courseRepository.findOne(id);
}
public void addCourse(Course course) {
courseRepository.save(course); //save a course to the database
}
public void updateCourse(Course course) {
courseRepository.save(course);
//save does both add and update
}
public void deleteCourse(String id) {
courseRepository.delete(id);
}
}
编辑:这也是我的 pom.xml 文件
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<groupId>io.msela</groupId>
<artifactId>course-api-data</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>course-api-data</name>
<description>Course API with Spring Data</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
编辑 2
实际错误似乎如下:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'courseController': Unsatisfied dependency expressed through field 'courseService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'courseService': Unsatisfied dependency expressed through field 'courseRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'courseRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Could not create query metamodel for method public abstract java.util.List io.msela.springbootstarter.course.CourseRepository.findByName(java.lang.String)!
最佳答案
此错误仅出现在 Derby 中。这是因为您的属性默认设置为:
spring.jpa.hibernate.ddl-auto=create-drop
您必须将其设置为:
spring.jpa.hibernate.ddl-auto=update
可以在此处找到更多信息:https://github.com/spring-projects/spring-boot/issues/7706
关于java - 架构 'SA' 不存在并删除表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45322941/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t
我有一个对象has_many应呈现为xml的子对象。这不是问题。我的问题是我创建了一个Hash包含此数据,就像解析器需要它一样。但是rails自动将整个文件包含在.........我需要摆脱type="array"和我该如何处理?我没有在文档中找到任何内容。 最佳答案 我遇到了同样的问题;这是我的XML:我在用这个:entries.to_xml将散列数据转换为XML,但这会将条目的数据包装到中所以我修改了:entries.to_xml(root:"Contacts")但这仍然将转换后的XML包装在“联系人”中,将我的XML代码修改为
查看Ruby的CSV库的文档,我非常确定这是可能且简单的。我只需要使用Ruby删除CSV文件的前三列,但我没有成功运行它。 最佳答案 csv_table=CSV.read(file_path_in,:headers=>true)csv_table.delete("header_name")csv_table.to_csv#=>ThenewCSVinstringformat检查CSV::Table文档:http://ruby-doc.org/stdlib-1.9.2/libdoc/csv/rdoc/CSV/Table.html
我在我的项目中添加了一个系统来重置用户密码并通过电子邮件将密码发送给他,以防他忘记密码。昨天它运行良好(当我实现它时)。当我今天尝试启动服务器时,出现以下错误。=>BootingWEBrick=>Rails3.2.1applicationstartingindevelopmentonhttp://0.0.0.0:3000=>Callwith-dtodetach=>Ctrl-CtoshutdownserverExiting/Users/vinayshenoy/.rvm/gems/ruby-1.9.3-p0/gems/actionmailer-3.2.1/lib/action_mailer
在MRIRuby中我可以这样做:deftransferinternal_server=self.init_serverpid=forkdointernal_server.runend#Maketheserverprocessrunindependently.Process.detach(pid)internal_client=self.init_client#Dootherstuffwithconnectingtointernal_server...internal_client.post('somedata')ensure#KillserverProcess.kill('KILL',
我已经从我的命令行中获得了一切,所以我可以运行rubymyfile并且它可以正常工作。但是当我尝试从sublime中运行它时,我得到了undefinedmethod`require_relative'formain:Object有人知道我的sublime设置中缺少什么吗?我正在使用OSX并安装了rvm。 最佳答案 或者,您可以只使用“require”,它应该可以正常工作。我认为“require_relative”仅适用于ruby1.9+ 关于ruby-主要:Objectwhenrun
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我发现ActiveRecord::Base.transaction在复杂方法中非常有效。我想知道是否可以在如下事务中从AWSS3上传/删除文件:S3Object.transactiondo#writeintofiles#raiseanexceptionend引发异常后,每个操作都应在S3上回滚。S3Object这可能吗?? 最佳答案 虽然S3API具有批量删除功能,但它不支持事务,因为每个删除操作都可以独立于其他操作成功/失败。该API不提供任何批量上传功能(通过PUT或POST),因此每个上传操作都是通过一个独立的API调用完成的
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="