You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by JD Daniels <jd...@kismetsoftware.com> on 2005/01/26 16:14:12 UTC

[flow] Hibernate createCriteria syntax help?

Hi all,

I am trying to add criteria inside a flowscript. Here is what i think 
should work:

1        var criteria = hs.createCriteria(Bug.class);
2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
3        var bug = criteria.list();

this spits out : missing name after . operator on line 1

I have tried variations of switching to the the [""] syntax of calling 
methods, but while they fix the error, criteria is always undefined.

Anyone have insight into how i can call these methods in flow?

full function:

function search_bug()
{
        // Create The Form
        var form = new Form("forms/bugSearchModel.xml");

        // Set Some Form Specific Text Fields
        var model = form.getWidget();
        model.buttonText = "Search";
        model.title = "Search Bug Database";

        form.showForm("internal/show-form/bugSearch");

        // 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 ");}

        // This is problem Line:
        var criteria = hs.createCriteria(Bug.class);
        criteria.add(Expression.eq("status", "UNCONFIRMED"));
        var bug = criteria.list();

        // Clean Up Our Mess :)
        hs.flush();
        hs.close();
        cocoon.releaseComponent(factory);

        // Send The User Their Result
        cocoon.sendPage("internal/generate-view/bug_summary", {title : 
"Bugs",bug : bug});
}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 26/gen/05, alle 16:14, JD Daniels ha scritto:

> 1        var criteria = hs.createCriteria(Bug.class);
> 2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
> 3        var bug = criteria.list();
>
> this spits out : missing name after . operator on line 1

Simply use:

> 1        var criteria = hs.createCriteria(Bug);

Javascript does not need (or like) the .class. That's all.

	Ugo

-- 
Ugo Cei - http://agylen.com/blojsom/blog/

Re: [flow] Hibernate createCriteria syntax help?

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
Hibernate is concerned only with getting data into and out of a 
relational database.  As such, it's part of the 'M' in MVC.  Your flow 
code is the C part.  It's job should be to route requests, map data back 
and forth from forms to your facade, and generally to act as the glue 
between the frontend and backend.

Your question about a Hibernate as a Cocoon component is one that I 
cannot answer very well, but my concern is that this couples your 
backend to some Cocoon-specific functionality.  I'm not sure what it 
provides you in return.  Perhaps someone else can chime in here and 
enlighten both of us, because the functionality that Cocoon can provide 
in this particular circumstance transcends the layers of an MVC-based 
design.

phil.

JD Daniels wrote:
> I am at the start of a big ol project here heh heh. I would love to make 
> it so - I have made a class bugSearch, with methods to lookup by status, 
> etc, as well as take an example bean and do a full search by.
> 
> 
>        // Create The Form
>        var form = new Form("forms/bugSearchModel.xml");
> 
>        // Set Some Form Specific Text Fields
>        var model = form.getWidget();
>        model.buttonText = "Search";
>        model.title = "Search Bug Database";
> 
>        form.showForm("internal/show-form/bugSearch");
> 
>        // 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 ");}
> 
>        var bugSearch = new Packages.com.BugSearch(hs);
> 
>        var eBug=new Packages.com.kismetsoftware.insecticide.Bug;
>        if (model.projectId.getValue() != null)
>        {
>            eBug.project=hs.find("from Project WHERE 
> id='"+model.projectId.getValue()+"'").get(0);
>        }
>        eBug.severity=model.severity.getValue();
>        eBug.priority=model.priority.getValue();
>        eBug.opsys=model.opsys.getValue();
>        eBug.description=model.description.getValue();
>        eBug.status=model.status.getValue();
>        eBug.resolution=model.resolution.getValue();
>        var bug = bugSearch.findBugs(eBug);
> 
>        // Clean Up Our Mess :)
>        hs.flush();
>        hs.close();
>        cocoon.releaseComponent(factory);
> 
>        // Send The User Their Result
>        cocoon.sendPage("internal/generate-view/bug_summary", {title : 
> "Bugs",bug : bug});
> 
> so I guess my next question would be : would you just forget having a 
> hibernate factory as a cocoon component? ie, just have yet another class 
> like package.hibernateFactoryImpl? see I'm thinking it is too much 
> overhead to be registering classes at every request.
> 
> I'm just very confused :)
> 
> Gregor J. Rothfuss wrote:
> 
>> WHIRLYCOTT wrote:
>>
>>> If you will allow me to offer to you a thought which is only slightly 
>>> related to your original question, I would strongly encourage you to 
>>> move all of that transactional persistence stuff behind a facade a 
>>> for a few reasons, listed in no particular order:
>>>
>>> 1) you'll be able to write junit tests to see if the backend is behaving
>>> 2) decouple your application layers into something resembling MVC
>>> 3) If you decide one day to use something other than Hibernate, you 
>>> will  be able to rip out the persistence mechanism without touching 
>>> your flow controllers
>>> 4) you can reuse your facade in other applications
>>
>>
>>
>> just to chime in here: phil used this technique to share these facades 
>> between struts and cocoon. very useful if you live in a heterogenous 
>> world..
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
Heh heh what I want anyway.. still need to find a way to actually *do* it :S

