Anyone familiar with this ... user-to-role relationship

3 messages Options
Embed this post
Permalink
David Whitehurst

Anyone familiar with this ... user-to-role relationship

Reply Threaded More More options
Print post
Permalink
Hi:

I'm doing reference data exactly like user-role but without predefined data.  Load object has Attribute(s)  When the save occurs, the relationship is not fulfilled in the load_attribute table (hence two id's per row).  The mapping is provided below the test.  Is sample data required to make this work.  The table load and load_attribute are created.

My test ...


    public void testAddLoadAttribute() throws Exception {

        Load load = dao.get(-1L);
        assertEquals(0, load.getAttributes().size()); // was 1 expecting pre-load

        Attribute attribute = adao.getAttributeByName("Chains");
        load.addAttribute(attribute);
        load = dao.save(load);
        flush();

        load = dao.get(-1L);
        assertEquals(1, load.getAttributes().size());

Load.java

...
    private Set<Attribute> attributes = new HashSet<Attribute>();
   
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(
            name="load_attribute",
            joinColumns = { @JoinColumn( name="load_id") },
            inverseJoinColumns = @JoinColumn( name="attribute_id")
    )
    public Set<Attribute> getAttributes() {
        return attributes;
    }

    public void setAttributes(Set<Attribute> attributes) {
        this.attributes = attributes;
    }

dusty

Re: Anyone familiar with this ... user-to-role relationship

Reply Threaded More More options
Print post
Permalink
Dave,

What does load.addAttribute() look like?  Does it maintain both sides?

-D

On Jan 21, 2009, at 9:25 AM, David Whitehurst wrote:

> Hi:
>
> I'm doing reference data exactly like user-role but without  
> predefined data.  Load object has Attribute(s)  When the save  
> occurs, the relationship is not fulfilled in the load_attribute  
> table (hence two id's per row).  The mapping is provided below the  
> test.  Is sample data required to make this work.  The table load  
> and load_attribute are created.
>
> My test ...
>
>
>     public void testAddLoadAttribute() throws Exception {
>
>         Load load = dao.get(-1L);
>         assertEquals(0, load.getAttributes().size()); // was 1  
> expecting pre-load
>
>         Attribute attribute = adao.getAttributeByName("Chains");
>         load.addAttribute(attribute);
>         load = dao.save(load);
>         flush();
>
>         load = dao.get(-1L);
>         assertEquals(1, load.getAttributes().size());
>
> Load.java
>
> ...
>     private Set<Attribute> attributes = new HashSet<Attribute>();
>
>     @ManyToMany(fetch = FetchType.EAGER)
>     @JoinTable(
>             name="load_attribute",
>             joinColumns = { @JoinColumn( name="load_id") },
>             inverseJoinColumns = @JoinColumn( name="attribute_id")
>     )
>     public Set<Attribute> getAttributes() {
>         return attributes;
>     }
>
>     public void setAttributes(Set<Attribute> attributes) {
>         this.attributes = attributes;
>     }
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

David Whitehurst

Re: Anyone familiar with this ... user-to-role relationship

Reply Threaded More More options
Print post
Permalink
Dustin:

I got it working by doing my tables over and kicking off the mapping again.



David

On Wed, Jan 21, 2009 at 11:08 PM, DUSTIN PEARCE <[hidden email]> wrote:
Dave,

What does load.addAttribute() look like?  Does it maintain both sides?

-D


On Jan 21, 2009, at 9:25 AM, David Whitehurst wrote:

Hi:

I'm doing reference data exactly like user-role but without predefined data.  Load object has Attribute(s)  When the save occurs, the relationship is not fulfilled in the load_attribute table (hence two id's per row).  The mapping is provided below the test.  Is sample data required to make this work.  The table load and load_attribute are created.

My test ...


   public void testAddLoadAttribute() throws Exception {

       Load load = dao.get(-1L);
       assertEquals(0, load.getAttributes().size()); // was 1 expecting pre-load

       Attribute attribute = adao.getAttributeByName("Chains");
       load.addAttribute(attribute);
       load = dao.save(load);
       flush();

       load = dao.get(-1L);
       assertEquals(1, load.getAttributes().size());

Load.java

...
   private Set<Attribute> attributes = new HashSet<Attribute>();

   @ManyToMany(fetch = FetchType.EAGER)
   @JoinTable(
           name="load_attribute",
           joinColumns = { @JoinColumn( name="load_id") },
           inverseJoinColumns = @JoinColumn( name="attribute_id")
   )
   public Set<Attribute> getAttributes() {
       return attributes;
   }

   public void setAttributes(Set<Attribute> attributes) {
       this.attributes = attributes;
   }



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]