GORM - object with list or set of strings?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

GORM - object with list or set of strings?

elvanor
Hello,

I am surprised that I was not able to find the answer to this question
on the online docs or in the ML.

I want to map a domain class that has a set (or list) of strings. Is
it possible to do that at all with GORM? I checked and Hibernate can
do this without problem (although I think it implies the use of an
additional SQL table).

If someone gives me an useful answer I will update the Grails wiki.

Thanks,

Jean-Noel

ps: of course I could put the string in another domain class and have
an association to these, but thatś not the point...
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

Marcos Silva Pereira
GORM does not maps elements yet. You must do this mapping using Hibernate:

public class Directory {

    Set filenames;

    ...
}

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.foo.bar.Directory">

        <set name="filenames" table="filenames">
            <key column="directory"/>
            <element column="filename" type="java.lang.String"/>
        </set>

    </class>
</hibernate-mapping>

Kind Regards

On 8/20/07, Jean-Noël Rivasseau <[hidden email]> wrote:
Hello,

I am surprised that I was not able to find the answer to this question
on the online docs or in the ML.

I want to map a domain class that has a set (or list) of strings. Is
it possible to do that at all with GORM? I checked and Hibernate can
do this without problem (although I think it implies the use of an
additional SQL table).

If someone gives me an useful answer I will update the Grails wiki.

Thanks,

Jean-Noel

ps: of course I could put the string in another domain class and have
an association to these, but thatś not the point...



--
Marcos Silva Pereira
http://marcospereira.wordpress.com
"You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

elvanor
Hello

Is this possible to do this mapping using Hibernate annotations (on
Groovy files though, so I don't know if this works) rather than XML?

Is is planned to add this feature to GORM?

Thanks

Jean-Noel

On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:

> GORM does not maps elements yet. You must do this mapping using Hibernate:
>
> public class Directory {
>
>     Set filenames;
>
>     ...
> }
>
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
>     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
>
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>  <hibernate-mapping>
>     <class name="com.foo.bar.Directory">
>
>         <set name="filenames" table="filenames">
>             <key column="directory"/>
>             <element column="filename" type="java.lang.String"/>
>         </set>
>
>     </class>
> </hibernate-mapping>
>
> Kind Regards
>
>
>  On 8/20/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello,
> >
> > I am surprised that I was not able to find the answer to this question
> > on the online docs or in the ML.
> >
> > I want to map a domain class that has a set (or list) of strings. Is
> > it possible to do that at all with GORM? I checked and Hibernate can
> > do this without problem (although I think it implies the use of an
> > additional SQL table).
> >
> > If someone gives me an useful answer I will update the Grails wiki.
> >
> > Thanks,
> >
> > Jean-Noel
> >
> > ps: of course I could put the string in another domain class and have
> > an association to these, but thatś not the point...
> >
>
>
>
> --
> Marcos Silva Pereira
> http://marcospereira.wordpress.com
> "You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

Marcos Silva Pereira
Jean,

Yes, you could use some custom hibernate annotations to do this mapping. See CollectionOfElements annotation and the manual about "Collection of element or composite elements". :-)

Kind Regards

On 8/21/07, Jean-Noël Rivasseau <[hidden email]> wrote:
Hello

