我最近對已運行一年左右的JPA應用程序進行了一些更改。我添加了幾個新表,並遇到了一些問題。我無法發佈我的模式的圖像,因爲我沒有10個帖子,但我有一個項目表和一個產品表。許多產品可以有相同的項目,以便在產品表有一個ITEM_IDEclipseLink-93異常說明:表[項目]不存在於此描述符中
以下是我的項目實體
@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)
我有什麼錯在這裏做什麼?
更新:在數據庫中,我刪除了產品和項目之間的關係。在我的代碼中,我也刪除了兩個實體之間的任何引用,所以現在數據庫表和實體之間根本沒有任何關係。而我仍然得到同樣的錯誤?????
解決:當我在另一個不相關的實體中編碼我的實體時,我無意中誤解了一個產品的產品。我現在正在桌子上敲着我的頭。
嗨,我給了一個去,但沒有運氣,謝謝你的幫助 – user1461220
@ user1461220,你得到什麼錯誤?和以前一樣? – CycDemo
是的,我得到了同樣的錯誤 – user1461220