2014-06-17 2 views
6

에 많은 나는 많은 관계로 하나를 만들려면 내가 다음 service.xml 사용했습니다 :을 Liferay 서비스 빌더 6.2 : 한 관계

<entity name="Student" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="studentId" type="long" primary="true" /> 
    <column name="courses" type="Collection" entity="Course"/> 
</entity> 

<entity name="Course" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="courseId" type="long" primary="true" /> 
    <column name="studentId" type="long"/> 
</entity> 

내 문제는 아무 것도 수집 방법에 대한 생성되지 가져옵니다입니다 . 아무 예외도, 아무것도. 클래스가 생성되고 간단한 getter 메소드가 있지만 getCourse()는 없습니다.

내가 뭘 잘못하고 있니?

답변

7

게터가 자동으로 생성되지 않습니다. 각 엔티티는 데이터베이스의 테이블을 나타내므로 유용하다고 생각되는 getter를 만들어야합니다. 다행히 Service Builder는 필요한 경우 생성 할 수도 있습니다.

먼저 Service Builder에 StudentsCourses 사이의 매핑 테이블을 생성하도록 요청합니다.

<entity name="Student" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="studentId" type="long" primary="true" /> 

    <column name="courses" type="Collection" entity="Course" mapping-table="Courses_Students" /> 
</entity> 

<entity name="Course" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="courseId" type="long" primary="true" /> 

    <column name="students" type="Collection" entity="Student" mapping-table="Courses_Students" /> 
</entity> 

다음으로, 우리는 CourseLocalServiceImpl에 적절한 방법을 만들 :

public List<Course> getStudentCourses(long studentId) 
    throws PortalException, SystemException { 

    return coursePersistence.getCourses(studentId); 
} 

Student 개체에서 Courses를 얻으려면 우리가 생성 StudentImpl.java 내부 방법 작성 : 마지막으로

public List<Course> getCourses() throws Exceptions { 
    return CorseLocalServiceUtil.getStudentCourses(getStudentId()); 
} 

을 재생하여 ant build-service을 실행하여 수업을 시작합니다.

List<Course> courses = CourseLocalServiceUtil.getStudentCourses(studentId); 

또는

List<Course> courses = student.getCourses(); 
+0

좋습니다. 그러나 그것은 우리에게 코스 테이블에 대한 원치 않는 데이터베이스 컬럼 (studentId)을 남겨 둡니다, 그렇죠? – Breiti

+0

위에서 제공 한 Service Builder XML에서 'studentId'는 이미'course' 테이블의 열이었습니다. –

+0

ok, true;) 그건 내 실수입니다. 그것을 제거 할 수있는 방법이 있습니까? 목록에 대한 가져 오기 도구 만 있습니까? 그리고 두 번째 질문 : 학생 요소에서 그 요소를 얻을 수있는 방법이없는가요? – Breiti

6

을 Liferay 모든 버전에서 지정한 문서, 위에서 아래로 이동하는 데 도움이 : 이제

우리는 학생이 쓰기에 의해 걸리는 모든 과정을 얻을 수 있습니다 접근. 다음 코드를 자발적으로 추가 들어

<entity name="Student" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="studentId" type="long" primary="true" /> 
    <column name="courses" type="Collection" entity="Course"/> 
</entity> 

<entity name="Course" local-service="true" remote-service="true" cache-enabled="false"> 
    <column name="courseId" type="long" primary="true" /> 
    <column name="studentId" type="long"/> 

    <finder name="courseId" return-type="Collection"> 
     <finder-column name="courseId" /> 
    </finder> 

    <finder name="studentId" return-type="Collection"> 
     <finder-column name="studentId" /> 
    </finder> 
</entity> 

실행 빌드 서비스를

https://www.liferay.com/documentation/liferay-portal/6.2/development/-/ai/define-your-object-relational-map-liferay-portal-6-2-dev-guide-04-en

을 성공적으로 실행에 당신은 게터의 setter 메소드가 표시됩니다

이 첫 번째를 참조하십시오.

관련 문제