Wait a minute ok I think I see now...

project/java
persistenceFactory.java - interface to cocoon's persistenceFactory, methods createSession
HibernateFactory.java - implements persistenceFactory, methods configure, service, initialize, dispose, createSession


Ok so far so good, when cocoon starts up, the hibernate factory is initialized, and the sessionfactory is in existence:
cfg = new net.sf.hibernate.cfg.Configuration();
cfg.addClass(com.kismetsoftware.insecticide.Company.class);
cfg.addClass(com.kismetsoftware.insecticide.Project.class);
cfg.addClass(com.kismetsoftware.insecticide.Bug.class);
cfg.addClass(com.kismetsoftware.insecticide.Comment.class);
sf = cfg.buildSessionFactory();


I was thinking this would be moved to happen at every request, which I definately did not want. It makes sense now. So when I change the persistence mechanism, it *should* be only these two classes that need to be changed right?

Moving forward,

project/java
bug.java POJO
bugSearch.java methods like findbugsByStatus, findBugsByExample, etc.


Heres my next confusion - I am using cocoon to handle my sessionFactory right? So stuff I have in my flow now like:


// Create Hibernate Session
var factory = cocoon.getComponent(Packages.com.kismetsoftware.insecticide.PersistenceFactory.ROLE);
var hs = factory.createSession();


// Might as well quit now if the session is no good :(
if (hs == null){throw new Packages.org.apache.cocoon.ProcessingException("Hibernate session is null ");}


// Look up our Entry
var bean = hs.find("from com.kismetsoftware.insecticide.Bug WHERE id='"+id+"'").get(0);


Should change to:

// Create Persistence Session
var factory = cocoon.getComponent(Packages.com.kismetsoftware.insecticide.PersistenceFactory.ROLE);
var hs = factory.createSession();


// Might as well quit now if the session is no good :(
if (hs == null){throw new Packages.org.apache.cocoon.ProcessingException("Persistence session is null ");}


// Grab the class with the methods to do what we want (Constructor takes the session as an arguement)
var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch(hs);


       // Look up our Entry
       var bean = bugSearch.findBugById(id);

right? Or would it be better to have one class such as BugFacade with all methods dealing with bugs? (save, find, delete etc)

Lastly, I am pretty sure the above would work, but to be really separate-y, what about:

var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch(hs);
var bean = bugSearch.findBugById(id);

much simpler and really doesn't care how BugSearch does what it does. How would I get a grip on the cocoon component inside BugSearch.java?


<quote> You should really be using the "Open Session in View" pattern:

http://hibernate.org/Documentation/OpenSessionInView
</quote>

Sorry, but this has confused me further.. where would this fit into a cocoon framework?

JD


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to