Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Null @Id again after query execution

I have a (weird) inheritance structure like this:

@Entity(name = "Party")
@DiscriminatorColumn(name = "kind", discriminatorType = DiscriminatorType.STRING, length = 30)
@DiscriminatorValue("Party")
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "Party")
// other stuff
public abstract class PartyEntity ...
  @Id
  @Column(name = "id", updatable = false)
  Long id;

@MappedSuperclass
public abstract PersonMappedSuperclass extends PartyEntity...
  // various basic mappings here; no further @Id annotations

@Entity(name = "Person")
@DiscriminatorValue("Person")
@Table(name = "Person")
public class PersonEntity extends PersonMappedSuperclass...
  // more mappings; no @Id annotations
  // one to many with names, etc.

When I retrieve such an object via a particular named query, I can see in the debugger that his id property is null.  This never happened in the version of EclipseLink that shipped as part of GlassFish 3.1.

This should not be the case, correct?  Have I misunderstood what is and is not permitted in an inheritance hierarchy?

My named query in all its glory looks like this--it finds a Person based on values for certain names the person has:

SELECT p FROM Person p JOIN p.names n WHERE (n.nameType.code = 'legalFirstName' OR n.nameType.code = 'legalLastName') AND n.value LIKE :text

The resulting SQL from this is (rather suspiciously; note in particular the double "id" column retrieval--i.e. "id" is not present only in the WHERE clause but in the SELECT clause as well, with no way to distinguish between them):

SELECT
t2.kind,
[snip]
t2.version,
[snip; other t3 columns]
FROM Person t3, Party t2, Name t1, NameType t0
WHERE
(
   (
      (((t0.code = 'legalFirstName') OR (t0.code = 'legalLastName')) AND t1.nameValue LIKE 'Lair%')
      AND ((t3.id = t2.id) AND (t2.kind = 'Person'))
   )
   AND ((t1.owningPartyID = t2.id) AND (t0.id = t1.nameTypeID))
)

The resulting Person entity has a null id property.

I'm really not sure where to go next with this.

Best,
Laird

--
http://about.me/lairdnelson


Back to the top