Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: CodeGenerator: finders on two columns
PostPosted: Mon Dec 15, 2003 10:09 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Is there a way to generate a finder on two columns?
fi:
<class
name="com.jada.jada.User"
table="user"
>
<id
name="id"
type="int"
column="id"
>
<generator class="assigned" />
</id>

<property
name="name"
type="java.lang.String"
column="loginname"
not-null="true"
length="20"
>
</property>
<property
name="surname"
type="java.lang.String"
column="name"
length="40"
/>
</class>

How do I generate a finder which looks like
from User as user where user.name=? and surname=?

BTW I don't understand what the documentation says about generating a joined query.
Can somebody explain this also?
Thax


Top
 Profile  
 
 Post subject: Want to enhance hbm2java - HibernateExt CVS does not compile
PostPosted: Mon Dec 15, 2003 5:01 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Hi guys.
I answered my self the question which I posted earlier: it is not supported (yet).
I think it would be really easy to introduce and I'm willing to contribute and write a patch.
I checked out the cvs (both hibernate and hibernateext) but hibernateext does not compile.
Isn't strange that the repository is not consistent? (Solly, filst time wolking on a opensoulce ploject)
I've checked the errors, a couple of missing constructors and a couple of setters/getters. Can somebody fix it? I don't want to mess with the current code.
Anyway, what's the procedure to submit a patch? jira?...maybe...but it is down currently.
Thanx
/robcos


Top
 Profile  
 
 Post subject: Re: Want to enhance hbm2java - HibernateExt CVS does not com
PostPosted: Mon Dec 15, 2003 5:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
robcos wrote:
Hi guys.
I answered my self the question which I posted earlier: it is not supported (yet).
I think it would be really easy to introduce and I'm willing to contribute and write a patch.
I checked out the cvs (both hibernate and hibernateext) but hibernateext does not compile.
Isn't strange that the repository is not consistent? (Solly, filst time wolking on a opensoulce ploject)
I've checked the errors, a couple of missing constructors and a couple of setters/getters. Can somebody fix it? I don't want to mess with the current code.
Anyway, what's the procedure to submit a patch? jira?...maybe...but it is down currently.
Thanx
/robcos


Huh ? Could you please show your compile errors ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Ant compilation errors
PostPosted: Mon Dec 15, 2003 6:09 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Here you are, from a fresh CVS snapshot.
Are you the mainteiner of the package?
Could be possible to have multiple metatags having the same attribute?
Someting like
Code:
        <meta attribute="finder-extra-field">customer</meta>
        <meta attribute="finder-extra-field">system</meta>

or would be to complex for the PropertyField class? Seems that somewhere we would need need a method like
Code:
getMetas
.


Code:
ant
Buildfile: build.xml
[robcos@lina tools]$ ls
bin  build  build.xml  changelog.txt  CVS  hibernate-2.1  lgpl.txt  lib  readme.txt  src
[robcos@lina tools]$ mv hibernate-2.1/ ..
[robcos@lina tools]$ mv hibernate-2.1/ /tmp/
[robcos@lina tools]$ ant jar
Buildfile: build.xml

init:
     [echo] Build Hibernate Tools-2.0.1 (2003-12-15 11:01:20)

compile:
    [javac] Compiling 31 source files to /tmp/HibernateExt/tools/build
    [javac] /tmp/HibernateExt/tools/src/java/net/sf/hibernate/tool/ddl2hbm/MapGenerator.java:113: cannot resolve symbol
    [javac] symbol  : constructor ClassName ()
    [javac] location: class net.sf.hibernate.tool.hbm2java.ClassName
    [javac]                             ClassName cName = new ClassName();
    [javac]                                                   ^
    [javac] /tmp/HibernateExt/tools/src/java/net/sf/hibernate/tool/ddl2hbm/MapGenerator.java:114: cannot resolve symbol
    [javac] symbol  : method setFullyQualifiedName (java.lang.String)
    [javac] location: class net.sf.hibernate.tool.hbm2java.ClassName
    [javac]                             cName.setFullyQualifiedName(getBaseClass());
    [javac]                                      ^
    [javac] /tmp/HibernateExt/tools/src/java/net/sf/hibernate/tool/ddl2hbm/MapGenerator.java:115: cannot resolve symbol
    [javac] symbol  : constructor ClassMapping (net.sf.hibernate.tool.hbm2java.ClassName,org.jdom.Element,org.apache.commons.collections.MultiHashMap)
    [javac] location: class net.sf.hibernate.tool.hbm2java.ClassMapping
    [javac]                             cmap = new ClassMapping(cName, jdomBuilder.build(classElement), new MultiHashMap());
    [javac]                                        ^
    [javac] /tmp/HibernateExt/tools/src/java/net/sf/hibernate/tool/ddl2hbm/MapGenerator.java:117: cannot resolve symbol
    [javac] symbol  : constructor ClassMapping (org.jdom.Element,org.apache.commons.collections.MultiHashMap)
    [javac] location: class net.sf.hibernate.tool.hbm2java.ClassMapping
    [javac]                     else cmap = new ClassMapping(jdomBuilder.build(classElement), new MultiHashMap());
    [javac]                                     ^
    [javac] /tmp/HibernateExt/tools/src/java/net/sf/hibernate/tool/ddl2hbm/MapGenerator.java:118: cannot resolve symbol
    [javac] symbol  : method getCanonicalName ()
    [javac] location: class net.sf.hibernate.tool.hbm2java.ClassMapping
    [javac]                     map.put(cmap.getCanonicalName(), cmap);
    [javac]                                     ^
    [javac] 5 errors

