[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-46) PrePersist callback method not called if entity's primary key is null

payne (JIRA) noreply at atlassian.com
Thu Sep 25 01:00:06 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-46?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=31281#action_31281 ] 

payne commented on EJB-46:
--------------------------

http://www.tamilstar.info/forums/index.php?showtopic=158648
http://www.tamilstar.info/forums/index.php?showtopic=158646
http://www.tamilstar.info/forums/index.php?showtopic=158643
http://www.tamilstar.info/forums/index.php?showtopic=158640
http://www.tamilstar.info/forums/index.php?showtopic=158638
http://www.tamilstar.info/forums/index.php?showtopic=158636
http://www.tamilstar.info/forums/index.php?showtopic=158632
http://www.tamilstar.info/forums/index.php?showtopic=158631
http://www.tamilstar.info/forums/index.php?showtopic=158628
http://www.tamilstar.info/forums/index.php?showtopic=158625
http://www.tamilstar.info/forums/index.php?showtopic=158621
http://www.tamilstar.info/forums/index.php?showtopic=158619
http://www.tamilstar.info/forums/index.php?showtopic=158616
http://www.tamilstar.info/forums/index.php?showtopic=158613
http://www.tamilstar.info/forums/index.php?showtopic=158612
http://www.tamilstar.info/forums/index.php?showtopic=158608
http://www.tamilstar.info/forums/index.php?showtopic=158607
http://www.tamilstar.info/forums/index.php?showtopic=158604
http://www.tamilstar.info/forums/index.php?showtopic=158601
http://www.tamilstar.info/forums/index.php?showtopic=158598
http://www.tamilstar.info/forums/index.php?showtopic=158595
http://www.tamilstar.info/forums/index.php?showtopic=158592
http://www.tamilstar.info/forums/index.php?showtopic=158590
http://www.tamilstar.info/forums/index.php?showtopic=158588
http://www.tamilstar.info/forums/index.php?showtopic=158584
http://www.tamilstar.info/forums/index.php?showtopic=158580
http://www.tamilstar.info/forums/index.php?showtopic=158575
http://www.tamilstar.info/forums/index.php?showtopic=158573
http://www.tamilstar.info/forums/index.php?showtopic=158570
http://www.tamilstar.info/forums/index.php?showtopic=158430
http://www.tamilstar.info/forums/index.php?showtopic=158426
http://www.tamilstar.info/forums/index.php?showtopic=158422
http://www.tamilstar.info/forums/index.php?showtopic=158419
http://www.tamilstar.info/forums/index.php?showtopic=158415
http://www.tamilstar.info/forums/index.php?showtopic=158412
http://www.tamilstar.info/forums/index.php?showtopic=158407
http://www.tamilstar.info/forums/index.php?showtopic=158405
http://www.tamilstar.info/forums/index.php?showtopic=158405
http://www.tamilstar.info/forums/index.php?showtopic=158402
http://www.tamilstar.info/forums/index.php?showtopic=158399
http://www.tamilstar.info/forums/index.php?showtopic=158397
http://www.tamilstar.info/forums/index.php?showtopic=158394
http://www.tamilstar.info/forums/index.php?showtopic=158391
http://www.tamilstar.info/forums/index.php?showtopic=158390
http://www.tamilstar.info/forums/index.php?showtopic=158386
http://www.tamilstar.info/forums/index.php?showtopic=158382
http://www.tamilstar.info/forums/index.php?showtopic=158378
http://www.tamilstar.info/forums/index.php?showtopic=158367
http://www.tamilstar.info/forums/index.php?showtopic=158356
http://www.tamilstar.info/forums/index.php?showtopic=158348
http://www.tamilstar.info/forums/index.php?showtopic=158330
http://www.tamilstar.info/forums/index.php?showtopic=158303
http://www.tamilstar.info/forums/index.php?showtopic=158289
http://www.tamilstar.info/forums/index.php?showtopic=158273
http://www.tamilstar.info/forums/index.php?showtopic=158210
http://www.tamilstar.info/forums/index.php?showtopic=157908
http://www.tamilstar.info/forums/index.php?showtopic=157905
http://www.tamilstar.info/forums/index.php?showtopic=157903
http://www.tamilstar.info/forums/index.php?showtopic=157902
http://www.tamilstar.info/forums/index.php?showtopic=157899
http://www.tamilstar.info/forums/index.php?showtopic=157896
http://www.tamilstar.info/forums/index.php?showtopic=157894
http://www.tamilstar.info/forums/index.php?showtopic=157889
http://www.tamilstar.info/forums/index.php?showtopic=157886
http://www.tamilstar.info/forums/index.php?showtopic=157883
http://www.tamilstar.info/forums/index.php?showtopic=157881
http://www.tamilstar.info/forums/index.php?showtopic=157878
http://www.tamilstar.info/forums/index.php?showtopic=157875
http://www.tamilstar.info/forums/index.php?showtopic=157872
http://www.tamilstar.info/forums/index.php?showtopic=157871
http://www.tamilstar.info/forums/index.php?showtopic=157868
http://www.tamilstar.info/forums/index.php?showtopic=157864
http://www.tamilstar.info/forums/index.php?showtopic=157863
http://www.tamilstar.info/forums/index.php?showtopic=157859
http://www.tamilstar.info/forums/index.php?showtopic=157710
http://www.tamilstar.info/forums/index.php?showtopic=157708
http://www.tamilstar.info/forums/index.php?showtopic=157683
http://www.tamilstar.info/forums/index.php?showtopic=157680
http://www.tamilstar.info/forums/index.php?showtopic=157673
http://www.tamilstar.info/forums/index.php?showtopic=157671
http://www.tamilstar.info/forums/index.php?showtopic=157668
http://www.tamilstar.info/forums/index.php?showtopic=157660
http://www.tamilstar.info/forums/index.php?showtopic=157643
http://www.tamilstar.info/forums/index.php?showtopic=157628
http://www.tamilstar.info/forums/index.php?showtopic=157616
http://www.tamilstar.info/forums/index.php?showtopic=157601
http://www.tamilstar.info/forums/index.php?showtopic=157569
http://www.tamilstar.info/forums/index.php?showtopic=157546
http://www.tamilstar.info/forums/index.php?showtopic=157540
http://www.tamilstar.info/forums/index.php?showtopic=157531
http://www.tamilstar.info/forums/index.php?showtopic=157490
http://www.tamilstar.info/forums/index.php?showtopic=157079
http://www.tamilstar.info/forums/index.php?showtopic=157076
http://www.tamilstar.info/forums/index.php?showtopic=157073
http://www.tamilstar.info/forums/index.php?showtopic=157069
http://www.tamilstar.info/forums/index.php?showtopic=157065
http://www.tamilstar.info/forums/index.php?showtopic=157063
http://www.tamilstar.info/forums/index.php?showtopic=157063
http://www.tamilstar.info/forums/index.php?showtopic=157059
http://www.tamilstar.info/forums/index.php?showtopic=157056

