2016-04-27 8 views
0

を返します。Hibernateはここにシナリオを間違ったエンティティ

私の第一の方法は、エンティティSContact.class上の休止状態クエリを実行します。

最初のメソッドを使用すると、2番目のメソッドがSContactX.classを照会するために呼び出されます。

第2の照会が発射されるときはいつでも休止状態には、以下の例外をスロー:

javax.persistence.PersistenceException:org.hibernate.WrongClassException:オブジェクト[ID = 1-1A5V6Z]指定サブクラスではなかった[COM .qvc.crm.esp.entity.siebel.SContactX]:

@Override 
    @Transactional(value = "transactionManagerAftReplicDb", readOnly = true) 
    public List<SContact> identifyCustomers(CompanyCode companyCode, CustomerSearchSpec customerSearchSpec) throws ApplicationException { 
      List<SContact> resultList = null; 
     QueryBuilder criteria = new QueryBuilder(SContact.class).equals(customerSearchSpec.getSearchFieldName(), customerSearchSpec.getSearchFieldValue()) 
       .equals("buId", resultListBu.get(0).getRowId()); 
     QueryConfig queryConfig = new QueryConfig(criteria, getEntityManager()); 
     queryConfig.withEnd(customerSearchSpec.getCustomerLimit().intValue()); 
     resultList = queryConfig.query(SContact.class); // executes a query agains SContact 
     map(resultList); // executes a query agains SContactX 
     return resultList; 
    } 



@Override 
    public List<Customer> map(List<SContact> contacts) { 
     List<Customer> foundCustomer = new ArrayList<Customer>(); 
     if (CollectionUtils.isNotEmpty(contacts)) { 
      for (SContact contact : contacts) { 
       SContactX contactExt = loadContextExt(contact); 
       ... 
      } 
     } 
     return foundCustomer; 
    } 

    @Transactional(value = "transactionManagerAftReplicDb", readOnly = true) 
    private SContactX loadContextExt(SContact contact) { 
     TypedQuery<SContactX> query = getEntityManager().createQuery("FROM SContactX where rowId = :rowId", SContactX.class); 
     query.setParameter("rowId", contact.getRowId()); 
     SContactX result = query.getSingleResult(); // thows exception! 
     return result; 
    } 
:ロードされたオブジェクトは、ここで間違ったクラスクラスの最初のメソッド

com.qvc.crm.esp.entity.siebel.SContactました

SCONTACT:

@Entity 
@Table(name = "S_CONTACT") 
@SuppressWarnings("serial") 
public class SContact extends SiebelBaseEntity { 

SCONTACTX:

@SuppressWarnings("serial") 
@Entity 
@Table(name = "S_CONTACT_X") 
public class SContactX extends SiebelBaseEntity { 

SIEBELBASEENTITY:

@Entity 
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) 
@SuppressWarnings("serial") 
public abstract class SiebelBaseEntity extends BaseEntity { 

BASEENTITY。

public abstract class BaseEntity implements Serializable { 
+0

してください。 –

+0

ちょうどそれをやった。上のコードを参照してください –

+0

投稿**すべて**関連コード。この問題に関するその他の質問は、継承について議論します。 SiebelBaseEntityとは何ですか?他にどのようなマッピングが関係していますか? –

答えて

1

私はにスーパークラスのSiebelBaseEntityの注釈を変更することで、私の問題を解決:あなたのScontactXとSContactクラスを提供し、

関連する問題