views:

227

answers:

2

Hello,

is it possible to use Constraints in the google-app-engine? It seems not to work ... http://www.datanucleus.org/products/accessplatform%5F1%5F1/jpa/orm/constr...

The properties codingSystem and code should be unique. Is there a workaround?

@Entity @Table(uniqueConstraints={@UniqueConstraint(columnNames= {"codingSystem","code"})}) public class ArticleCode {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Key id;

    private String codingSystem;

    private String code;

Thanks, Ralph

+2  A: 

In a nutshell, no, they're not. The underlying datastore implementation doesn't support global transactions, so it's not practical to enforce arbitrary uniqueness constraints.

The workaround is to make the unique components part of the key name.

Nick Johnson
+2  A: 

Thanks a lot, it works fine.

Here is my new code.

@Entity public class ArticleCode {

@Id
private Key id;

@Column(name="codingSystem")
private String codingSystem;

@Column(name="code")
private String code;

public ArticleCode(Key parent, String codingSystem, String code) {
 this.id = KeyFactory.createKey(parent, ArticleCode.class.getSimpleName(), codingSystem + code);
 this.codingSystem = codingSystem;
 this.code = code;
}
Ralph Kretzler