WHIRLYCOTT wrote:

> I think you've basically got the hang of this now.
> phil.
>
> JD Daniels wrote:
>
>>
>>
>> Ugo Cei wrote:
>>
>>> Il giorno 27/gen/05, alle 15:16, JD Daniels ha scritto:
>>>
>>>> right? Or would it be better to have one class such as BugFacade 
>>>> with all methods dealing with bugs? (save, find, delete etc)
>>>
>>>
>>>
>>>
>>> Yes, that is usually preferrable. A class that deals with retrieving 
>>> and storing domain objects to a persitent store is usually called a 
>>> Data Access Object (DAO).
>>>
>>>
>>>> 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);
>>>
>>>
>>>
>>>
>>> What's changed WRT to the previous version? I can't see the difference.
>>>
>> var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch();
>> var bean = bugSearch.findBugById(id);
>>
>> The  cocoon component for the persisenceFactory , and the hibernate 
>> session  opening and closing is gone from flow. so the whole function 
>> would be:
>>
>> function showBug()
>> {
>>    var bugSearch = new 
>> Packages.com.kismetsoftware.insecticide.BugSearch();
>>    var bean = bugSearch.findBugById(id);
>>    cocoon.sendPage("internal/generate-view/bug_summary", {title : 
>> "Bug details", bug : bug});
>> }
>>
>>>   Ugo
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
I think you've basically got the hang of this now.
phil.

JD Daniels wrote:
> 
> 
> Ugo Cei wrote:
> 
>> Il giorno 27/gen/05, alle 15:16, JD Daniels ha scritto:
>>
>>> right? Or would it be better to have one class such as BugFacade with 
>>> all methods dealing with bugs? (save, find, delete etc)
>>
>>
>>
>> Yes, that is usually preferrable. A class that deals with retrieving 
>> and storing domain objects to a persitent store is usually called a 
>> Data Access Object (DAO).
>>
>>
>>> 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);
>>
>>
>>
>> What's changed WRT to the previous version? I can't see the difference.
>>
> var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch();
> var bean = bugSearch.findBugById(id);
> 
> The  cocoon component for the persisenceFactory , and the hibernate 
> session  opening and closing is gone from flow. so the whole function 
> would be:
> 
> function showBug()
> {
>    var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch();
>    var bean = bugSearch.findBugById(id);
>    cocoon.sendPage("internal/generate-view/bug_summary", {title : "Bug 
> details", bug : bug});
> }
> 
>>   Ugo
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
I sincerley appreciate the info you guys have shared with me :) thank you.

that was where i was stuck - I knew I had to separate my concerns, but 
all the tutorials I found had a cocoon component dealing with hibernate 
stuff. Hibernate itself is rather nice. I have been doing it for awhile 
now using the cocoon persistencefactory component. However, everytime i 
got stuck, and asked on the list for help, I got "Separate your stuff 
better" heh heh. believe me I want to, and since you guys were so 
helpful with the issue this time, I chased it a little. I actually have 
a much better understanding of the cocoon involvement, and now know 
where to mess with it to fix it. Of course, I have trashed my project so 
badly that it currently won't build, but I am confident I can get it 
worked out.

Right now, I had the idea of a filter for each request both open and 
close my session, but I haven't got it working yet.
I guess I will take the plunge into spring right now. (Maybe past 
discussions on the dev list will start to make sense)

Again thanks to both of you - you have truly expanded my knowledge.

I had no idea a syntax question would put me so far ahead :)

JD

WHIRLYCOTT wrote:

> +1 on that, Ugo.
>
> JD, there's a decent O'Reilly book called "Better, Faster, Lighter 
> Java" or something like that.  It covers a lot of the ideas that we 
> have been telling you about.  It doesn't cover any Cocoon stuff, but 
> the part you are working on shouldn't care about that at all.  You 
> might find it useful.
>
> phil.
>
> Ugo Cei wrote:
>
>> Il giorno 27/gen/05, alle 17:09, JD Daniels ha scritto:
>>
>>>> What's changed WRT to the previous version? I can't see the 
>>>> difference.
>>>>
>>> var bugSearch = new 
>>> Packages.com.kismetsoftware.insecticide.BugSearch();
>>> var bean = bugSearch.findBugById(id);
>>
>>
>>
>> Ah OK. I'll tell you a story :-) When we started using Hibernate with 
>> Cocoon, we used too get a session from a home-grown component that 
>> wrapped a SessionFactory and created Sessions on demand. Just like in 
>> your first version.
>>
>> Now we use Spring, which handles SessionFactory configuration, 
>> session creation (and guaranteed disposal), transactions and 
>> exception handling. Typically we define one (or a few) "Service" 
>> facades that are managed by Spring and interact with one or more DAOs 
>> in the backend. The flowscript deals exclusively with the service 
>> facade.
>>
>> If you want to develop robust, easily maintained and testable 
>> applications, I suggest you look closely at Spring.
>>
>>     Ugo
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
+1 on that, Ugo.

JD, there's a decent O'Reilly book called "Better, Faster, Lighter Java" 
or something like that.  It covers a lot of the ideas that we have been 
telling you about.  It doesn't cover any Cocoon stuff, but the part you 
are working on shouldn't care about that at all.  You might find it useful.

phil.

Ugo Cei wrote:
> Il giorno 27/gen/05, alle 17:09, JD Daniels ha scritto:
> 
>>> What's changed WRT to the previous version? I can't see the difference.
>>>
>> var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch();
>> var bean = bugSearch.findBugById(id);
> 
> 
> Ah OK. I'll tell you a story :-) When we started using Hibernate with 
> Cocoon, we used too get a session from a home-grown component that 
> wrapped a SessionFactory and created Sessions on demand. Just like in 
> your first version.
> 
> Now we use Spring, which handles SessionFactory configuration, session 
> creation (and guaranteed disposal), transactions and exception handling. 
> Typically we define one (or a few) "Service" facades that are managed by 
> Spring and interact with one or more DAOs in the backend. The flowscript 
> deals exclusively with the service facade.
> 
> If you want to develop robust, easily maintained and testable 
> applications, I suggest you look closely at Spring.
> 
>     Ugo
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 27/gen/05, alle 17:09, JD Daniels ha scritto:

>> What's changed WRT to the previous version? I can't see the 
>> difference.
>>
> var bugSearch = new 
> Packages.com.kismetsoftware.insecticide.BugSearch();
> var bean = bugSearch.findBugById(id);

Ah OK. I'll tell you a story :-) When we started using Hibernate with 
Cocoon, we used too get a session from a home-grown component that 
wrapped a SessionFactory and created Sessions on demand. Just like in 
your first version.

Now we use Spring, which handles SessionFactory configuration, session 
creation (and guaranteed disposal), transactions and exception 
handling. Typically we define one (or a few) "Service" facades that are 
managed by Spring and interact with one or more DAOs in the backend. 
The flowscript deals exclusively with the service facade.

If you want to develop robust, easily maintained and testable 
applications, I suggest you look closely at Spring.

	Ugo

-- 
Ugo Cei - http://agylen.com/blojsom/blog/

Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.

Ugo Cei wrote:

> Il giorno 27/gen/05, alle 15:16, JD Daniels ha scritto:
>
>> right? Or would it be better to have one class such as BugFacade with 
>> all methods dealing with bugs? (save, find, delete etc)
>
>
> Yes, that is usually preferrable. A class that deals with retrieving 
> and storing domain objects to a persitent store is usually called a 
> Data Access Object (DAO).
>
>
>> 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);
>
>
> What's changed WRT to the previous version? I can't see the difference.
>
var bugSearch = new Packages.com.kismetsoftware.insecticide.BugSearch();
var bean = bugSearch.findBugById(id);

The  cocoon component for the persisenceFactory , and the hibernate 
session  opening and closing is gone from flow. so the whole function 
would be:

function showBug()
{
    var bugSearch = new 
Packages.com.kismetsoftware.insecticide.BugSearch();
    var bean = bugSearch.findBugById(id);
    cocoon.sendPage("internal/generate-view/bug_summary", {title : "Bug 
details", bug : bug});
} 


>   Ugo
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 27/gen/05, alle 15:16, JD Daniels ha scritto:

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

Yes, that is usually preferrable. A class that deals with retrieving 
and storing domain objects to a persitent store is usually called a 
Data Access Object (DAO).


> 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);

What's changed WRT to the previous version? I can't see the difference.

   Ugo

-- 
Ugo Cei - http://agylen.com/blojsom/blog/

Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
No, I'm not really writing another bug tracker. I have it so clients can 
login and peek at the timesheets for what we have done including stuff 
like printers, adsl etc etc. It is just a simple object so they can add 
feature requests or fixes for whatever they need. They all hate having 
to login more than once, so this is just simple - not nearly bugzilla 
power :)

