Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

At least one attribute with a value appears to be required #42

Open
brucent opened this issue Jul 15, 2011 · 0 comments
Open

At least one attribute with a value appears to be required #42

brucent opened this issue Jul 15, 2011 · 0 comments

Comments

@brucent
Copy link

brucent commented Jul 15, 2011

I wanted to create an object that just keeps a one-to-many association, so I created model classes like these (getters and setters removed):

@Model
public class Student {
    @Id
    private Long id;

    @CollectionSet(of = Pen.class)
    @Indexed
    private Set<Pen> pens;

    //It appears that at least one attribute class is required
    //@Attribute
    //private String name;
}


@Model
public class Pen {
    @Id
    private Long id;

    @Attribute
    private String color;
}

Using these classes generated an error with JOhm 0.5.0 when you add a Pen to the Student's collection. I was able to work around the problem if I added an attribute to Student and gave it a value.

public class JOhmTest {

    public JOhmTest() {
    }

    @Before
    public void setup() throws Exception {
        JedisPool jedisPool = new JedisPool(new GenericObjectPool.Config(), "localhost");
        JOhm.setPool(jedisPool);
    }

    /**
     * Test of main method, of class JOhmTest.
     */
    @Test
    public void testMain() {
        System.out.println("main");

        Pen pen1 = new Pen();
        pen1.setColor("blue");
        JOhm.save(pen1);

        Student student = new Student();
        //student.setName("joe");
        JOhm.save(student);

        Pen pen2 = new Pen();
        pen2.setColor("black");
        JOhm.save(pen2);

        student.getPens().add(pen1);
        student.getPens().add(pen2);

        int id = (int) student.getId().intValue();
        Student foundStudent = JOhm.get(Student.class, id);
        System.out.println(foundStudent);

        assertEquals(2, foundStudent.getPens().size());
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant