[Hibernate-JIRA] Updated: (EJB-46) Property Validation should happen after PrePersist/PreUpdate
by Mark Menard (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-46?page=all ]
Mark Menard updated EJB-46:
---------------------------
Attachment: EJB3EventListener_v2.patch
This is an updated version of Michal's patch. This is done against hibernate-eventmanager-3.2.2.CR2.
> Property Validation should happen after PrePersist/PreUpdate
> ------------------------------------------------------------
>
> Key: EJB-46
> URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-46
> Project: Hibernate Entity Manager
> Type: Bug
> Components: EntityManager
> Versions: 3.1beta2, 3.1beta1
> Environment: MySQL4, Sun JRE5, WinXP
> Reporter: Johan Steiner
> 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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months
RE: Query.list() returns one item (as expected) but that item is null (which is unexpected)
by Mehdi.Rakhshani@gxs.com
I have a simple query that when I execute in sqlplus returns one record
as expected. When I run the same query using hibernate and java, I get a
list back which has one record, but that record is null.
I wrote the same search using Criteria and hibernate complains that the
column name cannot be resolved. Whether I use the "name" attribute or
the "column" attribute of the property it makes no difference.
Hibernate 3.1: 1,971,632 hibernate3.jar, Windows XP, Oracle DB
HBM snippet:
<hibernate-mapping package="com.gxs.iefe.alias">
<class
name="AliasTable"
table="IEFE.ALIAS_TABLE"
>
<meta attribute="sync-DAO">false</meta>
<composite-id name="id" class="AliasTablePK">
<key-property
name="owningSystem"
column="OWNING_SYSTEM"
type="string"
/>
<key-property
...
Code snippet using query:
q = theSession.createQuery(
"from AliasTable where OWNING_SYSTEM = :sys and
OWNING_ACCOUNT is null and OWNING_USER_ID is null and TABLE_NAME = :tbl"
);
q.setString( "sys", theOwner.getSystem() );
q.setString( "tbl", theTable );
// Using q.uniqueResult() produces the same behavior
List anAliasTableList = q.list();
if ( null == anAliasTableList || 0 ==
anAliasTableList.size() )
throw new Exception( "Null list" );
// Code that verifies list size has been removed. "Null list
element" is thrown.
anAliasTable = (AliasTable)anAliasTableList.get( 0 );
if ( null == anAliasTable )
throw new Exception( "Null list element" );
Code snippet using criteria:
Criteria aCriteria = theSession.createCriteria(
AliasTable.class );
// Specifying neither property name nor property
column works: could not resolve property: owningSystem of:
com.gxs.iefe.alias.AliasTable
//aCriteria.add( Restrictions.eq( "OWNING_SYSTEM",
theOwner.getSystem() ) );
aCriteria.add( Restrictions.eq( "owningSystem",
theOwner.getSystem() ) );
aCriteria.add( Restrictions.isNull( "owningAccount" ) );
aCriteria.add( Restrictions.isNull( "owningUserId" ) );
aCriteria.add( Restrictions.eq( "tableName", theTable ) );
// Retrieve the data
List anAliasTableList = aCriteria.list();
Any idea why?
18 years, 3 months
[Hibernate-JIRA] Commented: (HHH-1293) java.lang.NoSuchMethodError: <persistent class>.getHibernateLazyInitializer()
by Max Rydahl Andersen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1293?page=c... ]
Max Rydahl Andersen commented on HHH-1293:
------------------------------------------
on the latest release ?!
> java.lang.NoSuchMethodError: <persistent class>.getHibernateLazyInitializer()
> -----------------------------------------------------------------------------
>
> Key: HHH-1293
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1293
> Project: Hibernate3
> Type: Bug
> Versions: 3.1.1
> Reporter: Andreas Schildbach
> Assignee: Scott Marlow
> Priority: Blocker
> Fix For: 3.2.0.cr4
> Attachments: CGLIBLazyInitializer.patch, CGLIBLazyInitializer.patch, CGLIBLazyInitializer.patch3, CGLIBLazyInitializer.patch4, CGLIBProxyFactory.patch3, hibernate3.jar, manysessions.tgz, patch.CGLIBLazyInitializer.java
>
>
> As documented in
> http://forum.hibernate.org/viewtopic.php?t=940119
> some people (including me) are getting this exception with the final release of Hibernate 3.1:
> java.lang.NoSuchMethodError: de.schildbach.game.integration.HibernateGamePlayer.getHibernateLazyInitializer()Lorg/hibernate/proxy/LazyInitializer;
> at de.schildbach.game.integration.HibernateGamePlayer$$EnhancerByCGLIB$$afecb986.getHibernateLazyInitializer(<generated>)
> at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:274)
> at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
> at org.hibernate.type.TypeFactory.assemble(TypeFactory.java:398)
> at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:96)
> at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:82)
> at org.hibernate.event.def.DefaultLoadEventListener.assembleCacheEntry(DefaultLoadEventListener.java:520)
> at org.hibernate.event.def.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:474)
> at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:328)
> at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
> at org.hibernate.event.def.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:202)
> at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:169)
> at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
> at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
> at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:838)
> at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
> at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
> at org.hibernate.collection.PersistentList.initializeFromCache(PersistentList.java:378)
> at org.hibernate.cache.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:35)
> at org.hibernate.event.def.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:130)
> at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:48)
> at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1627)
> at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
> at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
> at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
> at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
> The exception varies with the actual persistent class in use. Most people seem to be using JDK 1.5 and Linux. Some reports say that the exception does not happen from the very start of the application, but it takes "several invocations"/"some time" until it appear, but then it appears very often.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months
[Hibernate-JIRA] Commented: (HHH-1293) java.lang.NoSuchMethodError: <persistent class>.getHibernateLazyInitializer()
by C Wilks (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1293?page=c... ]
C Wilks commented on HHH-1293:
------------------------------
Also occurred for us in Solaris 10.
> java.lang.NoSuchMethodError: <persistent class>.getHibernateLazyInitializer()
> -----------------------------------------------------------------------------
>
> Key: HHH-1293
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1293
> Project: Hibernate3
> Type: Bug
> Versions: 3.1.1
> Reporter: Andreas Schildbach
> Assignee: Scott Marlow
> Priority: Blocker
> Fix For: 3.2.0.cr4
> Attachments: CGLIBLazyInitializer.patch, CGLIBLazyInitializer.patch, CGLIBLazyInitializer.patch3, CGLIBLazyInitializer.patch4, CGLIBProxyFactory.patch3, hibernate3.jar, manysessions.tgz, patch.CGLIBLazyInitializer.java
>
>
> As documented in
> http://forum.hibernate.org/viewtopic.php?t=940119
> some people (including me) are getting this exception with the final release of Hibernate 3.1:
> java.lang.NoSuchMethodError: de.schildbach.game.integration.HibernateGamePlayer.getHibernateLazyInitializer()Lorg/hibernate/proxy/LazyInitializer;
> at de.schildbach.game.integration.HibernateGamePlayer$$EnhancerByCGLIB$$afecb986.getHibernateLazyInitializer(<generated>)
> at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:274)
> at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
> at org.hibernate.type.TypeFactory.assemble(TypeFactory.java:398)
> at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:96)
> at org.hibernate.cache.entry.CacheEntry.assemble(CacheEntry.java:82)
> at org.hibernate.event.def.DefaultLoadEventListener.assembleCacheEntry(DefaultLoadEventListener.java:520)
> at org.hibernate.event.def.DefaultLoadEventListener.loadFromSecondLevelCache(DefaultLoadEventListener.java:474)
> at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:328)
> at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
> at org.hibernate.event.def.DefaultLoadEventListener.returnNarrowedProxy(DefaultLoadEventListener.java:202)
> at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:169)
> at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
> at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:869)
> at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:838)
> at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
> at org.hibernate.type.ManyToOneType.assemble(ManyToOneType.java:177)
> at org.hibernate.collection.PersistentList.initializeFromCache(PersistentList.java:378)
> at org.hibernate.cache.entry.CollectionCacheEntry.assemble(CollectionCacheEntry.java:35)
> at org.hibernate.event.def.DefaultInitializeCollectionEventListener.initializeCollectionFromCache(DefaultInitializeCollectionEventListener.java:130)
> at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:48)
> at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1627)
> at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:344)
> at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:86)
> at org.hibernate.collection.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:109)
> at org.hibernate.collection.PersistentList.size(PersistentList.java:91)
> The exception varies with the actual persistent class in use. Most people seem to be using JDK 1.5 and Linux. Some reports say that the exception does not happen from the very start of the application, but it takes "several invocations"/"some time" until it appear, but then it appears very often.
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
18 years, 3 months