@CreatedDate annotation does not work with mysql
<p>I am new to spring and I am confused how @CreatedDate annotation works in an entity. </p>

<p>I did a google search and there were many solutions, but none of them worked for me except one. I am confused why? </p>

<p>This is what I tried first </p>

<pre><code>@Entity
@EntityListeners(AuditingEntityListener.class)
public class User implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private String name;

    @CreatedDate
    private Date created;

    public User(String name) {

        this.name = name;
    }

    public User() {
    }
</code></pre>

<p>It did not work. I got NULL for the value in <code>created</code> column. </p>

<p>Then I did this. </p>

<pre><code>@Entity
@EntityListeners(AuditingEntityListener.class)
public class User implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private String name;

    @CreatedDate
    private Date created = new Date();

    public User(String name) {

        this.name = name;
    }

    public User() {
    }
</code></pre>

<p>This actually stored the time stamp in the db. My question is most of the tutorials I followed suggested that I do not need <code>new Date()</code> to get the current time stamp. Looks like I do need that. Is there anything I am missing? </p>