Spring Data JPA with SQL Server giving error: Invalid object name 'Table_Name'












0















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.










share|improve this question

























  • Can you also show your utility method.

    – Pooja Aggarwal
    Nov 26 '18 at 7:00











  • erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

    – 薛源少
    Nov 26 '18 at 7:21











  • edited the db name. That's exactly what I have created in SQl server

    – roger_that
    Nov 26 '18 at 7:26











  • @PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

    – roger_that
    Nov 26 '18 at 7:27
















0















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.










share|improve this question

























  • Can you also show your utility method.

    – Pooja Aggarwal
    Nov 26 '18 at 7:00











  • erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

    – 薛源少
    Nov 26 '18 at 7:21











  • edited the db name. That's exactly what I have created in SQl server

    – roger_that
    Nov 26 '18 at 7:26











  • @PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

    – roger_that
    Nov 26 '18 at 7:27














0












0








0








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.










share|improve this question
















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.







java sql-server hibernate spring-boot spring-data-jpa






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 7:25







roger_that

















asked Nov 26 '18 at 6:34









roger_thatroger_that

5,102103570




5,102103570













  • Can you also show your utility method.

    – Pooja Aggarwal
    Nov 26 '18 at 7:00











  • erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

    – 薛源少
    Nov 26 '18 at 7:21











  • edited the db name. That's exactly what I have created in SQl server

    – roger_that
    Nov 26 '18 at 7:26











  • @PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

    – roger_that
    Nov 26 '18 at 7:27



















  • Can you also show your utility method.

    – Pooja Aggarwal
    Nov 26 '18 at 7:00











  • erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

    – 薛源少
    Nov 26 '18 at 7:21











  • edited the db name. That's exactly what I have created in SQl server

    – roger_that
    Nov 26 '18 at 7:26











  • @PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

    – roger_that
    Nov 26 '18 at 7:27

















Can you also show your utility method.

– Pooja Aggarwal
Nov 26 '18 at 7:00





Can you also show your utility method.

– Pooja Aggarwal
Nov 26 '18 at 7:00













erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

– 薛源少
Nov 26 '18 at 7:21





erm, can screenshot your database schema/table? just curious that whether you put the name as "db"...

– 薛源少
Nov 26 '18 at 7:21













edited the db name. That's exactly what I have created in SQl server

– roger_that
Nov 26 '18 at 7:26





edited the db name. That's exactly what I have created in SQl server

– roger_that
Nov 26 '18 at 7:26













@PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

– roger_that
Nov 26 '18 at 7:27





@PoojaAggarwal: Utility method is nothing but parses some JSON and created Ticket object, populates ticket fields and save it the a set and returns.

– roger_that
Nov 26 '18 at 7:27












2 Answers
2






active

oldest

votes


















0














Include one more annotation @Table(name = "Ticket") in Entity Class.



@Table(name = "Ticket")
@Entity(name = "Ticket")
public class Ticket {.....






share|improve this answer
























  • Already did that. No luck.

    – roger_that
    Nov 26 '18 at 7:38











  • What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

    – atul ranjan
    Nov 26 '18 at 7:38













  • It is hosted on windows. table name is ticket

    – roger_that
    Nov 26 '18 at 7:50



















0














Sqlserver is case sensitive so if the table name is TICKET it does not recognize "i" char in Ticket.
Can you check if the table name is TICKET or ticket. if it is TICKET then try this annotation.



@Table(name = "TICKET")
@Entity(name = "TICKET")





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475826%2fspring-data-jpa-with-sql-server-giving-error-invalid-object-name-table-name%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Include one more annotation @Table(name = "Ticket") in Entity Class.



    @Table(name = "Ticket")
    @Entity(name = "Ticket")
    public class Ticket {.....






    share|improve this answer
























    • Already did that. No luck.

      – roger_that
      Nov 26 '18 at 7:38











    • What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

      – atul ranjan
      Nov 26 '18 at 7:38













    • It is hosted on windows. table name is ticket

      – roger_that
      Nov 26 '18 at 7:50
















    0














    Include one more annotation @Table(name = "Ticket") in Entity Class.



    @Table(name = "Ticket")
    @Entity(name = "Ticket")
    public class Ticket {.....






    share|improve this answer
























    • Already did that. No luck.

      – roger_that
      Nov 26 '18 at 7:38











    • What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

      – atul ranjan
      Nov 26 '18 at 7:38













    • It is hosted on windows. table name is ticket

      – roger_that
      Nov 26 '18 at 7:50














    0












    0








    0







    Include one more annotation @Table(name = "Ticket") in Entity Class.



    @Table(name = "Ticket")
    @Entity(name = "Ticket")
    public class Ticket {.....






    share|improve this answer













    Include one more annotation @Table(name = "Ticket") in Entity Class.



    @Table(name = "Ticket")
    @Entity(name = "Ticket")
    public class Ticket {.....







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 26 '18 at 7:34









    atul ranjanatul ranjan

    15116




    15116













    • Already did that. No luck.

      – roger_that
      Nov 26 '18 at 7:38











    • What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

      – atul ranjan
      Nov 26 '18 at 7:38













    • It is hosted on windows. table name is ticket

      – roger_that
      Nov 26 '18 at 7:50



















    • Already did that. No luck.

      – roger_that
      Nov 26 '18 at 7:38











    • What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

      – atul ranjan
      Nov 26 '18 at 7:38













    • It is hosted on windows. table name is ticket

      – roger_that
      Nov 26 '18 at 7:50

















    Already did that. No luck.

    – roger_that
    Nov 26 '18 at 7:38





    Already did that. No luck.

    – roger_that
    Nov 26 '18 at 7:38













    What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

    – atul ranjan
    Nov 26 '18 at 7:38







    What is the table name in db? Depending upon OS the SQL Server table names may be case sensitive. So, please check the table name is small case ticket or Ticket. It must be ticket.

    – atul ranjan
    Nov 26 '18 at 7:38















    It is hosted on windows. table name is ticket

    – roger_that
    Nov 26 '18 at 7:50





    It is hosted on windows. table name is ticket

    – roger_that
    Nov 26 '18 at 7:50













    0














    Sqlserver is case sensitive so if the table name is TICKET it does not recognize "i" char in Ticket.
    Can you check if the table name is TICKET or ticket. if it is TICKET then try this annotation.



    @Table(name = "TICKET")
    @Entity(name = "TICKET")





    share|improve this answer




























      0














      Sqlserver is case sensitive so if the table name is TICKET it does not recognize "i" char in Ticket.
      Can you check if the table name is TICKET or ticket. if it is TICKET then try this annotation.



      @Table(name = "TICKET")
      @Entity(name = "TICKET")





      share|improve this answer


























        0












        0








        0







        Sqlserver is case sensitive so if the table name is TICKET it does not recognize "i" char in Ticket.
        Can you check if the table name is TICKET or ticket. if it is TICKET then try this annotation.



        @Table(name = "TICKET")
        @Entity(name = "TICKET")





        share|improve this answer













        Sqlserver is case sensitive so if the table name is TICKET it does not recognize "i" char in Ticket.
        Can you check if the table name is TICKET or ticket. if it is TICKET then try this annotation.



        @Table(name = "TICKET")
        @Entity(name = "TICKET")






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 8:23









        Serhat OzSerhat Oz

        35417




        35417






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53475826%2fspring-data-jpa-with-sql-server-giving-error-invalid-object-name-table-name%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Lallio

            Unable to find Lightning Node

            Futebolista