JPA:建模Map <entity,entity =“”> </entity,>

时间:2012-05-10 00:16:06

标签: jpa

使用EclipseLink为以下模型生成数据库表时遇到异常:

 @Entity
 @Table(name="RXRACTSPOT")
 public class ActivitySpot implements Serializable,IsSerializable {
    .....

    @OneToMany
    private Map<CustomAttributeDefinition, CustomAttributeRestriction> customAttributes;

-

@Entity
@Table(name="RXRCUSTATTRREST")
public class CustomAttributeRestriction implements Serializable

-

@Entity
@Table(name="RXRCUSTATTRDEF")
public class CustomAttributeDefinition implements Serializable

我遇到以下异常:

  

线程“main”中的异常javax.persistence.PersistenceException:Exception&gt; [EclipseLink-0](Eclipse Persistence Services - 2.1.2.v20101206-r8635):org.eclipse.persistence.exceptions.IntegrityException

描述符例外:

  

异常[EclipseLink-93](Eclipse Persistence Services - 2.1.2.v20101206-r8635):org.eclipse.persistence.exceptions.DescriptorException   异常说明:此描述符中不存在[RXRCUSTATTRREST]表。   描述符:RelationalDescriptor(com.rubiconred.activitystream.core.model.ActivitySpot - &gt; [DatabaseTable(RXRACTSPOT)])

运行时例外:

  

java.lang.IndexOutOfBoundsException:Index:0,Size:0

at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:417)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:164)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:221)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:209)
at com.rubiconred.activitystream.database.ActivityStreamDatabaseUtils.dropAndCreateTables(ActivityStreamDatabaseUtils.java:64)
at com.rubiconred.soauiext.server.db.CreateOneSpotDatabases.main(CreateOneSpotDatabases.java:16)

引起:异常[EclipseLink-0](Eclipse Persistence Services - 2.1.2.v20101206-r8635):org.eclipse.persistence.exceptions.IntegrityException

如果我在RXRACTSPOT中删除了Map,则会成功创建表RXRCUSTATTREST和RXRCUSTATTRDEF。使用Map既不会创建表,也会抛出异常。我怀疑我在地图上遗漏了一些注释,但我无法找到一个以密钥和值作为实体的地图的示例。

1 个答案:

答案 0 :(得分:1)

好像是一个错误。试试最新版本,如果仍然发生,请记录一个错误。

您还可以创建另一个Entity类来表示三向连接表,而不是使用Map。