2011-01-17 2 views
1

내가 슈퍼 클래스구글 앱 엔진 Datanucleus enhencer

@Entity 
@MappedSuperclass 
public class Location implements LocationCapable { 

    @Basic 
    private Double latitude; 

    @Basic 
    private Double longitude; 

    @Basic 
    private List<String> geocells; 

    @PrePersist 
    @Transient 
    private void generateGeoCells() { 
     geocells = GeocellManager.generateGeoCell(getLocation()); 
    } 

    public Double getLongitude() { 
     return longitude; 
    } 

    public void setLongitude(Double longitude) { 
     this.longitude = longitude; 
    } 

    public Double getLatitude() { 
     return latitude; 
    } 

    public void setLatitude(Double latitude) { 
     this.latitude = latitude; 
    } 

    @Override 
    @Transient 
    @JsonIgnore 
    public Point getLocation() { 
     return new Point(latitude, longitude); 
    } 

    @Override 
    @Transient 
    @JsonIgnore 
    public String getKeyString() { 
     return latitude + ":" + longitude; 
    } 

    @Override 
    public List<String> getGeocells() { 
     return geocells; 
    } 

    public void setGeocells(List<String> geocells) { 
     this.geocells = geocells; 
    } 

} 

그리고이

에서 상속하지만 JUnit 테스트를 실행하려고 할 때이

Caused by: org.datanucleus.metadata.InvalidMetaDataException: Class Location has application-identity and no objectid-class specified yet has 0 primary key fields. Unable to use SingleFieldIdentity. 
at org.datanucleus.metadata.AbstractClassMetaData.determineObjectIdClass(AbstractClassMetaData.java:1032) 
at org.datanucleus.metadata.ClassMetaData.populate(ClassMetaData.java:205) 
at org.datanucleus.metadata.AbstractClassMetaData.validateSuperClass(AbstractClassMetaData.java:720) 
at org.datanucleus.metadata.AbstractClassMetaData.determineSuperClassName(AbstractClassMetaData.java:642) 
at org.datanucleus.metadata.ClassMetaData.populate(ClassMetaData.java:193) 
at org.datanucleus.metadata.MetaDataManager$1.run(MetaDataManager.java:2317) 
at java.security.AccessController.doPrivileged(Native Method) 
at org.datanucleus.metadata.MetaDataManager.populateAbstractClassMetaData(MetaDataManager.java:2311) 
at org.datanucleus.metadata.MetaDataManager.populateFileMetaData(MetaDataManager.java:2148) 
at org.datanucleus.metadata.MetaDataManager.initialiseFileMetaDataForUse(MetaDataManager.java:864) 
at org.datanucleus.metadata.MetaDataManager.loadPersistenceUnit(MetaDataManager.java:794) 
at org.datanucleus.jpa.EntityManagerFactoryImpl.initialisePMF(EntityManagerFactoryImpl.java:488) 
at org.datanucleus.jpa.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:355) 
at org.datanucleus.store.appengine.jpa.DatastoreEntityManagerFactory.<init>(DatastoreEntityManagerFactory.java:63) 
at org.datanucleus.store.appengine.jpa.DatastorePersistenceProvider.createEntityManagerFactory(DatastorePersistenceProvider.java:35) 
at javax.persistence.Persistence.createFactory(Persistence.java:172) 
... 67 more 

있어 또 다른 하나 다음과 같은 클래스가 또한 @ Id로 주석이 달린 키 필드를 supperclass에 추가하려고 시도했지만 아무런 결과도 얻지 못했습니다.

답변

2

메시지에는 @Id 필드가 있어야합니다.

+0

오케이, 죄송합니다. 직접적인 질문은 http : // sta입니다. ckoverflow.com/questions/4760061/gae-datanucleus-jpa-problem-with-embedded – endryha

0

IDE 플러그인을 개선하거나 이클립스 할 때 어떤 문제가있는 것처럼 보입니다. IDE를 다시 시작한 후에는 문제가 없습니다. 그러나 ID가있는이 문제 만. 사실 저는 임베디드 엔티티와 관련된 또 다른 매우 이상한 문제에 직면했습니다. 나는 다음과 같은 한 도메인 모델 :

