Announcement Announcement Module
Collapse
No announcement yet.
Advise an object that will later be proxied by hibernate? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • m081072
    started a topic Advise an object that will later be proxied by hibernate?

    Advise an object that will later be proxied by hibernate?

    Hi All,

    My goal is to product hibernate objects that manage their own transations each time a setter or getter method is called. I am having trouble so I need your advice and help.

    What I have done so far:

    I have registered a Hibernate interceptor that instantiates new objects from a ProxyFactoryBean. This means my domain objects have advice applied to them using Spring. Hibernate then proxies that advised domain object (or at least I assume thats the order of events) and things go wrong - all of the fields of the resulting object are null when you inspect them. But if you access them through accessor methods, they do resolve correctly. I am using Hibernate field access.

    Can anybody please offer some advice on how to proceed? Is what I am trying to do unworkable?

    Thanks very much,
    Mike.

  • daiqing1981@yahoo.com.cn
    replied
    really it works! thank you!!!!

    Leave a comment:


  • daiqing1981@yahoo.com.cn
    replied
    I tried as you told but just get a java.io.NotSerializableException: org.springframework.aop.aspectj.AspectJPointcutAdv isor, please help, hope someone can pay attention to the old message

    Code:
    org.springframework.orm.hibernate3.HibernateSystemException: could not serialize; nested exception is org.hibernate.type.SerializationException: could not serialize
    	at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:661)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:789)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:663)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:709)
    	at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:678)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener$TransactionContext.endTransaction(TransactionalTestExecutionListener.java:504)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener.endTransaction(TransactionalTestExecutionListener.java:277)
    	at org.springframework.test.context.transaction.TransactionalTestExecutionListener.afterTestMethod(TransactionalTestExecutionListener.java:170)
    	at org.springframework.test.context.TestContextManager.afterTestMethod(TestContextManager.java:344)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runAfters(SpringMethodRoadie.java:307)
    	at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:338)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197)
    	at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143)
    	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142)
    	at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
    	at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
    	at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
    	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
    	at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
    	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:45)
    	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
    Caused by: org.hibernate.type.SerializationException: could not serialize
    	at org.hibernate.util.SerializationHelper.serialize(SerializationHelper.java:158)
    	at org.hibernate.util.SerializationHelper.serialize(SerializationHelper.java:178)
    	at org.hibernate.type.SerializableType.toBytes(SerializableType.java:78)
    	at org.hibernate.type.SerializableType.toString(SerializableType.java:62)
    	at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:93)
    	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:140)
    	at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:107)
    	at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:1997)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2371)
    	at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2307)
    	at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2607)
    	at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92)
    	at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
    	at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:142)
    	at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
    	at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
    	at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
    	at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
    	at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
    	at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:655)
    	... 23 more
    Caused by: java.io.NotSerializableException: org.springframework.aop.aspectj.AspectJPointcutAdvisor
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.writeArray(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
    	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
    	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject(Unknown Source)
    	at org.hibernate.util.SerializationHelper.serialize(SerializationHelper.java:154)
    	... 43 more

    Leave a comment:


  • adrian colyer
    replied
    Hibernate field access + Spring proxies

    I haven't tried the configuration you're using, but it seems to me that Hibernate field access and Spring proxying would be mutually incompatible. The Hibernate docs say that "If you specify access="field", Hibernate will bypass the get/set pair and access the field directly, using reflection." (http://www.hibernate.org/hib_docs/re...l/mapping.html). If you feed Hibernate a Spring proxy, the proxy class won't have the fields declared directly on it (and so they won't be found via reflection). If you use access=property instead then Hibernate should go through the getter/setter (which *are* proxied) and I would expect things to work fine...

    Leave a comment:


  • Colin Yates
    replied
    Interesting problem I remember reading about NakedObjects and did wonder how they would have a "unit of work".

    Good luck, and let us know how you get one

    Leave a comment:


  • m081072
    replied
    Hi,

    I am trying to do this because I am passing my domain objects to a nakedobjects style of framework that reflectively invokes the methods on my domain objects without regard to transations. So I wanted to wrap my domain objects in a proxy that takes care of the transactions.

    Thats the problem I am trying to solve or work around, and I'm open to any and all suggestions :-)

    Ta,
    Mike.

    Leave a comment:


  • Colin Yates
    replied
    I am not sure *why* you want to achieve this? Are you trying to resolve the lazy load problem with hibernate?

    Leave a comment:

Working...
X