0

I have a very simple Spring Boot application deployed on Heroku. The application itself works fine in terms of the Controller - the API returns some simple JSON, nothing too special.

I've added a Postgres database to Heroku and on application startup I see that Spring creates the table as expected. It is only 1 table with a super simple mapping class:

@Entity
public class Score implements Serializable {
private static final long serialVersionUID = -2899157432342241888L;

private String customer;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;

private Date date = new Date();

private int score;

//setters and getters

The repository is just an interface with no explicit implementation:

@Repository
public interface ScoreRepository extends CrudRepository<Score, Long>

I call repository.save(...) in a @Service annotated class that has the repository auto-wired in. I assume that is working ok, because I'm not seeing any errors - yet I don't see any records being persisted to the database! No idea what could be going wrong here; I suppose I could have set up Heroku wrong, or maybe there's something obvious that I missed with the Postgres setup in Heroku?

Secondary question

Maybe related, but logging doesn't seem to work too well either. According to Heroku documentation I can print to standard out and it should appear in the log, but this doesn't happen. Moreover I have this in properties file:

spring.jpa.show-sql=true

But I see no such logging of SQL queries in the heroku logs.

Any help much appreciated! Thanks in advance.

2 Answers 2

1

Logging issue: when you start your application, do you see any errors in console (first few lines even before spring logo) saying multiple version of logging jar (slf4j.jar) , if so you may not see logs. If this is true, then check your maven depencies and exclude all unncessary slf4j.jar

and start your spring application with debug.

java -jar myapp.jar --debug

persistence issue: Make sure you run it in transaction (in spring context)

After you solve your logging issue you can figure this out i believe, But you can debug your code and see if request reaches your save method, and then you can step into to find if there is any issue, But i would definitely see logs to find errors if any.

Sign up to request clarification or add additional context in comments.

Comments

0

I don't see a setter. Do you even have it as all I see is comment // Getter and setter

1 Comment

Yes they are there I omitted them here hence the comment

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.