Hi all,
I have an entity 'MyEntity' that has an attribute 'field1' which is mapped to column FIELD1.
I would like to use that field as join column to several external tables, and still have it exposed as an attribute. All external tables have the FIELD1 column annotated as Id column.
This all works (in a slightly different arrangement) when I use @JoinColumn(name = "FIELD1", insertable = false, updatable = false) for the external tables mappings.
However, is it possible to create an embeddable class, and move the external mappings in it, so I could group all external table mappings in one embeddable attribute?
I tried something like this:
@Entity
public abstract class MyEntity implements Serializable {
@Id
private Long id;
private String field1;
@Embedded
private MyEmbeddableClass ec;
....
}
@Embeddable
public class MyEmbeddableClass implements Serializable {
@OneToOne
@JoinColumn(name = "FIELD1")
private ExternalEntity1 ee1;
....
}
@Entity
public class ExternalEntity1 implements Serializable {
@Id
private String field1;
....
}
but I'm always getting exception
Exception [EclipseLink-93] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: The table [MYENTITY] is not present in this descriptor.
Descriptor: RelationalDescriptor(some.package.ExternalEntity1 --> [DatabaseTable(EXTERNALENTITY1)])
Exception [EclipseLink-41] (Eclipse Persistence Services - 1.1.1.v20090430-r4097): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: A non-read-only mapping must be defined for the sequence number field.
Descriptor: RelationalDescriptor(some.package.MyEntity --> [DatabaseTable(MYENTITY)])
Runtime Exceptions:
---------------------------------------------------------
java.lang.NullPointerException
java.lang.NullPointerException
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:111)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:163)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:150)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at weblogic.deployment.EntityManagerFactoryProxyImpl.invoke(EntityManagerFactoryProxyImpl.java:75)
at $Proxy140.createEntityManager(Unknown Source)
....
(truncated)
Is it possible to have complex attributes in an embeddable class? And, if yes, is my usecase achievable?
Thanks in advance,
Pedja