###SPRING MVC JPA にて1つのテーブルの2カラムから別テーブルへJOINを行うとサーバーで実行時404になる
Aテーブルの2カラムからBテーブルにJOINをして名称を取得する処理を作成したいです。
例
aテーブル[商品id、倉庫id、エージェントid](この倉庫idと、エージェントidをbテーブルの取引先idとjoinしてそれぞれの名称を取得したい)
bテーブル[取引先id、取引先名称]
エンティティとpersistence.xmlはJPAツールにて作成を行っています。
発生している問題・エラーメッセージ
ECLIPSE内のPIVOTAL TC SERVER 及びTOMCAT V9 SERVERにて実行するとブラウザにてルートページ時点で404となります。
ログが出ていました。
エラーログ WARN XmlWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/application-config.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory ERROR ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/application-config.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: model.TblWarehouseStock column: warehouse_cd (should be mapped with insert="false" update="false") 重大: クラス [org.springframework.web.context.ContextLoaderListener] のリスナインスタンスにコンテキスト初期化イベントを送信中の例外です org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [spring/application-config.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: model.TblWarehouseStock column: warehouse_cd (should be mapped with insert="false" update="false")
該当のソースコード
JAVA
1aテーブル 2 3import java.io.Serializable; 4import javax.persistence.*; 5 6 7/** 8 * The persistent class for the tbl_warehouse_stock database table. 9 * 10 */ 11@Entity 12@Table(name="tbl_warehouse_stock") 13@NamedQuery(name="TblWarehouseStock.findAll", query="SELECT t FROM TblWarehouseStock t") 14public class TblWarehouseStock implements Serializable { 15 private static final long serialVersionUID = 1L; 16 17 @EmbeddedId 18 private TblWarehouseStockPK id; 19 20 @Column(name="free_quantity") 21 private int freeQuantity; 22 23 //uni-directional many-to-one association to TblMSupplier 24 @ManyToOne 25 @JoinColumn(name="warehouse_cd") 26 private TblMSupplier tblMSupplier1; 27 28 //uni-directional many-to-one association to TblMSupplier 29 @ManyToOne 30 @JoinColumn(name="agent_cd") 31 private TblMSupplier tblMSupplier2; 32 33 public TblWarehouseStock() { 34 } 35 36 public TblWarehouseStockPK getId() { 37 return this.id; 38 } 39 40 public void setId(TblWarehouseStockPK id) { 41 this.id = id; 42 } 43 44 public int getFreeQuantity() { 45 return this.freeQuantity; 46 } 47 48 public void setFreeQuantity(int freeQuantity) { 49 this.freeQuantity = freeQuantity; 50 } 51 52 public TblMSupplier getTblMSupplier1() { 53 return this.tblMSupplier1; 54 } 55 56 public void setTblMSupplier1(TblMSupplier tblMSupplier1) { 57 this.tblMSupplier1 = tblMSupplier1; 58 } 59 60 public TblMSupplier getTblMSupplier2() { 61 return this.tblMSupplier2; 62 } 63 64 public void setTblMSupplier2(TblMSupplier tblMSupplier2) { 65 this.tblMSupplier2 = tblMSupplier2; 66 } 67 68} 69
JAVA
1bテーブル 2 3import java.io.Serializable; 4import javax.persistence.*; 5 6 7/** 8 * The persistent class for the tbl_m_suppliers database table. 9 * 10 */ 11@Entity 12@Table(name="tbl_m_suppliers") 13@NamedQuery(name="TblMSupplier.findAll", query="SELECT t FROM TblMSupplier t") 14public class TblMSupplier implements Serializable { 15 private static final long serialVersionUID = 1L; 16 17 @Id 18 @Column(name="suppliers_cd") 19 private String suppliersCd; 20 21 @Column(name="suppliers_name") 22 private String suppliersName; 23 24 public TblMSupplier() { 25 } 26 27 public String getSuppliersCd() { 28 return this.suppliersCd; 29 } 30 31 public void setSuppliersCd(String suppliersCd) { 32 this.suppliersCd = suppliersCd; 33 } 34 35 public String getSuppliersName() { 36 return this.suppliersName; 37 } 38 39 public void setSuppliersName(String suppliersName) { 40 this.suppliersName = suppliersName; 41 } 42 43}
試したこと
aテーブルの1カラムからbテーブルにJOINであれば上記の問題は発生しません。
上記の例でいえば倉庫id、代理店idのどちらか一つだけであれば問題が発生ことを確認しました。
補足情報(FW/ツールのバージョンなど)
JAVA 1.8.0_171
Spring Tool Suite
Version: 3.9.4.RELEASE
Build Id: 201804120921
Platform: Eclipse Oxygen.3a (4.7.3a)
SPRING MVC
回答1件
あなたの回答
tips
プレビュー