-2

I am trying to do a simple insertion into my database using Spring boot. When I run my program, I get the error 'could not extract ResultSet'. But I am not looking to extract anything out, I am just purely inserting.

This is my model code:

import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Table;

@Entity(name = "calendar")
@Table(name = "TB_EVENT")
public class Calendar {

@Id
@GeneratedValue
@JoinColumn(name = "EventID")
private int eventId;

@JoinColumn(name = "Privacy")
private String privacy;

@JoinColumn(name = "EventCode")
private String eventCode;

@JoinColumn(name = "Subject")
private String subject;

@JoinColumn(name = "Location")
private String location;

My service implementation class:

@Override
public void add(Calendar calendar) {
    // TODO Auto-generated method stub
    logger.info("invoked insertevent function in calendarServiceImpl");

    logger.info(calendar.getPrivacy());
    logger.info(calendar.getAllDay());
    logger.info(calendar.getEventCode());
    logger.info(calendar.getSubject());
    logger.info(calendar.getReminder());
    logger.info(calendar.getLocation());
    logger.info(calendar.getStartTime());
    logger.info(calendar.getEndTime());
    logger.info(calendar.getRecur());
    logger.info(calendar.getRemarks());


    calendarRepository.save(calendar);


}

I am using the .save() and in my database I have set the id to be auto incremental. Anybody know what went wrong?

Thanks guys, I managed to solve the problem by adding @GeneratedValue(strategy = GenerationType.IDENTITY)

purplewind
  • 331
  • 10
  • 26

3 Answers3

0

Try to change annotations above fields to @Column.

Tom
  • 224
  • 3
  • 9
0

@JoinColumn is used to indicate the relationship and ownership of the relationship. I guess what you need is @Column annotation. So replace all @JoinColumn's with @Column would fix the problem.

To see what @JoinColumn does please refer

Damith
  • 740
  • 4
  • 12
  • tried, but still getting the same error. I don't think that is causing the problem. – purplewind Sep 21 '18 at 07:25
  • please post the whole stacktrace and consider droping schema and creating it again and running the application. because if its not, changes may not apply according to your table creation strategy. – Damith Sep 21 '18 at 08:46
0

Using @JoinColumn instead of @Column is first issue that anyone can see from sky high. Please change it to @Column as Hibernate docs suggest. Putting @JoinColumn does not map your field to database in any situation whatsoever. Also "could not extract ResultSet" is not helpful at all you should have posted your stacktrace instead of only few words.

zawarudo
  • 1,907
  • 2
  • 10
  • 20