Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » @EmbeddedId in conjunction with InheritanceType.JOINED does not generate PK-Field
@EmbeddedId in conjunction with InheritanceType.JOINED does not generate PK-Field [message #728697] Fri, 23 September 2011 16:45 Go to next message
Hannes  is currently offline Hannes Friend
Messages: 14
Registered: March 2011
Junior Member
Hello,

I have a class, using @EmbeddedId as primary key:


@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="PAE")
@DiscriminatorColumn(name="DTYPE", discriminatorType=DiscriminatorType.STRING,length=20)
@DiscriminatorValue("R")
public class PersistentAccountancyEntry implements AccountancyEntry {
@EmbeddedId
@AttributeOverride(name="id", column=@Column(name="ENTRY_ID"))
private AccountancyEntryIdentifier accountancyEntryIdentifier;


And a subclass of that class:



@Entity
@Table(name="PPE")
@DiscriminatorValue("P")
public class ProductPaymentEntry extends PersistentAccountancyEntry
{
@Embedded
@AttributeOverride(name = "id", column = @Column(name = "ORDER_ID"))
private OrderIdentifier orderIdentifier;

@Embedded
@AttributeOverride(name = "id", column = @Column(name = "UID"))
private UserIdentifier userIdentifier;


Which results in tables being generated as follows:


[EL Fine]: Connection(941535430)--DROP TABLE PAE
[EL Fine]: Connection(941535430)--CREATE TABLE PAE (DTYPE VARCHAR(20), DATE TIMESTAMP, DESCRIPTION VARCHAR(255), VALUE BLOB(2147483647), ENTRY_ID VARCHAR(255))
[EL Fine]: Connection(941535430)--DROP TABLE PPE
[EL Fine]: Connection(941535430)--CREATE TABLE PPE (ENTRY_ID VARCHAR(255) NOT NULL, ORDER_ID VARCHAR(255), UID VARCHAR(255) NOT NULL, PRIMARY KEY (ENTRY_ID, UID))


Notably, ENTRY_ID is not a primary key field on table PAE, instead the table PPE has a composite primary key of ENTRY_ID and UID. UID is just a foreign key, not a composite primary key. (OrderIdentifier is an @EmbeddedId in an entirely different class.)
All this would matter much, but some queries fail:


EntityManager em = emf.createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<PersistentAccountancyEntry> q = cb
.createQuery(PersistentAccountancyEntry.class);
Root<PersistentAccountancyEntry> r = q
.from(PersistentAccountancyEntry.class);
Predicate p = cb.between(r.get(PersistentAccountancyEntry_.date),
from.toDate(), to.toDate());
q.where(p);
TypedQuery<PersistentAccountancyEntry> tq = em.createQuery(q);



[EL Warning]: 2011-09-23 18:38:44.388--UnitOfWork(1237880619)--Exception [EclipseLink-6044] (Eclipse Persistence Services - 2.3.0.v20110604-r9504): org.eclipse.persistence.exceptions.QueryException
Exception Description: The primary key read from the row [ArrayRecord(
PAE.DTYPE => R
PAE.DATE => 2011-09-23 18:38:37.219
PAE.DESCRIPTION => null
PAE.VALUE => [B@6153e0c0
PAE.ENTRY_ID => 45aabaaf-cf87-4261-b0b0-f13a8b5e5ead)] during the execution of the query was detected to be null. Primary keys must not contain null.
Query: ReadAllQuery(referenceClass=PersistentAccountancyEntry sql="SELECT DISTINCT DTYPE FROM PAE WHERE (DATE BETWEEN ? AND ?)")


Now, ENTRY_ID should be the primary key field, and it is obviously not null. What am I doing wrong?
Re: @EmbeddedId in conjunction with InheritanceType.JOINED does not generate PK-Field [message #729598 is a reply to message #728697] Mon, 26 September 2011 15:33 Go to previous message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
Include the AccountancyEntryIdentifier source.

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Previous Topic:Tool to run JPQL queries
Next Topic:sync error with eclipselink
Goto Forum:
  


Current Time: Sat Apr 27 03:47:20 GMT 2024

Powered by FUDForum. Page generated in 0.02481 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top