ObjectDB ObjectDB

Unique contraint with 2 members

#1

I am trying to do the following:


@javax.persistence.Entity
public class Account {


@Unique()
private String name;


@Unique(members={"SalesforceID","sport"})
private String SalesforceID;
private String sport;

...

}

The first Unique constraint works. On commit, an exception is thrown if an Account already exists with the specified name.

The second does not seem to work. I would expect an exception to be thrown if the combination of SalesforceID and sport is not unique. Am I doing this right?

Thanks,

Carl

 

edit
delete
#2

Just tried the following test code and got a "Unique constraint" exception:

import javax.jdo.annotations.*;
import javax.persistence.*;

public class T486 {
   
    public static void main(String[] args) {
        EntityManagerFactory emf =
            Persistence.createEntityManagerFactory(
                "objectdb:$objectdb/db/test.tmp;drop");
        EntityManager em = emf.createEntityManager();
       
        em.getTransaction().begin();
        em.persist(new MyEntity());
        em.getTransaction().commit();

        em.getTransaction().begin();
        em.persist(new MyEntity());
        em.getTransaction().commit();

        em.close();
        emf.close();
    }
   
    @Entity
    static class MyEntity {
        @Unique(members={"SalesforceID","sport"})
        private String SalesforceID = "123";
        private String sport = "abc";
    }
}
ObjectDB Support
edit
delete

Reply

To post on this website please sign in.