Prev: Eclipse 3.5.1: "Open Project" dialog pops up when I open a certain class in the Visual Editor
Next: Urgent Openings: 1.GIS Web Developer(.Net), 2.Business System Analyst, Austin, TX., 3.Maximo positions
From: stunaz on 1 Jul 2010 00:47 Hello, I want to tinitialize my objetc using the @PrePersist annotations. Lets say i have an Entiy user: @Entity @Table(name = "USERS") Public Class User { @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name = "ID", unique = true, nullable = false) private Integer id; @Column(name="DATE_UPDATED",nullable = false) @Temporal(TemporalType.DATE) @NotNull private Date dateCreated; @PrePersist public void beforeCreate(){ if (this.dateCreated == null) { this.dateCreated = new Date(); } } //getter and setter } Somehow, the method beforeCreate is never called when i do : session.saveOrUpdate(user) but only when i do session.persist(user) Can somebody tell me why and how to fix that? Thanks
From: Lew on 1 Jul 2010 07:17 stunaz wrote: > I want to tinitialize my objetc using the @PrePersist annotations. > Lets say i [sic] have an Entiy user: > > @Entity > @Table(name = "USERS") > Public Class User { That line won't compile. It's 'public class', not 'Public Class'. > @Id > @GeneratedValue(strategy=GenerationType.AUTO) > @Column(name = "ID", unique = true, nullable = false) > private Integer id; > > @Column(name="DATE_UPDATED",nullable = false) > @Temporal(TemporalType.DATE) > @NotNull > private Date dateCreated; > > @PrePersist > public void beforeCreate(){ > if (this.dateCreated == null) { > this.dateCreated = new Date(); > } > } > > //getter and setter > } > > Somehow, the method beforeCreate is never called when i [sic] do : > session.saveOrUpdate(user) > but only when i [sic] do session.persist(user) > > Can somebody tell me why and how to fix that? Perhaps you should use EntityManager instead of Session. You should use spaces (maximum four per indent level) rather than TABs in Usenet posts. -- Lew
From: stunaz on 1 Jul 2010 13:07 how to use EntityManager instead of Session?
From: Lew on 1 Jul 2010 16:32
stunaz wrote: > how to use EntityManager instead of Session? <http://download.oracle.com/docs/cd/E17477_01/javaee/5/tutorial/doc/> specifically <http://download.oracle.com/docs/cd/E17477_01/javaee/5/tutorial/doc/ bnbqw.html#bnbqy> <http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/ html/> -- Lew |