-->
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.  [ 11 posts ] 
Author Message
 Post subject: any way one can implement custom sessionfactory and session
PostPosted: Thu Apr 27, 2006 5:03 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.2

Quote:
Is there anyway to implement a custom sessionfactory and session objects, similar to what hibernate provides? If so, how do I tell hibernate to use these classes instead of the native ones. Everytime I try to call

Code:
hibernateSessionFactory = new Configuration().configure().buildSessionFactory();


it ends up calling the native org.hibernate.impl.SessionFactoryImpl. When it does invoke my implementation of sessionfactory it is asking for JNDI names etc.


Top
 Profile  
 
 Post subject: Re: any way one can implement custom sessionfactory and sess
PostPosted: Thu Apr 27, 2006 5:47 am 
Senior
Senior

Joined: Mon Aug 22, 2005 5:45 am
Posts: 146
srinivasj wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1.2

Quote:
Is there anyway to implement a custom sessionfactory and session objects, similar to what hibernate provides? If so, how do I tell hibernate to use these classes instead of the native ones. Everytime I try to call

Code:
hibernateSessionFactory = new Configuration().configure().buildSessionFactory();


it ends up calling the native org.hibernate.impl.SessionFactoryImpl. When it does invoke my implementation of sessionfactory it is asking for JNDI names etc.


how does it invoke you own impl.? how did you specify the class?
The session implementation is a very intrinsic piece of code of the hibernate software. It is not encouraged to use your own impl.

If you really need your own session impl. this is actually equal to creating a new software product. Don't expect hibernate to do anything in conformity with the specification/documentation.
I had also the idea of creating my own session-impl. a while ago. Eventually I figured out it's hardly necessary if you use the full potential that standard-hibernate provides.

_________________
Please don't forget to give credit, if my posting helped to solve your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 5:55 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
Quote:
To invoke the custom sessionfactoryImpl class I tried to give a property in the hibernate configuration XML file.

Hibernate did not invoke my implementation at all.

I agree that, it is not advised to do so. However, I am in a situation wherein, I believe this will probably be a solution to the dilema at hand.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:11 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what is the dilemma ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:23 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
the dilema

I am using a proprietary DB that is non-transactional. Even the proprietary JDBC drivers that help me connect to the DB are non-transactional. Now, if i use hibernate to perform transactions for me it ends up using the built in JDBC transactions. These are of no help. So thats the reason I have my own transaction and transactionfactory classes.

Our idea is to implement an "in-memory" rollback mechanism if there is a failure. it will be a very crude mechanism. however, to get that to work i would either need an interceptor to intercept the objects coming into session.save(), session.saveOrupdate() or session.delete() methods, OR use our own sessionfactory and session implementations so that, we can easily know what the objects are, store them in some sort of data structure and roll back.

That's the reason I posted this. Hibernate is amazing absolutely. However, because of the situation we are in, we would like some help to do the same rather than go the way we are going.[/quote]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:24 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
the dilema

I am using a proprietary DB that is non-transactional. Even the proprietary JDBC drivers that help me connect to the DB are non-transactional. Now, if i use hibernate to perform transactions for me it ends up using the built in JDBC transactions. These are of no help. So thats the reason I have my own transaction and transactionfactory classes.

Our idea is to implement an "in-memory" rollback mechanism if there is a failure. it will be a very crude mechanism. however, to get that to work i would either need an interceptor to intercept the objects coming into session.save(), session.saveOrupdate() or session.delete() methods, OR use our own sessionfactory and session implementations so that, we can easily know what the objects are, store them in some sort of data structure and roll back.

That's the reason I posted this. Hibernate is amazing absolutely. However, because of the situation we are in, we would like some help to do the same rather than go the way we are going.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 7:26 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
rollback in memory - you are joking right ? :)

I don't understand why you want to override sessionimpl/sessionfactoryimpl - use the Hibernate 3.1 events for this.


but seriously reconsider trying to do rollbacks in memory; that won't solve anything. Use flushmode.NEVER and just only do flush when you want the changes to be done.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 8:12 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
hibernate3.1 events? what are these events and how do I get to access them? any examples would be great.

flushMode.NEVER would not solve the problem. Lets say we have 10 DML operations to done. some inserts, updates and deletes. And after 5 operations there is an error, I need to rollback the first 4. It would not matter what the flushMode is set to. I will still have an DB inconsistency issue.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 8:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and how does rollback in memory help you here ?

events is documented in the manual.

/max

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 8:48 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
I do not know how it will help as of now. Its thought and a research task that I am doing. If it works great. If not, I have given it a shot.

I will look into the manual for the documentation for events.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 9:55 am 
Newbie

Joined: Mon Apr 03, 2006 9:44 am
Posts: 9
I am sorry I did not see who had sent me the message/post. Thanks for taking sometime to look into my dilema.

the rollback in memory was something we had done a long long time ago for a flat file based system. something like a stack to traverse back to undo the changes.

With the events I could use the afterTransactionCompletion() event to verify if everything passed and if there was a problem, then figure out a way to only rollback the ones that have been committed.

Is there an onFlush() event handler too? There should not be as this does not sound even remotely logical. :).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 11 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.