Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RevisionMetadata cannot handle RevisionTimestamp in TIMESTAMP format #135

Closed
stefanzilske opened this issue Aug 30, 2018 · 9 comments
Closed

Comments

@stefanzilske
Copy link

Hi folks,

I started using Hibernate Envers natively and created my own RevisonInfo and REVINFO table. I used TIMESTAMP as data type for the RevisionTimestamp and mapped it to java.util.Date, which is fine for Hibernate.

Now we are starting to use spring-data-envers and run into the following issue:

RevisionMetadata expects the RevisionTimestamp to be either an Instant, LocalDateTime Long, while Hibernate supports only Long, java.util.Date or java.sql.Date.

I could switch to long, but I would prefer to keep a readable format in the database.

Is there any way out of this? I wonder why spring-data-envers, which wraps Hibernate Envers, is supporting different types.

Cheers,
Stefan

@odrotbohm
Copy link
Member

odrotbohm commented Aug 30, 2018

If you map it to a java.util.Date, shouldn't you be able to adapt it to an Instant? Are you able to provide a sample project to clarify what is not working?

@odrotbohm
Copy link
Member

Oh, wait. Now I get you. I guess the relevant parts are missing in Spring Data Commons' AnnotationRevisionMetadata.convertToInstant(…). I wouldn't mind to see a PR that adds the necessary if-clause to convert from Date or Timestamp right away. However, we'd have to track this in Spring Data Commons.

@odrotbohm
Copy link
Member

odrotbohm commented Aug 31, 2018

I've filed DATACMNS-1384. Looks pretty straight forward, I'll get right to it.

@odrotbohm
Copy link
Member

That's fixed for Lovelace and Kay. Would you mind trying the latest snapshots?

@stefanzilske
Copy link
Author

Definitely! Thanks for the quick reaction. I was just about forking the repo when you confirmed it's already done.

I will come back at you, as soon as I tried it.

@stefanzilske
Copy link
Author

@olivergierke we have tried the latest snapshots and it works fine. Thank you for the quick reaction!

@odrotbohm
Copy link
Member

Awesome, thanks for confirming.

@arvera
Copy link

arvera commented Jun 13, 2024

Is there documetation that explains how to achieve the transformation?

@arvera
Copy link

arvera commented Jun 13, 2024

Is there documetation that explains how to achieve the transformation?

Well I figure it out and it might worth to add it to some documentation. This is what I did for Derby:

My class looks like:

public class MyRevisionInfo implements Serializable{
...	
   @RevisionTimestamp
   @Column (name="REVTSTMP")
   private Instant timestamp;
...
   @Transient
   public Date getRevisionDate() {
		 return new Date(timestamp.toEpochMilli());
   }
   
   public Instant getTimestamp() {
        return timestamp;
   }

   public void setTimestamp(Instant timestamp) {
        this.timestamp = timestamp;
   }

and my ddl looks like:

     create table REVINFO (
       REVISION bigint generated by default as identity,
       REVTSTMP timestamp,
       USERNAME varchar(255),
       primary key (REVISION)
   );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants