users@glassfish.java.net

Strange Behavior Toplink Essentials 2.0

From: <glassfish_at_javadesktop.org>
Date: Fri, 13 Jul 2007 21:06:43 PDT

The environment is:
Glassfish v2 b53
Oracle TopLink Essentials - 2.0 (Build b53-rc (06/27/2007)

Domain objects:
Telephone extends PartyContactMechanism extends AbstractEntity
AbstractEntity is a @MappedSuperclass
PartyContactMechanism is an @Entity and is abstract
Telephone is an @Entity
Telephone contains an embedded @TelecommNumberType
PartyContactMechanism is related @OnetoOne to a Party (Person)

I am searching for a Person by HomeTelephone.....
SELECT t FROM Telephone t WHERE t.teleCommNumber = :phoneNumber
AND t.telephoneType = com.xxx.cms.domain.contact.mechanism.Telephone.TelephoneType.HOME

When I execute the following query out of the container, that is Java SE, the following SQL is generated

[TopLink Fine]: 2007.07.13 09:55:11.775--ServerSession(886220)--Connection(2416253)--Thread(Thread[main,5,main])--SELECT t0.PCM_POID, t0.PCM_TYPE, t0.FROM_DATE, t0.THRU_DATE, t0.COMMENT, t0.VERSION, t0.PARTY_POID, t1.TELEPHONE_POID, t1.TELEPHONETYPE, t1.CONTACT_NUMBER, t1.COUNTRY_CODE, t1.AREA_CODE, t1.EXTENSION FROM PARTY_CONTACT_MECHANISM t0, TELEPHONE t1 WHERE ((((((t1.CONTACT_NUMBER = ?) AND (t1.COUNTRY_CODE = ?)) AND (t1.AREA_CODE = ?)) AND (t1.EXTENSION = ?)) AND (t1.TELEPHONETYPE = 'HOME')) AND ((t1.TELEPHONE_POID = t0.PCM_POID) AND (t0.PCM_TYPE = 'TELEPHONE')))
bind => [6345554, , 320, ]

Notice the bold....

Now when I expose this as a EJB3 StatelessSessionBean and call it using a remote client, or as a JAX-WS 2.1.1 based Webservice using @Webservice the following SQL is generated.

Call: SELECT t0.PCM_POID, t0.PCM_TYPE, t0.FROM_DATE, t0.THRU_DATE, t0.COMMENT, t0.VERSION, t0.PARTY_POID, t1.TELEPHONE_POID, t1.TELEPHONETYPE, t0.CONTACT_NUMBER, t0.COUNTRY_CODE, t0.AREA_CODE, t0.EXTENSION FROM PARTY_CONTACT_MECHANISM t0, TELEPHONE t1 WHERE ((((((t0.CONTACT_NUMBER = ?) AND (t0.COUNTRY_CODE = ?)) AND (t0.AREA_CODE = ?)) AND (t0.EXTENSION = ?)) AND (t1.TELEPHONETYPE = 'HOME')) AND ((t1.TELEPHONE_POID = t0.PCM_POID) AND (t0.PCM_TYPE = 'TELEPHONE')))
bind => [6345554, , 320, ]

Again notice the bold. When accessed in remotely the generated SQL is DIFFERENT!! Suddenly the fields associated with TELEPHONE t1 are switched to PARTY_CONTACT_MECHANISM t0. Those values are mapped to the @Embedded TelecommNumberType....

This of course results in the following exception:
java.sql.SQLSyntaxErrorException: Column 'T0.CONTACT_NUMBER' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE statement then 'T0.CONTACT_NUMBER' is not a column in the target table.

Any ideas what could be causing this very very odd behavior?
[Message sent by forum member 'slepage' (slepage)]

http://forums.java.net/jive/thread.jspa?messageID=226653