2014-01-22 5 views
0

저는 이미 그 작업을 시도하는 데 몇 시간을 소비합니다. 기록 정책을 사용하여 일부 테이블에 대한 전체 기록을 만듭니다. 이것은 추상 클래스에서 정의됩니다. 그런 다음이 클래스를 구현하고 필드를 정의하는 일반 엔터티가 있습니다. 그런 다음 상급 클래스에서 상속 한 클래스를 사용하려고했지만 테이블은 기록 테이블로 설정됩니다. 그게 완벽하게 작동, 유일한 문제는, 내가 역사 테이블 (lasso_warehandling_entry)에 대한 쿼리를했을 때, 항상 역사 엔티티 (lasso_warehandling_entry_hist)에서 결과를 반환했습니다. 그래서 나는 descriptor.getInheritancePolicy() 라인을 추가했다. setShouldReadSubclasses (false); 어딘가에서 읽었습니다. 문제가 해결되어야합니다. 불행히도 그렇지 않습니다. 지금은 항상 다음과 같은 메시지 얻을 : 우리는 각 엔티티에 대한 별도의 테이블을 사용하기 때문에eclipselink InheritanceType.TABLE_PER_CLASS를 사용할 때 클래스 지시자 필드를 묻습니다.

Exception Description: The descriptor [RelationalDescriptor(dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)])] has been set to use inheritance, but a class indicator field has not been defined. 
When using inheritance, a class indicator field or class extraction method must be set. 
Parent Descriptor: [RelationalDescriptor(org.rorotec.lasso.dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)])] 
Descriptor: RelationalDescriptor(dao.LassoWarehandlingEntry --> [DatabaseTable(lasso_warehandling_entry)]) 

, 표시기 필드를 사용하는 것이 많이하지 않습니다. 어쨌든, 나는이 메시지를 멀리 할 수 ​​없다. 아무도 그 문제를 어떻게 풀어야할지 모릅니다. 코드는 다음과 같습니다

@MappedSuperclass 
@Customizer(abstractDao.HistoryCustomizer.class) 
public abstract class AbstractAuditedOzlEntity { 
// defined the columns all the autited classes have 
... 
} 

public class HistoryCustomizer implements DescriptorCustomizer { 

    public void customize(ClassDescriptor descriptor) { 
     HistoryPolicy policy = new HistoryPolicy(); 
     policy.addHistoryTableName(descriptor.getTableName() + "_hist"); 
     policy.addStartFieldName("start_date"); 
     policy.addEndFieldName("end_date"); 
     descriptor.setHistoryPolicy(policy); 

     // This here I added afterwards, as described in the text, and is the reason for the error message i get 
     descriptor.getInheritancePolicy().setShouldReadSubclasses(false); 
    } 
} 

@Entity 
// when i define the inhertiancetype already in the abstract class, it doesn't seem to have any influence, so I added it here. 
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS) 
@Table(name = "lasso_warehandling_entry") 
public class LassoWarehandlingEntry extends AbstractAuditedOzlEntity implements Serializable { 
// define the specific stuff of this table 
... 

} 

@Entity 
@Table(name = "lasso_warehandling_entry_hist") 
@AttributeOverride(name="id", [email protected](name="hist_id")) 
public class LassoWarehandlingEntryHist extends LassoWarehandlingEntry { 
... 
// add the columns which only exist in the history tables like end_date 
} 

답변

0

내가 당신 같은 문제에 직면하고있다.

EclipseLink가 LassoWarehandlingEntry 또는 LassoWarehandlingEntryHist를 조회하는지 여부를 구분할 수 없다는 오류 메시지가 표시됩니다. (클래스 표시기 필드 또는 클래스 추출 메소드가 설정되어야합니다.) 따라서 LassoWarehandlingEntry를 조회하면 EclipseLink는 LassoWarehandlingEntry 및 LassoWarehandlingEntryHist를 모두 조회합니다. 그래서 우리가 InheritanceType.TABLE_PER_CLASS을 사용하고 있기 때문에, 불행하게도

descriptor.getInheritancePolicy().setShouldReadSubclasses(false); 

를 사용하려고 추측, 우리가 판별 주석 (@DiscriminatorColumn 및 @DiscriminatorValue)를 사용할 수 없습니다 것 같다. 이 2 가지 주석은 InheritanceType.SINGLE_TABLE 및 InheritanceType.JOINED에 대해서만 있습니다. ClassExtractor가 작동하지 않습니다. 더 자세한 정보는 https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Entities/Inheritance

어쨌든 두 가지 구체적인 클래스에 상속 될 추상 클래스를 작성하여이 문제를 해결했습니다. 귀하의 경우 :


@MappedSuperclass 
public abstract class AbstractLassoWarehandlingEntry extends AbstractAuditedOzlEntity implements Serializable { 
// define the specific stuff of this table 
... 

} 


@Entity 
@Table(name = "lasso_warehandling_entry") 
public class LassoWarehandlingEntry extends AbstractLassoWarehandlingEntry implements Serializable { 
// Empty class as the content is already defined in AbstractLassoWarehandlingEntry 

} 


@Entity 
@Table(name = "lasso_warehandling_entry_hist") 
@AttributeOverride(name="id", [email protected](name="hist_id")) 
public class LassoWarehandlingEntryHist extends AbstractLassoWarehandlingEntry { 
... 
// add the columns which only exist in the history tables like end_date 
} 

이 방법을 사용하면 HistoryCustomizer 클래스에서 다음 행을 제거 할 수 있습니다. 당신이 LassoWarehandlingEntry를 조회 할 경우


descriptor.getInheritancePolicy().setShouldReadSubclasses(false); 

이제,는 EclipseLink는 LassoWarehandlingEntry 테이블 1 개 쿼리를 실행합니다.

희망이 도움이됩니다!