0
所有我想感謝大家,甚至讀這首先。休眠與註解:「在FO實體映射重複列」 - 複合PK
我在與我的應用程序在Hibernate FW問題。下圖顯示了導致錯誤的數據庫部分的示意圖。
通過逆向工程autmatically產生我的代碼,並使它工作,我不得不「秀」的代碼生成的module_application表不是多到多臺(使用對自定義逆向工程策略)。現在,當我運行我的代碼,我得到以下錯誤:
Error creating Session: org.hibernate.MappingException: Repeated column in mapping for entity: DAL.module_application.ModuleApplication column: application_id (should be mapped with insert="false" update="false")
的ModuleApplication類,如下圖所示:
@Entity
@Table(name = "module_application", catalog = "domotics")
public class ModuleApplication implements java.io.Serializable
{
/**
*
*/
private static final long serialVersionUID = 4725933797587110677L;
private ModuleApplicationId id;
private Application application;
private Module module;
private Set<ModuleApplicationStatus> moduleApplicationStatuses = new HashSet<ModuleApplicationStatus>(0);
public ModuleApplication()
{
}
public ModuleApplication(ModuleApplicationId id, Application application, Module module)
{
this.id = id;
this.application = application;
this.module = module;
}
public ModuleApplication(ModuleApplicationId id, Application application, Module module, Set<ModuleApplicationStatus> moduleApplicationStatuses)
{
this.id = id;
this.application = application;
this.module = module;
this.moduleApplicationStatuses = moduleApplicationStatuses;
}
@EmbeddedId
@AttributeOverrides(
{
@AttributeOverride(name = "networkAddress", column = @Column(name = "network_address", nullable = false, length = 45)),
@AttributeOverride(name = "applicationId", column = @Column(name = "application_id", nullable = false))
})
public ModuleApplicationId getId()
{
return this.id;
}
public void setId(ModuleApplicationId id)
{
this.id = id;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_id", nullable = false, insertable = false, updatable = false)
public Application getApplication()
{
return this.application;
}
public void setApplication(Application application)
{
this.application = application;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "network_address", nullable = false, insertable = false, updatable = false)
public Module getModule()
{
return this.module;
}
public void setModule(Module module)
{
this.module = module;
}
@OneToMany(fetch = FetchType.LAZY, mappedBy = "moduleApplication")
public Set<ModuleApplicationStatus> getModuleApplicationStatuses()
{
return this.moduleApplicationStatuses;
}
public void setModuleApplicationStatuses(Set<ModuleApplicationStatus> moduleApplicationStatuses)
{
this.moduleApplicationStatuses = moduleApplicationStatuses;
}
}
我們可以看到,無論是插入和更新設置爲false。如果有人知道這個錯誤的確切原因和/或如何解決它,請分享知識!
我嘗試不要改變我的ER模型,我傾向於認爲,該框架需要參加到數據庫模式,而不是周圍的其他方式。你能解釋一些關於「使用查詢來檢索應用程序」的含義嗎? –
@GustavoSgarbiCampos我同意你的觀點,但有時折中的提出和答案更新。 – Hippoom
非常感謝你的幫助。我沒有完全得到存儲庫解決方案,你能解釋一下嗎?我嘗試刪除getApplication和setApplication方法,以及'@ManyToOne'和'@JoinColumn'註釋,但錯誤不斷髮生! –