持久化JPA表示实体不存在于描述符中

时间:2016-04-26 14:31:47

标签: java eclipse postgresql jpa persistence

我们在尝试使用数据库实现梯形图游戏应用程序时遇到了问题。我们有一个名为'Spill'的实体,它与另一个名为'Brett'的实体有一个ManyToOne关系。

但是当持久性尝试将实体映射到数据库时,它似乎找不到它们。

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [brett] is not present in this descriptor.
Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

它们都在persistence.xml文件中定义,并且程序似乎连接到数据库就好了。我们明确地给出了名称和模式名称:

@Entity
@Table(name="spill",schema = "stigespill")

两个班级。

泄漏:

@Entity
@Table(name="spill",schema = "stigespill")
public class Spill {

  // FELTVARIABLER
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer spillid;

  private Integer ferdig;
  private Timestamp dato;

  @OneToMany(mappedBy = "spill" , cascade = CascadeType.ALL)
  private List<Spiller> spillere; // TODO Skiftet fra Queue til ArrayList

  @OneToMany(mappedBy = "spill" , cascade = CascadeType.ALL)
  private List<Trekk> trekklog;

  @ManyToOne( cascade = CascadeType.ALL)
  @JoinColumn(name = "brett", referencedColumnName="brettid", insertable = false, updatable = false)
  private Brett brett;
}

布雷特:

@Entity
@Table(name = "brett", schema = "stigespill")
public class Brett {

  // FELTVARIABLER
  @Id
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer brettid;

  @OneToMany(mappedBy = "brett", cascade = CascadeType.ALL)
  private List<Rute> ruter;
}

我们一直在网上搜索并试图在过去几个小时内解决这个问题,但我们找不到解决方案。

完整控制台日志:

[EL Info]: server: 2016-04-26 15:58:15.551--ServerSession(1348949648)--Detected server platform: org.eclipse.persistence.platform.server.NoServerPlatform.
[EL Warning]: metadata: 2016-04-26 15:58:15.876--ServerSession(1348949648)--The reference column name [spillid] mapped on the element [field spill] does not correspond to a valid id or basic field/column on the mapping reference. Will use referenced column name as provided.
[EL Info]: server: 2016-04-26 15:58:15.951--ServerSession(1348949648)--Detected server platform: org.eclipse.persistence.platform.server.NoServerPlatform.
[EL Info]: 2016-04-26 15:58:16.63--ServerSession(1348949648)--EclipseLink, version: Eclipse Persistence Services - 2.6.0.v20150309-bf26070
[EL Severe]: 2016-04-26 15:58:17.084--ServerSession(1348949648)--Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.IntegrityException

Descriptor Exceptions:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The table [brett] is not present in this descriptor. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: A non-read-only mapping must be defined for the sequence number field. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Runtime Exceptions:

[EL Info]: connection: 2016-04-26 15:58:17.087--ServerSession(1348949648)--/file:/Users/../Stigespill/bin/_eclipselink logout successful [EL Severe]: ejb: 2016-04-26 15:58:17.091--ServerSession(1348949648)--Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.IntegrityException

Descriptor Exceptions:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The table [brett] is not present in this descriptor. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: A non-read-only mapping must be defined for the sequence number field. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Runtime Exceptions:

Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Deployment of PersistenceUnit [eclipselink] failed. Close all factories for this PersistenceUnit. Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.IntegrityException

Descriptor Exceptions:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The table [brett] is not present in this descriptor. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: A non-read-only mapping must be defined for the sequence number field. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Runtime Exceptions:

at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createDeployFailedPersistenceException(EntityManagerSetupImpl.java:866)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:806)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:205)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:305)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:337)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:303)
at no.hib.dat101.database.Emh.slettAlt(Emh.java:137)
at no.hib.dat101.main.Main_Tekst.main(Main_Tekst.java:12)

Caused by: Exception [EclipseLink-28019] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.EntityManagerSetupException Exception Description: Deployment of PersistenceUnit [eclipselink] failed. Close all factories for this PersistenceUnit. Internal Exception: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.IntegrityException

Descriptor Exceptions:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The table [brett] is not present in this descriptor. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: A non-read-only mapping must be defined for the sequence number field. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Runtime Exceptions:

at org.eclipse.persistence.exceptions.EntityManagerSetupException.deployFailed(EntityManagerSetupException.java:239)
... 8 more

Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.IntegrityException

Descriptor Exceptions:

Exception [EclipseLink-93] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: The table [brett] is not present in this descriptor. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Exception [EclipseLink-41] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): org.eclipse.persistence.exceptions.DescriptorException Exception Description: A non-read-only mapping must be defined for the sequence number field. Descriptor: RelationalDescriptor(no.hib.dat101.entities.Spill --> [DatabaseTable(stigespill.spill)])

Runtime Exceptions:

at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:701) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:637) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:568) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:804) at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.loginAndDetectDatasource(DatabaseSessionImpl.java:748) at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:253) at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:728) ... 6 more<code>

1 个答案:

答案 0 :(得分:0)

在一个案例中,为了让@Table正常工作,我还必须添加catalog。另外,我必须在@Entity中命名该表。尝试:

@Entity(name="spill")
@Table(name="spill",schema = "stigespill", catalog="public")