@Test 
    public void testSave() throws Exception { 
     City city = new City("testCity1", new Location(1d, 1d)); 
     cityDao.persist(city); 
     assertNotNull(city.getId()); 
    } 

cityDao.persist(city)가하는 나는이 개체를 유지하려고 할 때 단순히

그리고에서 jpaTemplate.persist(object); 나는 다음있어이 :

@Entity 
public class City { 
    @Id 
    @GeneratedValue(strategy = GenerationType.IDENTITY) 
    private Key id; 
    @Basic 
    private String name; 
    // Entity won't persist if location is not null, requires to persist with 
    // further update 
    @Embedded 
    // @OneToOne(cascade = CascadeType.ALL) it works the same when I add or remove this line 
    private Location location; 

    /* getters and setters */ 
} 

@Embeddable 
public class Location implements LocationCapable { 
    @Basic 
    @NotNull 
    private Double latitude; 
    @Basic 
    @NotNull 
    private Double longitude; 
    @Basic 
    private List<String> geocells; 

    /* getters and setters */ 
} 

내가 JUnit 테스트 케이스 다음의 한을 테스트하려면 예외 :

Caused by: java.lang.IllegalArgumentException: out of field index :-1 
    at com.myproject.model.Location.jdoProvideField(Location.java) 
    at org.datanucleus.state.JDOStateManagerImpl.provideField(JDOStateManagerImpl.java:2585) 
    at org.datanucleus.state.JDOStateManagerImpl.provideField(JDOStateManagerImpl.java:2555) 
    at org.datanucleus.store.mapped.mapping.CollectionMapping.postInsert(CollectionMapping.java:91) 
    at org.datanucleus.store.mapped.mapping.EmbeddedPCMapping.postInsert(EmbeddedPCMapping.java:104) 
    at org.datanucleus.store.appengine.DatastoreRelationFieldManager.runPostInsertMappingCallbacks(DatastoreRelationFieldManager.java:217) 
    at org.datanucleus.store.appengine.DatastoreRelationFieldManager.access$200(DatastoreRelationFieldManager.java:48) 
    at org.datanucleus.store.appengine.DatastoreRelationFieldManager$1.apply(DatastoreRelationFieldManager.java:116) 
    at org.datanucleus.store.appengine.DatastoreRelationFieldManager.storeRelations(DatastoreRelationFieldManager.java:81) 
    at org.datanucleus.store.appengine.DatastoreFieldManager.storeRelations(DatastoreFieldManager.java:955) 
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.storeRelations(DatastorePersistenceHandler.java:546) 
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertPostProcess(DatastorePersistenceHandler.java:304) 
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObjects(DatastorePersistenceHandler.java:256) 
    at org.datanucleus.store.appengine.DatastorePersistenceHandler.insertObject(DatastorePersistenceHandler.java:240) 
    at org.datanucleus.state.JDOStateManagerImpl.internalMakePersistent(JDOStateManagerImpl.java:3185) 
    at org.datanucleus.state.JDOStateManagerImpl.flush(JDOStateManagerImpl.java:4513) 
    at org.datanucleus.ObjectManagerImpl.flushInternal(ObjectManagerImpl.java:2814) 
    at org.datanucleus.ObjectManagerImpl.flush(ObjectManagerImpl.java:2754) 
    at org.datanucleus.ObjectManagerImpl.preCommit(ObjectManagerImpl.java:2893) 
    at org.datanucleus.TransactionImpl.internalPreCommit(TransactionImpl.java:369) 
    at org.datanucleus.TransactionImpl.commit(TransactionImpl.java:256) 
    at org.datanucleus.jpa.EntityTransactionImpl.commit(EntityTransactionImpl.java:104) 
    at org.datanucleus.store.appengine.jpa.DatastoreEntityTransactionImpl.commit(DatastoreEntityTransactionImpl.java:55) 
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:467) 
    ... 41 more