Announcement Announcement Module
Collapse
No announcement yet.
Spring data jpa and problem with @LastModifiedDate annotation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring data jpa and problem with @LastModifiedDate annotation

    Hi,
    i created a very small test application to get involved in the spring data package. I create a very small app with Spring,JPA and hibernate. I used the spring JpaRepository for the database operations and it worked very well. Now i just played around with the annotation in the data package. The @version annotation worked very well, but the @LastModifiedDate or @CreatedDate does not work.

    Here are my database Entities:
    Code:
    @MappedSuperclass
    public class BaseEntity implements Serializable {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    
    	@Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        protected Integer id;
    
    	@Version
    	private Integer version;
    	
    	@LastModifiedDate
    	private DateTime lastModifiedDate;
    	
    	@CreatedDate
    	private DateTime createdDate;
    /* getters and setter 
    all Date values are joda DateTime
    /*
    Code:
    @Entity
    public class FirstEntity extends BaseEntity {
    	
    	private static final long serialVersionUID = 1L;
    	
    	@Column
    	@NotEmpty
    	String name;
    /* getters and setter */
    After persisting the object, the DateTime values are null. Is there somting special i have to configure to get it running?

    I am very new in this business, so please let me know if you need more informations about it.

  • #2
    Hi,
    i still have this problem. I try to get more informations about it, but only get database informations. It is possible to set these values in the database and then the null value send to the database from spring will be correct. But if you want to use this feature, the database table must be created correct. So, this could be fixed by two different ways.

    Create the database in a different way, to set these values while commit. Or add these values and send them to the database.

    In my current way, spring will create the database and handle all details. It would be great if someone use this feature and know which is the correct way for doing it.

    THX

    Comment


    • #3
      There are several more steps you have to configure. Please check the tutorials and documentation. F.e. entity listener and AuditorAware bean.

      The @Version annotation is processed by JPA/Hibernate, not Spring Data JPA. It works because there is no further configuration necessary.

      Comment


      • #4
        Thank you very much. I will read the documentation again and try to find a solution.

        THX

        Comment

        Working...
        X