I was hoping this list would be ok, I can make a hibernate command line 
app do what I want ( Ie hello world again) It is getting it into cocoon 
that is my headache :)

So I am off to read about filters .. this might be good way to do it and 
get all that crap out of my flow. Quick question for you before i go off 
into researchland: From what I have googled so far, it looks like people 
are only using the filter to trash sessions when they are done with them 
at the end of the request. For example, 
http://wiki.apache.org/cocoon/CocoonAndHibernateTutorial still using a 
cocoon component to create the session.

How are you creating the session in your business logic?

JD


WHIRLYCOTT wrote:

> As a preface, the Cocoon-users list is probably not the best place to 
> get Hibernate assistance, but here goes....
>
> JD Daniels wrote:
>
>> 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();
>
>
> You should be declaring these inside hibernate.cfg.xml to avoid 
> putting all this hardcoded junk in your code.  What you are doing will 
> work, but gives you pain with no gain, in your particular case.
>
>> 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?
>
>
> You should only create one SessionFactory per application lifecycle.
>
>> Should change to:
>>
>>        // Create Persistence Session
>>        var factory = 
>> cocoon.getComponent(Packages.com.kismetsoftware.insecticide.PersistenceFactory.ROLE); 
>
>
>
> Right, this is the part that I am less keen on.  I don't see the point 
> of creating this dependency between Cocoon and your backend.
>
>>        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);
>
>
> Well, you shouldn't even be exposing any of this Hibernate stuff in 
> the flow code at _all_.  The Hibernate session is just wrapping your 
> JDBC connection and whatever transaction JTA/JDBC transaction that 
> you're currently in, so you could create a class to wrap that.
>
>
>>
>>        // Look up our Entry
>>        var bean = bugSearch.findBugById(id);
>
>
> Yes, that's looking better.  But call it a 'facade', so that others 
> who work on your code will understand the role of bugSearch 
> immediately just by looking at the name.
>
>> right? Or would it be better to have one class such as BugFacade with 
>> all methods dealing with bugs? (save, find, delete etc)
>
>
> You can run into an anti-pattern quickly here, but you should ideally 
> have all of your transactional and business logic methods exposed in 
> one interface or class, not just your bug search stuff.
>
> (Aside: are you really writing _another_ bug tracking system...???)
>
>> 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);
>
>
> Right.
>
>> 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?
>
>
> I don't think you should be, but maybe someone else has a good 
> argument for creating this dependency.
>
>>
>> <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?
>
>
> Cocoon sits on top of a web container.  The servlet 2.3 api supports 
> servlet filters.  What this person is suggesting is that you use a 
> servlet filter to drop a hibernate session into a threadlocal that 
> sits in the thread currently servicing your request.  It's a very 
> standard way of doing stuff like this... definitely take the time to 
> understand that.
>
> phil.
>
>> JD
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
As a preface, the Cocoon-users list is probably not the best place to 
get Hibernate assistance, but here goes....

JD Daniels wrote:
> 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();

You should be declaring these inside hibernate.cfg.xml to avoid putting 
all this hardcoded junk in your code.  What you are doing will work, but 
gives you pain with no gain, in your particular case.

> 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?

You should only create one SessionFactory per application lifecycle.

> Should change to:
> 
>        // Create Persistence Session
>        var factory = 
> cocoon.getComponent(Packages.com.kismetsoftware.insecticide.PersistenceFactory.ROLE); 

Right, this is the part that I am less keen on.  I don't see the point 
of creating this dependency between Cocoon and your backend.

>        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);

Well, you shouldn't even be exposing any of this Hibernate stuff in the 
flow code at _all_.  The Hibernate session is just wrapping your JDBC 
connection and whatever transaction JTA/JDBC transaction that you're 
currently in, so you could create a class to wrap that.


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

Yes, that's looking better.  But call it a 'facade', so that others who 
work on your code will understand the role of bugSearch immediately just 
by looking at the name.

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

You can run into an anti-pattern quickly here, but you should ideally 
have all of your transactional and business logic methods exposed in one 
interface or class, not just your bug search stuff.

(Aside: are you really writing _another_ bug tracking system...???)

> 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);

Right.

> 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?

I don't think you should be, but maybe someone else has a good argument 
for creating this dependency.

