2017-09-14 79 views
1

我有一張名爲LocalEventSessions的表格。它有2列,localevent_idsession_id如何刪除連接表中的行?

在我LocalEventSessionRepository我有這樣的代碼:

List<LocalEventSession> findAllByLocalEventSessionId_localEventId(Integer id); 

這將返回屬於LocalEvent所有會話的列表。這用於顯示會話。

我想刪除與localevent的會話關係。所以我寫了這一點:

Integer deleteByLocalEventIdAndSessionId(@Param("localevent_id") Integer lid, @Param("session_id") Integer sid); 

我預計這將在LocalEventSession表基礎上,localevent_idsession_id刪除記錄。我可以毫無問題地編譯代碼,但是當我用Wildfly部署它時,我收到了一些錯誤。在堆棧跟蹤結束時,它顯示Wildfly無法找到localEventId屬性。

Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [localEventId] on this ManagedType [net.atos.eventsite.jar.LocalEventSession]"}, 
"WFLYCTL0412: Required services that are not installed:" => ["jboss.undertow.deployment.default-server.default-host./beheerback"], 
"WFLYCTL0180: Services with missing/unavailable dependencies" => undefined 

如果我沒有deleteBy方法聲明中部署它的代碼編譯,並沒有任何問題展開。

+1

要刪除連接表的一行,只需從使用該連接表映射的集合中刪除該元素:'course.students.remove(student)' –

+0

@JBNizet在arraylist上使用.remove我能te從數組中刪除一個對象,但不是從表中刪除一個對象。我所要做的就是找到正確的對象,並使用Spring的.delete()方法將它從數據庫中刪除。像這樣'localEventSessionRepository.delete(j);'J是一個for循環比較localevent_id和sessions_id的對象。 –

+0

它正在尋找'localEventId',但你似乎有'localevent_id'。 –

回答

0

按照JB Nizet的建議,我創建了一個包含所有localeventid和sessionid對象的數組列表。然後用一個for循環,我可以搜索正確的對象,像這樣:

for (LocalEventSession j : deleteItem) { 
    if (j.getSessionId() == sessionId) { 
     localEventSessionRepository.delete(j);   
    } 
} 

然後使用delete()方法從春季從表中刪除記錄。