2013-02-12 2 views
0

NHibernate (최신 버전 사용)을 처음 사용하고 일반 데이터 로딩 응용 프로그램의 개체를 데이터베이스에 매핑 할 때 문제가 있습니다. 데이터베이스가 제 3 자이므로 데이터베이스를 변경할 수 없습니다.매핑 문제 : 올바른 결과 수 (모든 결과는 첫 번째 resut와 중복 됨)

우리의 목적은 다음과 같습니다

public class GenericObjectValue 
{ 
    public string ObjectId { get; set; } 
    public string ObjectTypeId { get; set; } 
    public string measurementId { get; set; } 
    public DateTime timestamp { get; set; } 
    public Double Value { get; set; } 
} 

데이터 소스 테이블 우리가 사용

Table t_data_point 
(
    id (PK, int, not null) 
    object_id (FK, Varchar(30), not null) 
    object_type_id (FK, Varchar(30), not null); 
    measurement_id (FK, Varchar(30), not null); 
) 


Table t_data_point_Value 
(
    data_point_id (PK, FK, int, not null) 
    timestamp (PK, FK, datetime, not null) 
    version (PK, FK, int, not null) 
    value (numeric(18,6), not null); 
) 

내가 설정 한 매핑은 다음과 같습니다

<?xml version="1.0" encoding="utf-8" ?> 
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Phoenix.Model"  assembly="Phoenix.Common"> 
<class name="MeasValue" table="t_data_point_Value"> 
    <id column="data_point_id" type="int" /> 
    <property name="Timestamp" column="timestamp "/> 
    <property name="Value" column="value"/> 

    <join table="t_data_point"> 
     <key column="id" /> 
     <property name="measurementId" column="measurement_id" /> 
     <property name="ObjectId" column="object_id" /> 
     <property name="ObjectTypeId" column="object_type" /> 
    </join> 
</class> 
</hibernate-mapping> 

확실하지 내가 멍청한 짓을하고있어 경우 아니면 그냥 불가능하지만 내가이 코드를 실행할 때 나는 올바른 수의 결과를 얻을 수 있지만 결과는 반환 된 첫 번째 결과의 중복 일뿐입니다. 즉, 타임 스탬프와 값은 같습니다.

자세한 정보가 필요하면 알려주십시오.

답변

0

ID가 잘못 매핑 된 경우 (예 : 고유하지 않은 열)입니다. Nhibernate는 캐시에서 찾은 첫 번째 객체를 동일한 ID로 재사용합니다. 올바른 방향으로 안내 할 수있는 무료 매핑 도구가 있습니다. 조인은 생성되지 않지만 기본 열과 ID는 http://nmg.codeplex.com이됩니다.