> 
> <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?

Cocoon sits on top of a web container.  The servlet 2.3 api supports 
servlet filters.  What this person is suggesting is that you use a 
servlet filter to drop a hibernate session into a threadlocal that sits 
in the thread currently servicing your request.  It's a very standard 
way of doing stuff like this... definitely take the time to understand that.

phil.

> JD
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
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: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Ugo Cei <ug...@apache.org>.
Il giorno 26/gen/05, alle 22:44, JD Daniels ha scritto:

> so I guess my next question would be : would you just forget having a 
> hibernate factory as a cocoon component? ie, just have yet another 
> class like package.hibernateFactoryImpl? see I'm thinking it is too 
> much overhead to be registering classes at every request.

You mean you are creating a SessionFactory for _every_ request? This is 
WAY too much overhead. The SessionFactory should be a singleton, no 
discussion about that!

>
> I'm just very confused :)

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

http://hibernate.org/Documentation/OpenSessionInView

	Ugo

-- 
Ugo Cei - http://agylen.com/blojsom/blog/

Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
I am at the start of a big ol project here heh heh. I would love to make 
it so - I have made a class bugSearch, with methods to lookup by status, 
etc, as well as take an example bean and do a full search by.


        // Create The Form
        var form = new Form("forms/bugSearchModel.xml");

        // Set Some Form Specific Text Fields
        var model = form.getWidget();
        model.buttonText = "Search";
        model.title = "Search Bug Database";

        form.showForm("internal/show-form/bugSearch");

        // 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 ");}

        var bugSearch = new Packages.com.BugSearch(hs);

        var eBug=new Packages.com.kismetsoftware.insecticide.Bug;
        if (model.projectId.getValue() != null)
        {
            eBug.project=hs.find("from Project WHERE 
id='"+model.projectId.getValue()+"'").get(0);
        }
        eBug.severity=model.severity.getValue();
        eBug.priority=model.priority.getValue();
        eBug.opsys=model.opsys.getValue();
        eBug.description=model.description.getValue();
        eBug.status=model.status.getValue();
        eBug.resolution=model.resolution.getValue();
        var bug = bugSearch.findBugs(eBug);

        // Clean Up Our Mess :)
        hs.flush();
        hs.close();
        cocoon.releaseComponent(factory);

        // Send The User Their Result
        cocoon.sendPage("internal/generate-view/bug_summary", {title : 
"Bugs",bug : bug});

so I guess my next question would be : would you just forget having a 
hibernate factory as a cocoon component? ie, just have yet another class 
like package.hibernateFactoryImpl? see I'm thinking it is too much 
overhead to be registering classes at every request.

I'm just very confused :)

Gregor J. Rothfuss wrote:

> WHIRLYCOTT wrote:
>
>> If you will allow me to offer to you a thought which is only slightly 
>> related to your original question, I would strongly encourage you to 
>> move all of that transactional persistence stuff behind a facade a 
>> for a few reasons, listed in no particular order:
>>
>> 1) you'll be able to write junit tests to see if the backend is behaving
>> 2) decouple your application layers into something resembling MVC
>> 3) If you decide one day to use something other than Hibernate, you 
>> will  be able to rip out the persistence mechanism without touching 
>> your flow controllers
>> 4) you can reuse your facade in other applications
>
>
> just to chime in here: phil used this technique to share these facades 
> between struts and cocoon. very useful if you live in a heterogenous 
> world..
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by "Gregor J. Rothfuss" <gr...@apache.org>.
WHIRLYCOTT wrote:
> If you will allow me to offer to you a thought which is only slightly 
> related to your original question, I would strongly encourage you to 
> move all of that transactional persistence stuff behind a facade a for a 
> few reasons, listed in no particular order:
> 
> 1) you'll be able to write junit tests to see if the backend is behaving
> 2) decouple your application layers into something resembling MVC
> 3) If you decide one day to use something other than Hibernate, you will 
>  be able to rip out the persistence mechanism without touching your flow 
> controllers
> 4) you can reuse your facade in other applications

just to chime in here: phil used this technique to share these facades 
between struts and cocoon. very useful if you live in a heterogenous world..


-- 
Gregor J. Rothfuss
COO, Wyona       Content Management Solutions    http://wyona.com
Apache Lenya                              http://lenya.apache.org
gregor.rothfuss@wyona.com                       gregor@apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Brent Johnson <bl...@gmail.com>.
I agree - I always write objects specifically designed to be used in
flow that handle all the actual Hibernate calls.  The great thing
about this is I can write test classes (or use JUnit as was suggested)
that test the classes themselves to make sure the Hibernate calls are
working correctly.