Is this possible to do this mapping using Hibernate annotations (on
Groovy files though, so I don't know if this works) rather than XML?

Is is planned to add this feature to GORM?

Thanks

Jean-Noel

On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:
> GORM does not maps elements yet. You must do this mapping using Hibernate:
>

> public class Directory {
>
>     Set filenames;
>
>     ...
> }
>
> <?xml version="1.0"?>
> <!DOCTYPE hibernate-mapping PUBLIC
>     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
>
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
>  <hibernate-mapping>
>     <class name=" com.foo.bar.Directory">
>
>         <set name="filenames" table="filenames">
>             <key column="directory"/>
>             <element column="filename" type=" java.lang.String"/>
>         </set>
>
>     </class>
> </hibernate-mapping>
>
> Kind Regards
>
>
>  On 8/20/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello,
> >
> > I am surprised that I was not able to find the answer to this question
> > on the online docs or in the ML.
> >
> > I want to map a domain class that has a set (or list) of strings. Is
> > it possible to do that at all with GORM? I checked and Hibernate can
> > do this without problem (although I think it implies the use of an
> > additional SQL table).
> >
> > If someone gives me an useful answer I will update the Grails wiki.
> >
> > Thanks,
> >
> > Jean-Noel
> >
> > ps: of course I could put the string in another domain class and have
> > an association to these, but thatś not the point...
> >
>
>
>
> --
> Marcos Silva Pereira
> http://marcospereira.wordpress.com
> "You only live once.", James Brown



--
Marcos Silva Pereira
http://marcospereira.wordpress.com
"You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

elvanor
Hi, thanks for the reply. I've tried to use Hibernate annotations in
my Groovy domain class but ran into a number of problems. I will make
a separate thread for that

Jean-Noël

On 8/21/07, Marcos Silva Pereira <[hidden email]> wrote:

> Jean,
>
> Yes, you could use some custom hibernate annotations to do this mapping. See
> CollectionOfElements annotation and the manual about "Collection of element
> or composite elements". :-)
>
> Kind Regards
>
>
> On 8/21/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello
> >
> > Is this possible to do this mapping using Hibernate annotations (on
> > Groovy files though, so I don't know if this works) rather than XML?
> >
> > Is is planned to add this feature to GORM?
> >
> > Thanks
> >
> > Jean-Noel
> >
> > On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:
> > > GORM does not maps elements yet. You must do this mapping using
> Hibernate:
> > >
> > > public class Directory {
> > >
> > >     Set filenames;
> > >
> > >     ...
> > > }
> > >
> > > <?xml version="1.0"?>
> > > <!DOCTYPE hibernate-mapping PUBLIC
> > >     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> > >
> > >
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> > >  <hibernate-mapping>
> > >     <class name=" com.foo.bar.Directory">
> > >
> > >         <set name="filenames" table="filenames">
> > >             <key column="directory"/>
> > >             <element column="filename" type=" java.lang.String"/>
> > >         </set>
> > >
> > >     </class>
> > > </hibernate-mapping>
> > >
> > > Kind Regards
> > >
> > >
> > >  On 8/20/07, Jean-Noël Rivasseau < [hidden email]> wrote:
> > > > Hello,
> > > >
> > > > I am surprised that I was not able to find the answer to this question
> > > > on the online docs or in the ML.
> > > >
> > > > I want to map a domain class that has a set (or list) of strings. Is
> > > > it possible to do that at all with GORM? I checked and Hibernate can
> > > > do this without problem (although I think it implies the use of an
> > > > additional SQL table).
> > > >
> > > > If someone gives me an useful answer I will update the Grails wiki.
> > > >
> > > > Thanks,
> > > >
> > > > Jean-Noel
> > > >
> > > > ps: of course I could put the string in another domain class and have
> > > > an association to these, but thatś not the point...
> > > >
> > >
> > >
> > >
> > > --
> > > Marcos Silva Pereira
> > > http://marcospereira.wordpress.com
> > > "You only live once.", James Brown
> >
>
>
>
> --
>
> Marcos Silva Pereira
> http://marcospereira.wordpress.com
> "You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

Marcos Silva Pereira
Jean, as far as I know, you must use annotations in Java classes instead in Groovy domain classes.  Groovy 1.1 will support annotations and Grails 1.0 will support JPA (see the Roadmap - http://grails.codehaus.org/Roadmap).

Kind Regards

On 8/22/07, Jean-Noël Rivasseau <[hidden email] > wrote:
Hi, thanks for the reply. I've tried to use Hibernate annotations in
my Groovy domain class but ran into a number of problems. I will make
a separate thread for that

Jean-Noël

On 8/21/07, Marcos Silva Pereira <[hidden email]> wrote:

> Jean,
>
> Yes, you could use some custom hibernate annotations to do this mapping. See
> CollectionOfElements annotation and the manual about "Collection of element
> or composite elements". :-)
>
> Kind Regards
>
>
> On 8/21/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > Hello
> >
> > Is this possible to do this mapping using Hibernate annotations (on
> > Groovy files though, so I don't know if this works) rather than XML?
> >
> > Is is planned to add this feature to GORM?
> >
> > Thanks
> >
> > Jean-Noel
> >
> > On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:
> > > GORM does not maps elements yet. You must do this mapping using
> Hibernate:
> > >
> > > public class Directory {
> > >
> > >     Set filenames;
> > >
> > >     ...
> > > }
> > >
> > > <?xml version="1.0"?>

> > > <!DOCTYPE hibernate-mapping PUBLIC
> > >     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> > >
> > >
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> > >  <hibernate-mapping>
> > >     <class name=" com.foo.bar.Directory">
> > >
> > >         <set name="filenames" table="filenames">
> > >             <key column="directory"/>
> > >             <element column="filename" type=" java.lang.String"/>
> > >         </set>
> > >
> > >     </class>
> > > </hibernate-mapping>
> > >
> > > Kind Regards
> > >
> > >
> > >  On 8/20/07, Jean-Noël Rivasseau < [hidden email]> wrote:
> > > > Hello,
> > > >
> > > > I am surprised that I was not able to find the answer to this question
> > > > on the online docs or in the ML.
> > > >
> > > > I want to map a domain class that has a set (or list) of strings. Is
> > > > it possible to do that at all with GORM? I checked and Hibernate can
> > > > do this without problem (although I think it implies the use of an
> > > > additional SQL table).
> > > >
> > > > If someone gives me an useful answer I will update the Grails wiki.
> > > >
> > > > Thanks,
> > > >
> > > > Jean-Noel
> > > >
> > > > ps: of course I could put the string in another domain class and have
> > > > an association to these, but thatś not the point...
> > > >
> > >
> > >
> > >
> > > --
> > > Marcos Silva Pereira
> > > http://marcospereira.wordpress.com
> > > "You only live once.", James Brown
> >
>
>
>
> --
>
> Marcos Silva Pereira
> http://marcospereira.wordpress.com
> "You only live once.", James Brown



--
Marcos Silva Pereira
http://marcospereira.wordpress.com
"You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

elvanor
Groovy 1.1-beta already supports some kind of annotations. I am trying
to see if the improvements in 0.6 will help me achieve what I want.

On 8/22/07, Marcos Silva Pereira <[hidden email]> wrote:

> Jean, as far as I know, you must use annotations in Java classes instead in
> Groovy domain classes.  Groovy 1.1 will support annotations and Grails 1.0
> will support JPA (see the Roadmap -
> http://grails.codehaus.org/Roadmap).
>
> Kind Regards
>
>
> On 8/22/07, Jean-Noël Rivasseau <[hidden email] > wrote:
> > Hi, thanks for the reply. I've tried to use Hibernate annotations in
> > my Groovy domain class but ran into a number of problems. I will make
> > a separate thread for that
> >
> > Jean-Noël
> >
> > On 8/21/07, Marcos Silva Pereira <[hidden email] > wrote:
> > > Jean,
> > >
> > > Yes, you could use some custom hibernate annotations to do this mapping.
> See
> > > CollectionOfElements annotation and the manual about "Collection of
> element
> > > or composite elements". :-)
> > >
> > > Kind Regards
> > >
> > >
> > > On 8/21/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > > > Hello
> > > >
> > > > Is this possible to do this mapping using Hibernate annotations (on
> > > > Groovy files though, so I don't know if this works) rather than XML?
> > > >
> > > > Is is planned to add this feature to GORM?
> > > >
> > > > Thanks
> > > >
> > > > Jean-Noel
> > > >
> > > > On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:
> > > > > GORM does not maps elements yet. You must do this mapping using
> > > Hibernate:
> > > > >
> > > > > public class Directory {
> > > > >
> > > > >     Set filenames;
> > > > >
> > > > >     ...
> > > > > }
> > > > >
> > > > > <?xml version="1.0"?>
> > > > > <!DOCTYPE hibernate-mapping PUBLIC
> > > > >     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> > > > >
> > > > >
> > >
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> > > > >  <hibernate-mapping>
> > > > >     <class name=" com.foo.bar.Directory">
> > > > >
> > > > >         <set name="filenames" table="filenames">
> > > > >             <key column="directory"/>
> > > > >             <element column="filename" type=" java.lang.String"/>
> > > > >         </set>
> > > > >
> > > > >     </class>
> > > > > </hibernate-mapping>
> > > > >
> > > > > Kind Regards
> > > > >
> > > > >
> > > > >  On 8/20/07, Jean-Noël Rivasseau < [hidden email]> wrote:
> > > > > > Hello,
> > > > > >
> > > > > > I am surprised that I was not able to find the answer to this
> question
> > > > > > on the online docs or in the ML.
> > > > > >
> > > > > > I want to map a domain class that has a set (or list) of strings.
> Is
> > > > > > it possible to do that at all with GORM? I checked and Hibernate
> can
> > > > > > do this without problem (although I think it implies the use of an
> > > > > > additional SQL table).
> > > > > >
> > > > > > If someone gives me an useful answer I will update the Grails
> wiki.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Jean-Noel
> > > > > >
> > > > > > ps: of course I could put the string in another domain class and
> have
> > > > > > an association to these, but thatś not the point...
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Marcos Silva Pereira
> > > > > http://marcospereira.wordpress.com
> > > > > "You only live once.", James Brown
> > > >
> > >
> > >
> > >
> > > --
> > >
> > > Marcos Silva Pereira
> > > http://marcospereira.wordpress.com
> > > "You only live once.", James Brown
> >
>
>
>
> --
>
> Marcos Silva Pereira
>  http://marcospereira.wordpress.com
> "You only live once.", James Brown
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

graemer
In reply to this post by Marcos Silva Pereira
I've updated the Roadmap, we are scaling back our goals for 1.0 to
make sure we deliver a stable release. The focust will be on
stability, project infastructure and plug-in system refinements until
1.0

After 1.0 we'll deal with things like JPA, probably as a plugin

Cheers

On 8/22/07, Marcos Silva Pereira <[hidden email]> wrote:

> Jean, as far as I know, you must use annotations in Java classes instead in
> Groovy domain classes.  Groovy 1.1 will support annotations and Grails 1.0
> will support JPA (see the Roadmap -
> http://grails.codehaus.org/Roadmap).
>
> Kind Regards
>
>
> On 8/22/07, Jean-Noël Rivasseau <[hidden email] > wrote:
> > Hi, thanks for the reply. I've tried to use Hibernate annotations in
> > my Groovy domain class but ran into a number of problems. I will make
> > a separate thread for that
> >
> > Jean-Noël
> >
> > On 8/21/07, Marcos Silva Pereira <[hidden email] > wrote:
> > > Jean,
> > >
> > > Yes, you could use some custom hibernate annotations to do this mapping.
> See
> > > CollectionOfElements annotation and the manual about "Collection of
> element
> > > or composite elements". :-)
> > >
> > > Kind Regards
> > >
> > >
> > > On 8/21/07, Jean-Noël Rivasseau <[hidden email]> wrote:
> > > > Hello
> > > >
> > > > Is this possible to do this mapping using Hibernate annotations (on
> > > > Groovy files though, so I don't know if this works) rather than XML?
> > > >
> > > > Is is planned to add this feature to GORM?
> > > >
> > > > Thanks
> > > >
> > > > Jean-Noel
> > > >
> > > > On 8/20/07, Marcos Silva Pereira <[hidden email]> wrote:
> > > > > GORM does not maps elements yet. You must do this mapping using
> > > Hibernate:
> > > > >
> > > > > public class Directory {
> > > > >
> > > > >     Set filenames;
> > > > >
> > > > >     ...
> > > > > }
> > > > >
> > > > > <?xml version="1.0"?>
> > > > > <!DOCTYPE hibernate-mapping PUBLIC
> > > > >     "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
> > > > >
> > > > >
> > >
> "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
> > > > >  <hibernate-mapping>
> > > > >     <class name=" com.foo.bar.Directory">
> > > > >
> > > > >         <set name="filenames" table="filenames">
> > > > >             <key column="directory"/>
> > > > >             <element column="filename" type=" java.lang.String"/>
> > > > >         </set>
> > > > >
> > > > >     </class>
> > > > > </hibernate-mapping>
> > > > >
> > > > > Kind Regards
> > > > >
> > > > >
> > > > >  On 8/20/07, Jean-Noël Rivasseau < [hidden email]> wrote:
> > > > > > Hello,
> > > > > >
> > > > > > I am surprised that I was not able to find the answer to this
> question
> > > > > > on the online docs or in the ML.
> > > > > >
> > > > > > I want to map a domain class that has a set (or list) of strings.
> Is
> > > > > > it possible to do that at all with GORM? I checked and Hibernate
> can
> > > > > > do this without problem (although I think it implies the use of an
> > > > > > additional SQL table).
> > > > > >
> > > > > > If someone gives me an useful answer I will update the Grails
> wiki.
> > > > > >
> > > > > > Thanks,
> > > > > >
> > > > > > Jean-Noel
> > > > > >
> > > > > > ps: of course I could put the string in another domain class and
> have
> > > > > > an association to these, but thatś not the point...
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > Marcos Silva Pereira
> > > > > http://marcospereira.wordpress.com
> > > > > "You only live once.", James Brown
> > > >
> > >
> > >
> > >
> > > --
> > >
> > > Marcos Silva Pereira
> > > http://marcospereira.wordpress.com
> > > "You only live once.", James Brown
> >
>
>
>
> --
>
> Marcos Silva Pereira
>  http://marcospereira.wordpress.com
> "You only live once.", James Brown


--
Graeme Rocher
Grails Project Lead
http://grails.org
Reply | Threaded
Open this post in threaded view
|

Re: GORM - object with list or set of strings?

frankie kuo
In reply to this post by elvanor
I have new question about this, how to create criteria for this kind attribute:

 for example:

   class Book {
       static hasMany = [references:String]
       Set references
   }


 when we need use some reference string as a search condition, how to find out books with these reference string?
------------------------------------------------------------------------------------------------
 def books = Book.createCriteria().list() {
   
    references {
       ilike(?, 'grails user guide')
    }
 }

 the above code will not work ... is anyone can give suggestions?