2011-12-05 4 views
2

JDO의 일반적인 시나리오라고 생각합니다. 나는 간단한 영속 클래스가 추가가 실패 할 경우 고유 제한 조건JDO 고유 제약 조건 위반 처리

public void addPerson(String name) throws NotUniqueException { 
    PersistenceManager pm = getPM(); 
    Transaction tx = pm.currentTransaction(); 

    try { 
     tx.begin(); 

     Person toAdd = new Person(name); 
     pm.makePersistent(toAdd); 

     // how do I throw a NotUniqueException if the transaction fails due to 
     // "name" not being unique? 

     tx.commit(); 
    } finally { 
     if (tx.isActive()) { 
      tx.rollback(); 
     } 
     pm.close(); 
    } 
} 

을 위반했기 때문에 내가 감지 어떻게 간단하게 추가 할 수 있지만, 사용자 정의 예외를 throw 할 그런

@PersistenceCapable 
public class Person { 

    @PrimaryKey 
    @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) 
    private long id; 

    @Persistent 
    @Unique 
    private String name 

    //constructor, equals, hashcode, etc... 
} 

말 JDO에서의이 오류 상태? 우선 성공 여부를 확인하기 위해 쿼리를 수행해야하는데, 확인 및 추가 작업이 수행되는 한 인 한 입니다. 나는 JDO 트랜잭션을 처음 접했을 뿐이며 쿼리를 수행하고 트랜잭션을 체크인하면 어떤 보장을 받을지 확신 할 수 없다.

this answer에 따르면 JPA를 사용하면 벤더 특정 원인 예외에 대한 예외 체인을 파고 해당 정보를 사용해야합니다. JDO가 사실입니까?

답변

0

JDO 사양에 따라 중첩 데이터 저장소 관련 예외가있는 JDODataStoreException

관련 문제