openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel Halbert <>
Subject Does PrePersist work when merging entities? (2.0.1)
Date Wed, 09 Feb 2011 15:06:41 GMT
Hi Folks,

Are there any known issues around using  @PrePersist on merge with
My Entities use Property access.

@PostLoad method is always called when loading entities.
@PrePersist is called on persist, but never on merge.

I'm tried using both runtime (agent) and compile time enhancement.

Here's a sample Entity that I used for testing this.

import javax.persistence.*;

public class Test {

	private int id;
	private String name;
	@GeneratedValue(strategy = GenerationType.IDENTITY)	
	public int getId() {
		return id;
	public void setId(int id) { = id;
	public String getName() {
		return name;
	public void setName(String name) { = name;
	void populateDBFields(){
		System.out.println("Hello, I happen prePersist!");

	void populateTransientFields(){
		System.out.println("Hello, I happen postLoad!");
	public static void main(String[] args) throws Exception {
		EntityManagerFactory factory = Persistence.createEntityManagerFactory(
				"su3", null);
		EntityManager em = factory.createEntityManager();

		// Test t = new Test();
		// t.setName("name");
		// em.persist(t);

		Test t = em.find(Test.class, 1);
		t.setName("new name");



Any clues?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message