pupsnow / dphibernate

Automatically exported from code.google.com/p/dphibernate
0 stars 0 forks source link

RC4 Long id problem with lazy load and entity.save() entity.deleteRecord() #58

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use BaseEntity with Long id type.
2. Try to lazy load or use entity.save() entity.deleteRecord()

What is the expected output? What do you see instead?
I expect to get the entities loaded instead I get errors.

What version of the product are you using? On what operating system?
OS Windows XP, I tried it both changemessagging with long fix by Dae and RC4

Please provide any additional information below.

I got RC4 to work with Long id types (but only for Long id types) as a 
temporary measure. Following is what I changed. Hope it helps to fix it.

ObjectChangeUpdater.java
------------------------
at getEntity method I added following line after if(primaryKey instanceof 
String)...

primaryKey = ProxyUtil.convertProxyIdToEntityIdType(primaryKey, entityClass, 
sessionFactory);

AbstractCollectionProxyResolver.java
-------------------------------------
at getPreparedStatement method I added another else if for Long type as follows

else if (t instanceof LongType)
{
 stmt.setLong(1, new Long(collection.getKey().toString()).longValue());
}

HibernateDeserializer.java (I don't know if this one is needed..  as a just in 
case)
--------------------------------------------------
added
@Resource
private SessionFactory sessionFactory;

and changed the args.add(((IHibernateProxy) obj).getProxyKey()) to

Serializable primaryKey = (Serializable) ((IHibernateProxy) obj).getProxyKey();
primaryKey = ProxyUtil.convertProxyIdToEntityIdType(primaryKey, 
Class.forName(obj.getClass().getName()), sessionFactory);

ProxyBatchLoader.java (this is where I make it work only for Long)
---------------------
after CreateCriteria criteria...

I basically changed every possible types for requestClassEntry collection 
members to Long. Something like:
for each item in the requestClassEntry
{
 if (item instance of ...)
  {
    item = new Long (""+item);
  }
}

ProxyLoadRequest.java
----------------------
at matchesEntity method entity.getProxyKey().equals(this.getProxyID()) was 
always giving false (something to do with Long and equals I guess)

so I used a custom equals method which basically changes entity.getProxyKey() 
and this.getProxyID() to Long before doing
return (entityProxyKey.compareTo(thisProxyID)==0)

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Here is the message I wrote about Dae's fix earlier:
-------------------------------------------------------------
http://groups.google.com/group/dphibernate/msg/8ba2d9fc3ea3ed6c?

Original issue reported on code.google.com by uo1979 on 16 Feb 2011 at 3:24

GoogleCodeExporter commented 9 years ago

Original comment by martypit...@gtempaccount.com on 15 Mar 2011 at 3:42