最近、1年ほど正常に動作しているJPAアプリケーションにいくつかの変更を加えました。いくつかの新しいテーブルを追加しましたが、いくつかの問題が発生しました。投稿数が 10 ではないため、スキーマの画像を投稿できませんが、item テーブルと product テーブルがあります。多くの製品が同じアイテムを持つことができるため、製品テーブルには item_id があります
以下は私のアイテムエンティティです
@Entity
@Table(name="item")
public class Item implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer _id;
private Double carbonValue;
private String description;
private String name;
private Integer discount;
@OneToMany(mappedBy="item")
private Collection<Product> products;
// getters and setters etc
そして、これが私の製品エンティティです
@Entity
@Table(name="product")
public class Product implements Serializable {
private static final long serialVersionUID = 1L;
@Id
private Integer _id;
private Integer deleted;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="ITEM_ID", referencedColumnName="_ID")
private Item item;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="SUPPLIER_ID", referencedColumnName="_ID")
private Supplier supplier;
@OneToMany(mappedBy = "product")
private Collection<Consumption> consumptions;
私はeclipselink 2.2を使用しています
次のように項目テーブルでクエリを実行すると:
public final static String SELECT_ALL_ENTITIES_SQL = "SELECT o FROM Item AS o";
public List<Item> getAllEntities() {
final EntityManager entityManager = DaoUtils.getEntityManagerFactory().createEntityManager();
final List<Item> items;
try {
items = (List<Item>) entityManager.createQuery(SELECT_ALL_ENTITIES_SQL).getResultList();
} finally {
entityManager.close();
}
return items;
}
次のエラーが表示されます。
[EL Info]: 2012-10-24 14:16:23.798--ServerSession(1351669994)--EclipseLink, version: Eclipse Persistence Services - 2.2.0.v20110202-r8913
[EL Severe]: 2012-10-24 14:16:24.16--ServerSession(1351669994)--Local Exception Stack:
Exception [EclipseLink-0] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.IntegrityException
Descriptor Exceptions:
---------------------------------------------------------
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [item] is not present in this descriptor.
Descriptor: RelationalDescriptor(database.entities.Product --> [DatabaseTable(product)])
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [circle] is not present in this descriptor.
Descriptor: RelationalDescriptor(database.entities.Refund --> [DatabaseTable(refund)])
Runtime Exceptions:
---------------------------------------------------------
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:476)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:407)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:680)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:628)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:394)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
at database.dao.ItemDao.getAllEntities(ItemDao.java:24)
at database.dao.ItemDao.main(ItemDao.java:19)
Descriptor Exceptions:
---------------------------------------------------------
Local Exception Stack:
Exception [EclipseLink-93] (Eclipse Persistence Services - 2.2.0.v20110202-r8913): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [item] is not present in this descriptor.
Descriptor: RelationalDescriptor(database.entities.Product --> [DatabaseTable(product)])
at org.eclipse.persistence.exceptions.DescriptorException.tableNotPresent(DescriptorException.java:1628)
at org.eclipse.persistence.descriptors.ClassDescriptor.getTable(ClassDescriptor.java:2478)
at org.eclipse.persistence.descriptors.ClassDescriptor.buildField(ClassDescriptor.java:760)
at org.eclipse.persistence.descriptors.ClassDescriptor.buildField(ClassDescriptor.java:749)
at org.eclipse.persistence.mappings.OneToManyMapping.initializeTargetForeignKeysToSourceKeys(OneToManyMapping.java:796)
at org.eclipse.persistence.mappings.OneToManyMapping.initializeReferenceDescriptor(OneToManyMapping.java:726)
at org.eclipse.persistence.mappings.ForeignReferenceMapping.initialize(ForeignReferenceMapping.java:1160)
at org.eclipse.persistence.mappings.CollectionMapping.initialize(CollectionMapping.java:1095)
at org.eclipse.persistence.mappings.OneToManyMapping.initialize(OneToManyMapping.java:466)
at org.eclipse.persistence.descriptors.ClassDescriptor.initialize(ClassDescriptor.java:2744)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:453)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:407)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:680)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:628)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:394)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:185)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:242)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:230)
at database.dao.ItemDao.getAllEntities(ItemDao.java:24)
at database.dao.ItemDao.main(ItemDao.java:19)
ここで私は何を間違えましたか?
更新: データベースで、製品とアイテムの関係を削除しました。私のコードでは、2 つのエンティティ間の参照も削除したため、データベース テーブルとエンティティは相互にまったく関係がなくなりました。そして、私はまだ同じエラーが発生します?????
解決済み: 別の無関係なエンティティで自分のエンティティをコーディングしていたときに、誤ってアイテムを製品と間違えました。私は今テーブルに頭をぶつけています。