Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8121731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:35:29+00:00 2026-06-06T05:35:29+00:00

I’m doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate

  • 0

I’m doing a Web application using Spring 3.1.0.RELEASE, JSF 2.x, JPA 2 with Hibernate Provider, MySql 5.1.x. The application runs on Tomcat 7.X.

In my entities I have some date like last update date:

@Column(name = "last_update_date", insertable = false, updatable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date lastUpdateDate;

For the moment I have a trigger that updates:

CREATE TRIGGER upd_site BEFORE UPDATE ON site
FOR EACH ROW SET NEW.last_update_date = CURRENT_TIMESTAMP();

It works fine, but I just notice that there is some callbacks methods in JPA http://www.objectdb.com/java/jpa/persistence/event

What is the best between JPA Events and the MySql’s triggers ?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T05:35:32+00:00Added an answer on June 6, 2026 at 5:35 am

    I have used it both ways with Triggers in the DB and with JPA listeners, I have settled on the JPA listeners because:

    • the only code talking to the database in JPA code so I don’t have to worry about the time stamp fields falling out of date. (If this changes in the future I can add triggers and change my mapped super calss)

    • JPA listeners are less complex in the sense that I did not have to go creating lots of triggers in my database so I had less things to maintain. Since I am actively developing and changing the db structure as I go along its great not to have to go and update triggers as I rapidly iterate through the development.

    • I have complete control over the database and made a rule for the db that every table was going to have a integer pkey, and an integer version, and that the time stamped tables would have insert_ts and update_ts columns these are universal rules in my db design so life is easy I have these two mapped superclases that make all my enitites simple to code since I extend from them.

    @MappedSuperclass
    public abstract class PersistableObject {
    
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name="pkey")
        private Integer pkey;
    
        @Version
        @Column(name="version")
        private Integer version;
    
        public Integer getPkey() {
            return this.pkey;
        }
    
        public Integer getVersion() {
            return this.version;
        }
    
        @Override
        public String toString() {
            return "Presistable Object: pkey=" + this.pkey + " Object: " + this.getClass().getName();
        }
    }
    

    and

    @MappedSuperclass
    public class TimeStampedPersistableObject extends PersistableObject {
    
        @Column(name = "insert_ts")
        @Temporal(TemporalType.TIMESTAMP)
        private Date    insertTimestamp;
    
        @Column(name = "update_ts")
        @Temporal(TemporalType.TIMESTAMP)
        private Date    updateTimestamp;
    
        @SuppressWarnings("unused")
        @PrePersist
        private void onInsert() {
            this.insertTimestamp = new Date();
            this.updateTimestamp = this.insertTimestamp;
        }
    
        @SuppressWarnings("unused")
        @PreUpdate
        private void onUpdate() {
            this.updateTimestamp = new Date();
        }
    
    
        public Date getInsertTimestamp() {
            return this.insertTimestamp;
        }
    
    
        public Date getUpdateTimestamp() {
            return this.updateTimestamp;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.