chukinn
chukinn

Reputation: 5

Records timestamp

I'd like to add a Date/DateTime/Timestamp field on an entity object, that will be automatically created when the entity is created and set to "now". Same goes when the entity is updated.

Any one could help me?

Upvotes: 0

Views: 313

Answers (2)

Kox
Kox

Reputation: 98

You can do it by using just java Timestamp in your model class

public Timestamp setlogTime() {
    time = new Timestamp(System.currentTimeMillis());
    return time;
}

and everywhere you want to use this just add (for example in controllers Result function)

 object.setlogTime();

Also you have to make new tables to save it in database

For example in models class add

@Constraints.Required
public Timestamp time;

I'm novice at playframework there are automatic functions too but i used this method and this is doing job :P

Upvotes: 0

Felix Novovic
Felix Novovic

Reputation: 625

This question has been asked before, have a look here: How to create an auto-generated Date/timestamp field in a Play! / JPA?

Essentially you want to create a superclass that automatically handles the create and update fields.

This might also be interesting: http://www.avaje.org/static/javadoc/pub/com/avaje/ebean/annotation/CreatedTimestamp.html

Upvotes: 1

Related Questions