• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

How to insert todays date into Database using Entity

 
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am trying to understand @Temporal annotation,for this i just written an entity class like below:



How do i implement the setter method to insert today's date everytime entity is persisted.

Regards
Sudhakar
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved.

Regards
Sudhakae
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope you used @PrePersist. I think that is best way.

It would be a help to others who are looking the answers for the same problem if you post your method you came across than just saying "Problem solved".
And other hand there maybe better method than you used. So others may help you in that case.

Do something for community as well.

Thanks
 
Karnati Sudhakar
Ranch Hand
Posts: 270
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

It would be a help to others who are looking the answers for the same problem if you post your method you came across than just saying "Problem solved".



I thought the problem i faced is very silly and i was able to solve it after some googling.

I did not modify the entity,I just changed the session bean code:



With the above code i was able to test all the elements of Temporal annotation(DATE,TIME,TIMESTAMP)..

I dont know if this is useful to anybody

Regards
Sudhakar
 
Chaminda Amarasinghe
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Karnati,

Your method will work if the client (of ejb or ejb itself) set creation date purposely. But it does not guaranteed.

So the better way is make the setCretaedDate private that ensure no one can set it, and set it in PrePersist. It is more accurate.

Thanks
 
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic