-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: Spring Integration
PostPosted: Thu Jul 07, 2005 3:56 am 
Newbie

Joined: Wed Jun 01, 2005 11:00 am
Posts: 17
Location: UK
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hello All,
I have just started working with a Spring based architecture. I am in the process of integrating Hibernate into the system. The system is based on POJOs. Each POJO has associated DAO and Validator helper objects that are not mapped to tables in the database. These objects are injected to the POJO using a spring factory. Calls to delete and update on the POJO are then delegated to the associated DAO.

All well and good. However, I would like to start using Hibernate in in my data access layer. I want to use Hibernate to do a lookup but induce it to use Springs dependency injection. At the moment I can use Hibernate to do a lookup but it does not populate the helper objects so the DAO will be null and I have no way of persisting any changes made.
I would be really grateful of any suggestions.
Many Thanks,

Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 4:02 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Ask on the Spring forum.


Top
 Profile  
 
 Post subject: on load listener
PostPosted: Thu Jul 07, 2005 7:39 am 
Newbie

Joined: Wed Jun 01, 2005 11:00 am
Posts: 17
Location: UK
Ok so this is how far I have got.
I am using the domain factory that wraps the spring application context. the create call injects the helper class dependencies.
I am assuming that by setting the instance to load on the event hibernate will populate the properties using its own ORM. Is this correct?

public class HibernateLoadListener extends DefaultLoadEventListener {

public Object onLoad(LoadEvent event,LoadEventListener.LoadType loadType)
throws HibernateException{
DomainObject obj ;
//perform dependency injection here
Class classToMake;
try{
classToMake = Class.forName(event.getEntityClassName());

obj = DomainFactory.getInstance().create(classToMake);

obj.setId((DomainObjectID)event.getEntityId());

event.setInstanceToLoad(obj);

}
catch(ClassNotFoundException ex){
throw new HibernateException(ex);
}

obj =(DomainObject ) super.onLoad(event, loadType);

return obj;
}

}

anyway I get the following error when I atempt this. Should I be using a pre load listener? I should point out there is no error if i dont use event set instance

