I am trying to save a list of object in a sql-server database in my Spring Boot application but getting exception when I call the save method.
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'. Below is the configuration am using:
#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 And the Model looks like:
@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.... } I have created the Repository class:
@Repository public interface TicketRepository extends JpaRepository<Ticket, Long> { } and finally, the controller:
@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(); } } Not sure what is wrong here. Is there a different way to save list of objects in SQL server than in MySQl? This works great with MySQL or if I switch to Mongo.
Any help would be appreciated.
schema, while mysql doesn't. It might not be directly applicable here but if you usenativeQuery, ensure table name in query is of typedbName.schemaName.tableName.