But glad you got the problem worked out.

- Brent

On Wed, 26 Jan 2005 14:10:58 -0500, WHIRLYCOTT <ph...@whirlycott.com> wrote:
> If you will allow me to offer to you a thought which is only slightly
> related to your original question, I would strongly encourage you to
> move all of that transactional persistence stuff behind a facade a for a
> few reasons, listed in no particular order:
> 
> 1) you'll be able to write junit tests to see if the backend is behaving
> 2) decouple your application layers into something resembling MVC
> 3) If you decide one day to use something other than Hibernate, you will
>   be able to rip out the persistence mechanism without touching your
> flow controllers
> 4) you can reuse your facade in other applications
> 
> etc.
> 
> All I am suggesting to you is that your flow code goes against a facade
> like this:
> 
>         ...
>         var myFacade = new ApplicationFacade();
>         var bug = myFacade.getBugsByStatus('UNCONFIRMED');
>         myFacade.close();
>         ...
> 
> The flow doesn't know or care that Hibernate/OJB/SOAP/JDO/JDBC/foo is
> behind the facade, which is precisely the point.  Business logic
> shouldn't live in flow.
> 
> phil.
> 
> JD Daniels wrote:
> > Hi all,
> >
> > I am trying to add criteria inside a flowscript. Here is what i think
> > should work:
> >
> > 1        var criteria = hs.createCriteria(Bug.class);
> > 2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
> > 3        var bug = criteria.list();
> >
> > this spits out : missing name after . operator on line 1
> >
> > I have tried variations of switching to the the [""] syntax of calling
> > methods, but while they fix the error, criteria is always undefined.
> >
> > Anyone have insight into how i can call these methods in flow?
> >
> > full function:
> >
> > function search_bug()
> > {
> >        // Create The Form
> >        var form = new Form("forms/bugSearchModel.xml");
> >
> >        // Set Some Form Specific Text Fields
> >        var model = form.getWidget();
> >        model.buttonText = "Search";
> >        model.title = "Search Bug Database";
> >
> >        form.showForm("internal/show-form/bugSearch");
> >
> >        // 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 ");}
> >
> >        // This is problem Line:
> >        var criteria = hs.createCriteria(Bug.class);
> >        criteria.add(Expression.eq("status", "UNCONFIRMED"));
> >        var bug = criteria.list();
> >
> >        // Clean Up Our Mess :)
> >        hs.flush();
> >        hs.close();
> >        cocoon.releaseComponent(factory);
> >
> >        // Send The User Their Result
> >        cocoon.sendPage("internal/generate-view/bug_summary", {title :
> > "Bugs",bug : bug});
> > }
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> > For additional commands, e-mail: users-help@cocoon.apache.org
> >
> 
> --
>                                    Whirlycott
>                                    Philip Jacob
>                                    phil@whirlycott.com
>                                    http://www.whirlycott.com/phil/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
If you will allow me to offer to you a thought which is only slightly 
related to your original question, I would strongly encourage you to 
move all of that transactional persistence stuff behind a facade a for a 
few reasons, listed in no particular order:

1) you'll be able to write junit tests to see if the backend is behaving
2) decouple your application layers into something resembling MVC
3) If you decide one day to use something other than Hibernate, you will 
  be able to rip out the persistence mechanism without touching your 
flow controllers
4) you can reuse your facade in other applications

etc.

All I am suggesting to you is that your flow code goes against a facade 
like this:

	...
	var myFacade = new ApplicationFacade();
	var bug = myFacade.getBugsByStatus('UNCONFIRMED');
	myFacade.close();
	...

The flow doesn't know or care that Hibernate/OJB/SOAP/JDO/JDBC/foo is 
behind the facade, which is precisely the point.  Business logic 
shouldn't live in flow.

phil.