[07/07/05 11:38:41:828 GMT] 4e3c4e3c DefaultLoadEv I org.hibernate.event.def.DefaultLoadEventListener TRAS0014I: The following exception was logged org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.du.ezmarket.business.parallelnegotiation.AuctionLineImpl#com.du.ezmarket.business.DomainObjectID@494a494a[id=10201]]
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:100)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:22)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:28)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:171)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:210)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at com.du.ezmarket.integration.marketbasket.HibernateLoadListener.onLoad(HibernateLoadListener.java)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:599)
at org.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:73)
at org.hibernate.type.EntityType.resolve(EntityType.java:264)
at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:196)
at org.hibernate.persister.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:617)
at org.hibernate.collection.PersistentSet.readFrom(PersistentSet.java:226)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:610)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:347)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:302)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1360)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:105)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1353)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:133)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getLineDTOs(AuctionSummaryDTOBuilder.java:183)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getBasketDTOs(AuctionSummaryDTOBuilder.java:130)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getBasketSummaryDTO(AuctionSummaryDTOBuilder.java:83)
at com.du.ezmarket.reverseauction.controllercommands.AuctionSummaryRedirectorCmdImpl.performExecute(AuctionSummaryRedirectorCmdImpl.java:83)
at com.ibm.commerce.command.ECCommandTarget.executeCommand(ECCommandTarget.java:132)
at com.ibm.ws.cache.command.CommandCache.executeCommand(CommandCache.java:282)
at com.ibm.websphere.command.CacheableCommandImpl.execute(CacheableCommandImpl.java:161)
at com.ibm.commerce.command.AbstractECTargetableCommand.execute(AbstractECTargetableCommand.java:175)
at com.ibm.commerce.webcontroller.ControllerCmdExecUnit.execute(ControllerCmdExecUnit.java:193)
at com.ibm.commerce.webcontroller.WebController.executeTransaction(WebController.java:222)
at com.ibm.commerce.webcontroller.WebController.processRequest(WebController.java:877)
at com.ibm.commerce.adapter.AbstractHttpAdapter.processRequest(AbstractHttpAdapter.java:330)
at com.ibm.commerce.server.RequestServlet$2.run(RequestServlet.java:1504)
at com.ibm.commerce.server.RequestServlet.service(RequestServlet.java:1574)
at com.du.ezmarket.reverseauction.servlets.EZMRequestServlet.service(EZMRequestServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
at com.ibm.commerce.dynacache.filter.CacheFilter$1.run(CacheFilter.java:359)
at com.ibm.commerce.dynacache.filter.CacheFilter.doFilter(CacheFilter.java:396)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:939)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java)
.
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.du.ezmarket.business.parallelnegotiation.AuctionLineImpl#com.du.ezmarket.business.DomainObjectID@494a494a[id=10201]]
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:100)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:22)
at org.hibernate.NonUniqueObjectException.<init>(NonUniqueObjectException.java:28)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:171)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:210)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at com.du.ezmarket.integration.marketbasket.HibernateLoadListener.onLoad(HibernateLoadListener.java)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:599)
at org.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:73)
at org.hibernate.type.EntityType.resolve(EntityType.java:264)
at org.hibernate.type.EntityType.nullSafeGet(EntityType.java:196)
at org.hibernate.persister.collection.AbstractCollectionPersister.readElement(AbstractCollectionPersister.java:617)
at org.hibernate.collection.PersistentSet.readFrom(PersistentSet.java:226)
at org.hibernate.loader.Loader.readCollectionElement(Loader.java:610)
at org.hibernate.loader.Loader.readCollectionElements(Loader.java:347)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:302)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1360)
at org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:105)
at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:488)
at org.hibernate.event.def.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:60)
at org.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:1353)
at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:170)
at org.hibernate.collection.AbstractPersistentCollection.read(AbstractPersistentCollection.java:47)
at org.hibernate.collection.PersistentSet.iterator(PersistentSet.java:133)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getLineDTOs(AuctionSummaryDTOBuilder.java:183)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getBasketDTOs(AuctionSummaryDTOBuilder.java:130)
at com.du.ezmarket.business.transport.marketbasket.AuctionSummaryDTOBuilder.getBasketSummaryDTO(AuctionSummaryDTOBuilder.java:83)
at com.du.ezmarket.reverseauction.controllercommands.AuctionSummaryRedirectorCmdImpl.performExecute(AuctionSummaryRedirectorCmdImpl.java:83)
at com.ibm.commerce.command.ECCommandTarget.executeCommand(ECCommandTarget.java:132)
at com.ibm.ws.cache.command.CommandCache.executeCommand(CommandCache.java:282)
at com.ibm.websphere.command.CacheableCommandImpl.execute(CacheableCommandImpl.java:161)
at com.ibm.commerce.command.AbstractECTargetableCommand.execute(AbstractECTargetableCommand.java:175)
at com.ibm.commerce.webcontroller.ControllerCmdExecUnit.execute(ControllerCmdExecUnit.java:193)
at com.ibm.commerce.webcontroller.WebController.executeTransaction(WebController.java:222)
at com.ibm.commerce.webcontroller.WebController.processRequest(WebController.java:877)
at com.ibm.commerce.adapter.AbstractHttpAdapter.processRequest(AbstractHttpAdapter.java:330)
at com.ibm.commerce.server.RequestServlet$2.run(RequestServlet.java:1504)
at com.ibm.commerce.server.RequestServlet.service(RequestServlet.java:1574)
at com.du.ezmarket.reverseauction.servlets.EZMRequestServlet.service(EZMRequestServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:76)
at com.ibm.commerce.dynacache.filter.CacheFilter$1.run(CacheFilter.java:359)
at com.ibm.commerce.dynacache.filter.CacheFilter.doFilter(CacheFilter.java:396)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:132)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:71)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:939)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:435)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java)


I configure the listener:
<listener type="load" class="com.du.ezmarket.integration.marketbasket.HibernateLoadListener"/>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 8:26 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
What part of "this has nothing to do with Hibernate and you are in the wrong place" wasn't understandable?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 8:32 am 
Newbie

Joined: Wed Jun 01, 2005 11:00 am
Posts: 17
Location: UK
Hello,

I am sorry that you seem so annoyed. I am actually tracing through the hibernate source code and have found something I think maybe an issue. I really aprrecaite the help I have had so far and think hibernate is a great product. Anyway, I am sorry you feel that way. I shall post it for general interest.

I am really very puzzled by your attitude,

Ben


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 8:40 am 
Newbie

