문제

저는 2 체/테이블이 있습니다.

하나는 적절한 entity,하자 전화 data.그것은 수의 분야가 포함된 소위"다국어 구사 가능 codes".

두 번째,테이블 code, 포함하고,다국어 구사 가능 값이다.

여기에 몇 가지 예를 들어 데이터:

Data table
id  name         continentCode  countryCode 
------------------------------------
1   Toto         EU             CH
2   Titi         AS             CN

Code table
id  code   language  text
----------------------------
1   EU     EN        Europe
2   EU     FR        Europe
3   EU     DE        Europa
4   CH     EN        Switzerland
5   CH     FR        Suisse
6   CH     DE        Schweiz
... etc

하고 싶지도 속성 대륙,국가 등에서 데이터 개체 맵으로,다음과 같다:

@OneToMany()
@MapKey(name="languageCode")
private Map<String, Code> continents;

할 수 있도록 다음 텍스트를 읽는 권리에 대한 언어 다음과 같다:

Data toto = dao.findByName("Toto");
String text = toto.getContries.get("FR").getText(); //--> returns "Suisse"
String text = toto.getContries.get("EN").getText(); //--> returns "Switzerland"

또한 필요할 수 있게 텍스트 검색에서 이러한 값을"코드를 사용하여,"사용자의 언어.(예:모든 자료는 국가='스위스',프랑스어!)

그래서,그것은 지도 OneToMany 키를 사용하여 컬렉션 필드지 않는 기본 키의 현재 entity?내 대륙 컬렉션에"모든 기록부터 코드 테이블 code=값의 continentCode property".나 어쩌면 더 많은 적절한 방법으로 표현하는 이런 종류의 관계는?

NB:불행하게도 나는 바꿀 수 없는 SQL 스키마...

도움이 되었습니까?

해결책

OK,I 해결책을 발견했다.이 OneToMany 매핑에서 내 데이터 entity 처럼 보인다:

@OneToMany()
@JoinColumn(name="code", referencedColumnName="continentCode", insertable=false, updatable=false)   
@MapKey(name="languageCode")
private Map<String, AAGeoContinentThesaurusEntry> continents;

도가 지도 continentCode 열기 위해서 작동합니다.I fi 지 않았다,그것을 가지고:

org.hibernate.MappingException: Unable to find column with logical name: GCH_CDE_CODE_CNT in org.hibernate.mapping.Table
(GCHDATA) and its related supertables and secondary tables
        at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:396)
        at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:102)

지금 내가 할 수 있습니다:

myData.getContinentCodes().get("FR").getText() 

을 받을 문자열""유럽:)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top