JD Daniels wrote:
> Hi all,
> 
> I am trying to add criteria inside a flowscript. Here is what i think 
> should work:
> 
> 1        var criteria = hs.createCriteria(Bug.class);
> 2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
> 3        var bug = criteria.list();
> 
> this spits out : missing name after . operator on line 1
> 
> I have tried variations of switching to the the [""] syntax of calling 
> methods, but while they fix the error, criteria is always undefined.
> 
> Anyone have insight into how i can call these methods in flow?
> 
> full function:
> 
> function search_bug()
> {
>        // Create The Form
>        var form = new Form("forms/bugSearchModel.xml");
> 
>        // Set Some Form Specific Text Fields
>        var model = form.getWidget();
>        model.buttonText = "Search";
>        model.title = "Search Bug Database";
> 
>        form.showForm("internal/show-form/bugSearch");
> 
>        // 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 ");}
> 
>        // This is problem Line:
>        var criteria = hs.createCriteria(Bug.class);
>        criteria.add(Expression.eq("status", "UNCONFIRMED"));
>        var bug = criteria.list();
> 
>        // Clean Up Our Mess :)
>        hs.flush();
>        hs.close();
>        cocoon.releaseComponent(factory);
> 
>        // Send The User Their Result
>        cocoon.sendPage("internal/generate-view/bug_summary", {title : 
> "Bugs",bug : bug});
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Rolf Kulemann <ro...@apache.org>.
On Wed, 2005-01-26 at 19:23, Brent Johnson wrote:
> I've run into this error before.  This usually means that some
> function used is a Javascript builtin function (or statement).  So
> odds are, either add() or eq() are functions or statements in
> Javascript.
> 
> I ran into this problem with a Java method I called delete().  So I'm
> guessing that your add() call is the problem.  Change the call to
> something like this and see if it works:
> 
> criteria["add"](Expression.eq("status", "UNCONFIRMED"));

IMHO, it is bad design to access persistence direct from flow.
I would prefer a command class (J2EE command pattern) which has several
getters and setters and an exceute method. That command class exceutes
the persistence calls. The result, if any, is available via the getters.
This would also enable you to use the wrapped business logic in other
web app frameworks than cocoon.

var myCommand = new MyCommand();
myCommand.setParam1(something);
myCommand.set*(*);
myCommand.execute();

var someResult = myCommand.getResultProp1();

Do not misuse flow :)

-- 
Rolf Kulemann


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


[SOLVED] Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
        var criteria = 
hs["createCriteria"](full.package.name.insecticide.Bug);
        
criteria["add"](Packages.net.sf.hibernate.expression.Expression.eq("status", 
"UNCONFIRMED"));
        var bug = criteria.list();

seems to work .. I guess flow doesn't like the .class, but it seems it 
is not needed.

JD


JD Daniels wrote:

> Yeah thats the same problem I'm having I think - except it is the line 
> above it is dying on:
>
> var criteria = hs["createCriteria"](Bug[class]); - Identifier is a 
> reserved word
> var criteria = hs["createCriteria"](Bug.class);  - missing name after 
> . operator
>
> arg
>
>
> Brent Johnson wrote:
>
>> I've run into this error before.  This usually means that some
>> function used is a Javascript builtin function (or statement).  So
>> odds are, either add() or eq() are functions or statements in
>> Javascript.
>>
>> I ran into this problem with a Java method I called delete().  So I'm
>> guessing that your add() call is the problem.  Change the call to
>> something like this and see if it works:
>>
>> criteria["add"](Expression.eq("status", "UNCONFIRMED"));
>>
>> - Brent
>>
>> On Wed, 26 Jan 2005 10:14:12 -0500, JD Daniels 
>> <jd...@kismetsoftware.com> wrote:
>>  
>>
>>> Hi all,
>>>
>>> I am trying to add criteria inside a flowscript. Here is what i think
>>> should work:
>>>
>>> 1        var criteria = hs.createCriteria(Bug.class);
>>> 2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
>>> 3        var bug = criteria.list();
>>>
>>> this spits out : missing name after . operator on line 1
>>>
>>> I have tried variations of switching to the the [""] syntax of calling
>>> methods, but while they fix the error, criteria is always undefined.
>>>
>>> Anyone have insight into how i can call these methods in flow?
>>>
>>> full function:
>>>
>>> function search_bug()
>>> {
>>>        // Create The Form
>>>        var form = new Form("forms/bugSearchModel.xml");
>>>
>>>        // Set Some Form Specific Text Fields
>>>        var model = form.getWidget();
>>>        model.buttonText = "Search";
>>>        model.title = "Search Bug Database";
>>>
>>>        form.showForm("internal/show-form/bugSearch");
>>>
>>>        // 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 ");}
>>>
>>>        // This is problem Line:
>>>        var criteria = hs.createCriteria(Bug.class);
>>>        criteria.add(Expression.eq("status", "UNCONFIRMED"));
>>>        var bug = criteria.list();
>>>
>>>        // Clean Up Our Mess :)
>>>        hs.flush();
>>>        hs.close();
>>>        cocoon.releaseComponent(factory);
>>>
>>>        // Send The User Their Result
>>>        cocoon.sendPage("internal/generate-view/bug_summary", {title :
>>> "Bugs",bug : bug});
>>> }
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>> For additional commands, e-mail: users-help@cocoon.apache.org
>>>
>>>
>>>   
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>> For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>>
>>  
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by JD Daniels <jd...@kismetsoftware.com>.
Yeah thats the same problem I'm having I think - except it is the line 
above it is dying on:

var criteria = hs["createCriteria"](Bug[class]); - Identifier is a 
reserved word
var criteria = hs["createCriteria"](Bug.class);  - missing name after . 
operator

arg


Brent Johnson wrote:

>I've run into this error before.  This usually means that some
>function used is a Javascript builtin function (or statement).  So
>odds are, either add() or eq() are functions or statements in
>Javascript.
>
>I ran into this problem with a Java method I called delete().  So I'm
>guessing that your add() call is the problem.  Change the call to
>something like this and see if it works:
>
>criteria["add"](Expression.eq("status", "UNCONFIRMED"));
>
>- Brent
>
>On Wed, 26 Jan 2005 10:14:12 -0500, JD Daniels <jd...@kismetsoftware.com> wrote:
>  
>
>>Hi all,
>>
>>I am trying to add criteria inside a flowscript. Here is what i think
>>should work:
>>
>>1        var criteria = hs.createCriteria(Bug.class);
>>2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
>>3        var bug = criteria.list();
>>
>>this spits out : missing name after . operator on line 1
>>
>>I have tried variations of switching to the the [""] syntax of calling
>>methods, but while they fix the error, criteria is always undefined.
>>
>>Anyone have insight into how i can call these methods in flow?
>>
>>full function:
>>
>>function search_bug()
>>{
>>        // Create The Form
>>        var form = new Form("forms/bugSearchModel.xml");
>>
>>        // Set Some Form Specific Text Fields
>>        var model = form.getWidget();
>>        model.buttonText = "Search";
>>        model.title = "Search Bug Database";
>>
>>        form.showForm("internal/show-form/bugSearch");
>>
>>        // 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 ");}
>>
>>        // This is problem Line:
>>        var criteria = hs.createCriteria(Bug.class);
>>        criteria.add(Expression.eq("status", "UNCONFIRMED"));
>>        var bug = criteria.list();
>>
>>        // Clean Up Our Mess :)
>>        hs.flush();
>>        hs.close();
>>        cocoon.releaseComponent(factory);
>>
>>        // Send The User Their Result
>>        cocoon.sendPage("internal/generate-view/bug_summary", {title :
>>"Bugs",bug : bug});
>>}
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>>For additional commands, e-mail: users-help@cocoon.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>
>
>
>  
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: [flow] Hibernate createCriteria syntax help?

Posted by Brent Johnson <bl...@gmail.com>.
I've run into this error before.  This usually means that some
function used is a Javascript builtin function (or statement).  So
odds are, either add() or eq() are functions or statements in
Javascript.

I ran into this problem with a Java method I called delete().  So I'm
guessing that your add() call is the problem.  Change the call to
something like this and see if it works:

criteria["add"](Expression.eq("status", "UNCONFIRMED"));

- Brent

On Wed, 26 Jan 2005 10:14:12 -0500, JD Daniels <jd...@kismetsoftware.com> wrote:
> Hi all,
> 
> I am trying to add criteria inside a flowscript. Here is what i think
> should work:
> 
> 1        var criteria = hs.createCriteria(Bug.class);
> 2       criteria.add(Expression.eq("status", "UNCONFIRMED"));
> 3        var bug = criteria.list();
> 
> this spits out : missing name after . operator on line 1
> 
> I have tried variations of switching to the the [""] syntax of calling
> methods, but while they fix the error, criteria is always undefined.
> 
> Anyone have insight into how i can call these methods in flow?
> 
> full function:
> 
> function search_bug()
> {
>         // Create The Form
>         var form = new Form("forms/bugSearchModel.xml");
> 
>         // Set Some Form Specific Text Fields
>         var model = form.getWidget();
>         model.buttonText = "Search";
>         model.title = "Search Bug Database";
> 
>         form.showForm("internal/show-form/bugSearch");
> 
>         // 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 ");}
> 
>         // This is problem Line:
>         var criteria = hs.createCriteria(Bug.class);
>         criteria.add(Expression.eq("status", "UNCONFIRMED"));
>         var bug = criteria.list();
> 
>         // Clean Up Our Mess :)
>         hs.flush();
>         hs.close();
>         cocoon.releaseComponent(factory);
> 
>         // Send The User Their Result
>         cocoon.sendPage("internal/generate-view/bug_summary", {title :
> "Bugs",bug : bug});
> }
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org