>  PrePersist callback method not called if entity's primary key is null
> ----------------------------------------------------------------------
>
>                 Key: EJB-46
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-46
>             Project: Hibernate Entity Manager
>          Issue Type: Bug
>          Components: EntityManager
>    Affects Versions: 3.1beta1, 3.1beta2
>         Environment: MySQL4, Sun JRE5, WinXP
>            Reporter: Johan Steiner
>            Assignee: Emmanuel Bernard
>             Fix For: 3.3.0.ga
>
>         Attachments: EJB3EventListener.patch, EJB3EventListener_v2.patch
>
>
> Hi,
> the description is from http://forum.hibernate.org/viewtopic.php?t=944964 but I'm experiencing the exact same issue.
> *********************
> Hibernate does property validation such as not null checking before it does the EJB3 callback to prepersist/preupdate. I'm not sure if there's a good reason for this, but I think it would be particularly convenient if this behavior was reversed. IMHO it seems to better fit the semantics of the PRE callbacks, and it would allow callbacks to make modifications to the objects before they are persisted or updated -- modifications that might in turn effect the property validation Hibernate is doing.
> The "audit" example in the entity manager documentation does make changes to the object. What if these changes had effected the property validation done before the callback occurred? What if the object was in an invalid state before the callback, but a valid state after the callback? The latter case is what I think would be conveniently handled if hibernate did its property validation after prepersist/preupdate.
> Just two cents worth, obviously there are workarounds. This EJB3 stuff is looking great.
> Ryan
> P.S. This might also allow those of us who assign our own IDs to objects to do so automatically within a callback.
> *********************
> In my case I'm working with an entity like:
> public class MyEntity
> {
> 	@Basic(temporalType = TemporalType.TIMESTAMP)
> 	@Column(name = "$createdOn", insertable = true, updatable = false, nullable = false)
> 	private Date firstPersistedOn = null;
> 	@Basic(temporalType = TemporalType.TIMESTAMP)
> 	@Column(name = "$modifiedOn", insertable = true, updatable = false, nullable = true)
> 	private Date lastPersistedOn = null;
> 	@PrePersist
> 	public void onPrePersist()
> 	{
> 		firstPersistedOn = new Date();
> 	}
> 	@PreUpdate
> 	public void onPreUpdate()
> 	{
> 		lastPersistedOn = new Date();
> 	}
> }
> Hibernate throws:
> org.hibernate.PropertyValueException: not-null property references a null or transient value: MyEntity.firstPersistedOn
> 	at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
> 	at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:262)
> 	at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:164)
> 	at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
> 	at org.hibernate.event.def.DefaultMergeEventListener.entityIsTransient(DefaultMergeEventListener.java:167)
> 	at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:113)
> 	at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:60)
> 	at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:540)
> 	at org.hibernate.ejb.AbstractEntityManagerImpl.merge(AbstractEntityManagerImpl.java:139)
> Regards,
> Johan

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list