BUILD FAILED


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 6:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
Yes - i'm the hbm2java et.al. maintainer ;)

Multiple meta tags are already available.

Look at getMetaAttribs() or the other 8 methods on MappingElement related to meta tag ;)

And regarding the compile errors which is ONLY in ddl2hbm are in methods that soon will be deprecated :)

So, just ignore them (i'll remove them now, but you won't get'em before in about 24hours)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 6:47 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Very good.
Can you explain me how to submit a patch then?
Since I need this features for a project I'm working on I will make some changes very soon.
Please explain me everything, like "get a cvs account, checkout, change, commit" or please point me to some guidelines.
As maybe you have read, my idea is to generate finders like
"select from eg.A where a.x=X and a.y=Y"
where x and y are whatever properties of the class A.
Nowdays, you can only generate finders for one property.
My approach would be to use a mapping which looks like:

Code:
<property name="x">
<meta attribute="finder">findByXandY</meta>
<meta attribute="finder-extra-field">y</meta>
</property>


and should produce a finder like

Code:

public static List findByName(Session session, XObject theX, YObject theY ) throws SQLException, HibernateException {   

        String query = "select a from a" +
                " in class eg.A" +
                " where a.x= :X" +
                "' and a.y :Y";
                                                                                                                   
            Query q = session.createQuery(query);
            q.setEntity("X", theX);
            q.setEntity("Y", theY);
           
           return q.list();
}



maybe better formatted though :-D

What do you think?

/robcos


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 7:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
Looks find by me.

Previously the original FinderRenderer author submitted the following improvement: http://opensource.atlassian.com/project ... ?key=HB-48

Don't know if that's usefull, but there you go ;)

To submit patches simply make a patch and submit it via the JIRA.

So, "cvs checkout" anonymously as you have already done.
Make the change and create a patch, enter the JIRA and submit it ....simple and easy ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 7:37 pm 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
Great, thanx for your help.
I've notice that

Code:
<codegen>
    <meta attribute="implements">my.class</meta>
    <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
    <generate
        package="com.nmt.ehandel.finder"
        suffix="Finder"
        renderer="net.sf.hibernate.tool.hbm2java.FinderRenderer"/>
                                                                                                                           
    <meta attribute="session-method">
         com.whatever.SessionTable.getSessionTable().getSession();
         </meta>
</codegen>


seems not to work correctly. Neither the implements or the session-method seem to work. Do you have any other similar report?
The file is is read correctly since <generate package=.. is set correctly.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
Are you reporiting that it does not pick up the meta attributes from config.xml ?

weird .. i'll see if I have the same behavior in my end ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 4:18 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
hmm....that was a bad bug ;(

Can't understand how anyone haven't complained about the broken meta inheritance - probably noone is using it ;)

Well - it's fixed now. <meta> is now inherited from everywhere, as per the docs and my previous tests ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 16, 2003 7:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Doh - Now I have to fix the generation of Meta tags in Middlegen Plugin not to inherit the meta data :-).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 4:13 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:30 am
Posts: 35
Location: Stockholm
You know how it is to be a programmer :-D
Fix here...crash there!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 6:43 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8611
Location: Neuchatel, Switzerland (Danish)
david wrote:
Doh - Now I have to fix the generation of Meta tags in Middlegen Plugin not to inherit the meta data :-).


Well - only for some of it ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 17, 2003 9:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Fun Fun Fun :-)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 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.