Joined: Wed Jun 01, 2005 11:00 am
Posts: 17
Location: UK
Anyway, I found this:

/**
* Perfoms the load of an entity.
*
* @return The loaded entity.
* @throws HibernateException
*/
protected Object load(
final LoadEvent event,
final EntityPersister persister,
final EntityKey keyToLoad,
final LoadEventListener.LoadType options)
throws HibernateException {

if ( event.getInstanceToLoad() != null ) {
if ( event.getSession().getPersistenceContext().getEntry( event.getInstanceToLoad() ) != null ) {
throw new PersistentObjectException(
"attempted to load into an instance that was already associated with the session: " +
MessageHelper.infoString( persister, event.getEntityId(), event.getSession().getFactory() )
);
}
persister.setIdentifier( event.getInstanceToLoad(), event.getEntityId(), event.getSession().getEntityMode() );
}

Object entity = doLoad(event, persister, keyToLoad, options);

boolean isOptionalInstance = event.getInstanceToLoad() != null;

if ( !options.isAllowNulls() || isOptionalInstance ) {
ObjectNotFoundException.throwIfNull( entity, event.getEntityId(), event.getEntityClassName() );
}

if ( isOptionalInstance && entity != event.getInstanceToLoad() ) {
throw new NonUniqueObjectException( event.getEntityId(), event.getEntityClassName() );
}

return entity;
}

It does a compare on reference and not id. Which screws up my code which places a new reference in.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:28 am 
Newbie

Joined: Wed Jun 01, 2005 11:00 am
Posts: 17
Location: UK
Oh and by the way Christian.
This has nothing to do with Spring. It could be any application context framework. So in simple English for you to understand:

How do I capture the the onLoad process for a POJO and successfully inject a new entity reference .

I am beginning to wonder if you have any understanding of Hibernate at all. It would seem by your previous posts,to me and others, that all you are capable of is criticising and demeaning other peoples efforts in rather poor English.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:28 am 
Newbie

Joined: Thu Jul 07, 2005 10:14 am
Posts: 3
[quote="christian"]What part of "this has nothing to do with Hibernate and you are in the wrong place" wasn't understandable?[/quote]

ok, i read these forums a lot and have solved a lot of my problems via other peoples posts so havent had a need to register. However, this fun forum posting made me register just to comment. Someone who is obviously keen on hibernate, enjoying working with it and getting an exception in hibernate when trying to integrate it with spring (fairly common I would think) posts for help on here and a member of the hibernate team comes back with the above helpful statement.

Fine you think its spring specific, the original poster doesnt and considering his error is in hibernate this seems a reasonable place to see if anyone else is getting a hibernate error.

tbh christian, if you have nothing valuable to add to a posting (which looking at other forum posts seems to be a common approach to your posting) dont bother answering.

ben - i had a similar problem. i'll dig up my solution.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:33 am 
Newbie

Joined: Thu Jul 07, 2005 10:14 am
Posts: 3
[quote="christian"]What part of "this has nothing to do with Hibernate and you are in the wrong place" wasn't understandable?[/quote]

ok, i read these forums a lot and have solved a lot of my problems via other peoples posts so havent had a need to register. However, this fun forum posting made me register just to comment. Someone who is obviously keen on hibernate, enjoying working with it and getting an exception in hibernate when trying to integrate it with spring (fairly common I would think) posts for help on here and a member of the hibernate team comes back with the above helpful statement.

Fine you think its spring specific, the original poster doesnt and considering his error is in hibernate this seems a reasonable place to see if anyone else is getting a hibernate error.

tbh christian, if you have nothing valuable to add to a posting (which looking at other forum posts seems to be a common approach to your posting) dont bother answering.

ben - i had a similar problem. i'll dig up my solution.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:33 am 
Newbie

Joined: Thu Jul 07, 2005 10:14 am
Posts: 3
double post - soz.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 10:35 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Ok, I'm out of this forum now, finally. You'll soon see how much fun it is without me deleting the crap.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 07, 2005 3:35 pm 
Regular
Regular

Joined: Sun Sep 26, 2004 9:27 pm
Posts: 75
Location: Atlanta, GA, USA
christian wrote:
Ok, I'm out of this forum now, finally. You'll soon see how much fun it is without me deleting the crap.


Does that mean you got fired? Or do you just have a new "aspect-oriented" personality view?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.