我正在尝试将对象列表保存到
sql-server
我的数据库
Spring Boot
当我调用
save
方法。
2018-11-26 11:50:41.896 WARN 22082 --- [nio-8080-exec-2] o.h.e.j.s.SqlExceptionHelper : SQL Error: 208, SQLState: S0002
2018-11-26 11:50:41.897 ERROR 22082 --- [nio-8080-exec-2] o.h.e.j.s.SqlExceptionHelper : Invalid object name 'ticket'.
以下是am使用的配置:
#SQL Server configurations
spring.datasource.url=jdbc:sqlserver://my.server.ip.address;databaseName=UH
spring.datasource.username=Test
spring.datasource.password=Test@123
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.show-sql=true
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
以及
Model
@Entity(name = "Ticket")
public class Ticket {
public Ticket() {
}
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name = "ticket_id", nullable = false, length=200)
private long ticket_id;
@Column(name = "topic", nullable = false, length=200)
private String topic;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Tag> tag;
@Column(name = "type", nullable = false, length=200)
private String type;
@Column(name = "brand", nullable = false, length=200)
private long brand;
@Column(name = "ticket_group", nullable = false, length=200)
private long ticket_group;
@Column(name = "priority", nullable = false, length=200)
private String priority;
@Column(name = "status", nullable = false, length=200)
private String status;
@Column(name = "created_date", nullable = false, length=200)
private String created_date;
@Column(name = "created_time", nullable = false, length=200)
private String created_time;
@Column(name = "channel", nullable = false, length=200)
private String channel;
// Getters & Setters....
}
我创造了
Repository
@Repository
public interface TicketRepository extends JpaRepository<Ticket, Long> {
}
@RestController
public class TicketController {
@Autowired
TicketRepository ticketRepository;
@GetMapping("/tickets")
public void saveTicketData() {
List<Ticket> tickets = null;
try {
tickets = getAllTickets(); //some utility method
ticketRepository.save(tickets); // here exception occurs
} catch (Exception e) {
e.printStackTrace();
}
}
不知道这里出了什么问题。在SQLServer中保存对象列表的方法和在MySQl中不同吗?这对于MySQL或者我切换到Mongo非常有用。
任何帮助都将不胜感激。