2

I am beginning with spring data jpa and i have configured all spring app. in which my bootstrap class is

@SpringBootApplication
@ComponentScan("com.ticket.booking")
@EnableJpaRepositories("com.ticket.booking.dao")
@EntityScan("com.ticket.booking.entity")
public class TicketBookingManagementApplication {

public static void main(String[] args) {
    SpringApplication.run(TicketBookingManagementApplication.class, args);
}

}

my controller

 @RestController
 @RequestMapping(value="/api/ticket")
 public class TicketController {

@Autowired
private TicketService ticketService;



@GetMapping(value="/")
public String welcome(){
    return "Welcome to Ticket Booking Systems";
}

@PostMapping(value="/add")
public Ticket createTicket(@RequestBody Ticket ticket){
    return ticketService.createNewTicket(ticket);
}

@GetMapping(value="/get/{ticketId}")
public Ticket getTicket(@PathVariable ("ticketId") Integer ticketId){

    return ticketService.getTicketById(ticketId);
}

}

service and repository

 @Service
 public class TicketService {


@Autowired
private TicketDao ticketDao;


public Ticket createNewTicket(Ticket ticket) {
    // TODO Auto-generated method stub
    return ticketDao.save(ticket);
}


public Ticket getTicketById(Integer ticketId) {
    // TODO Auto-generated method stub
    return ticketDao.findOne(ticketId);
}


}


public interface TicketDao extends CrudRepository<Ticket, Integer>{}

in pom.xml i have added

   <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>

It uses mysql-connector-java-5.1.46.jar:5.1.46 and it maps req successfully but while running app i am getting error like

  java.sql.SQLException: Unknown system variable 'language' 

and exporting schema to database

5
  • Give your mysql version Commented Jul 23, 2018 at 2:49
  • mysql version 5.1.30 Commented Jul 23, 2018 at 2:50
  • can you provide the configuration detail for mysql Commented Jul 23, 2018 at 3:03
  • Provide your configuration properties in question Commented Jul 23, 2018 at 3:05
  • @Vishal Kawade check now Commented Jul 23, 2018 at 3:28

2 Answers 2

1

update your mysql-connector version. it will solve your problem.

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>

properties:

spring.datasource.url=jdbc:mysql://localhost/schema_name
spring.datasource.username=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
Sign up to request clarification or add additional context in comments.

Comments

0

I am posting this answer because somebody might get benefited from this.

In my case, I was working with Spring-boot so the dependency in pom.xml was

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

So spring boot was taking some default dependency version from Spring boot parent which was different from my System installed mysql-server version 5.1.22 so that was the reason behind that error.

So to resolve this error I overridden the version by specifying manually like below.

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.22</version>
</dependency>

and it worked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.