Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: AW: [eclipselink-users] @ElementCollection with @Embeddables

Hi,

I don't know why this message got sent twice, sorry for that.

I opened a bug for the DDL issue here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=305856

Rafał

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Swierzynski, Rafal
Sent: Monday, March 15, 2010 2:50 PM
To: EclipseLink User Discussions
Subject: RE: AW: [eclipselink-users] @ElementCollection with @Embeddables

Hi Tom,

Thanks for looking into this.
Do you mean:
@CollectionTable(name = "SomeMap", joinColumns = JoinColumn(columnDefinition = "my DDL"))
?

As for the bug, is it ok to just link to this discussion after a brief description, or do you prefer that I repeat the whole problem in the bug body verbatim? What about the attachment?

Regards,
Rafał

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Tom Ware
Sent: Monday, March 15, 2010 2:38 PM
Cc: EclipseLink User Discussions
Subject: Re: AW: [eclipselink-users] @ElementCollection with @Embeddables

Another workaround:

Explicitly add the joinColumn with the correct type to the annotation for the 
collecttion.

Tom Ware wrote:
> Hi Rafal,
> 
>   Please enter a bug.  The issue is with our DDL generation.   The 
> "SomeMap" table does not have the correct type for SomeENtity_ID.
> 
>   The workaround is to use our option of generating the DDL as a 
> sql-script, then to edit the sql-script and run it against the DB.
> 
> -Tom
> 
> Swierzynski, Rafal wrote:
>> Hi Tom,
>>
>> yes, I am using the auto generated DDL. The statements are (I omit 
>> drops and the sequence table):
>> CREATE TABLE SOMEENTITY (ID BIGINT NOT NULL, PRIMARY KEY (ID))
>> CREATE TABLE SomeMap (VALUE VARCHAR(255), KEY VARCHAR(255), 
>> SomeEntity_ID VARCHAR(255))
>>
>> The insert statements are (after // is what gets bound to the 
>> parameters):
>> INSERT INTO SOMEENTITY (ID) VALUES (?) // bind => [1]
>> INSERT INTO SomeMap (SomeEntity_ID, VALUE, KEY) VALUES (?, ?, ?) // 
>> bind => [1, stół, pl]
>> INSERT INTO SomeMap (SomeEntity_ID, VALUE, KEY) VALUES (?, ?, ?) // 
>> bind => [1, table, en]
>> INSERT INTO SomeMap (SomeEntity_ID, VALUE, KEY) VALUES (?, ?, ?) // 
>> bind => [1, Tish, de]
>>
>> And eventually, the selects:
>> SELECT ID FROM SOMEENTITY WHERE (ID = ?) // bind => [1]
>> SELECT VALUE, KEY FROM SomeMap WHERE (SomeEntity_ID = ?) // bind => [1]
>>
>> And the last one results in this:
>> ERROR: operator does not exist: character varying = bigint
>>   Hint: No operator matches the given name and argument type(s). You 
>> might need to add explicit type casts.
>> 'character varying' is the data type of the SomeMap.PERSON_ID column 
>> as reported by PGadmin, so it means it is the PostgreSQL name for 
>> VARCHAR.
>>
>> In the DDL the SomeMap.SomeEntity_ID foreign key is of type VARCHAR 
>> whereas SomeEntity.id is BIGINT. I didn't think of looking in this 
>> direction, I thought my mapping was wrong, but I couldn't figure out 
>> what is wrong. We don't have such an issue as we don't use EL DDL in 
>> production.
>> I had a similar issue with Map collection.
>>
>> Does this mean it is a EclipseLink DDL generation issue? If not, what 
>> else do I need to do to make this work?
>>
>> Regards,
>> Rafał
>>
>> ________________________________________
>> Von: eclipselink-users-bounces@xxxxxxxxxxx 
>> [eclipselink-users-bounces@xxxxxxxxxxx] im Auftrag von Tom Ware 
>> [tom.ware@xxxxxxxxxx]
>> Gesendet: Freitag, 12. März 2010 16:39
>> An: EclipseLink User Discussions
>> Betreff: Re: [eclipselink-users] @ElementCollection with @Embeddables
>>
>> Hi Rafal,
>>
>>    What do the insert statements look like when the objects are inserted.
>> (persistence unit property eclipselink.logging.level=FINEST)?
>>
>>    Are you using EclipseLink to gennerate DDL? What do the table creation
>> statements look like?
>>
>> -Tom
>>
>> Swierzynski, Rafal wrote:
>>> Hi,
>>>
>>> I have such collection mapping:
>>>
>>> @ElementCollection(fetch = FetchType.EAGER)
>>> @CollectionTable(name = "SomeMap")
>>> private Set<Pair> someSet = new HashSet<Pair>();
>>>
>>> with Pair being defined as:
>>>
>>> @Embeddable
>>> public class Pair {
>>>
>>>     private String key;
>>>
>>>     private String value;
>>>
>>>     public Pair(String key, String value) {
>>>         this.key = key;
>>>         this.value = value;
>>>     }
>>>
>>>     protected Pair() {
>>>     }
>>>
>>>     public String getKey() {
>>>         return key;
>>>     }
>>>
>>>     public String getValue() {
>>>         return value;
>>>     }
>>> }
>>>
>>> The code to persist is as follows:
>>>
>>> EntityManagerFactory emf = 
>>> Persistence.createEntityManagerFactory("TestJPA");
>>> EntityManager em = emf.createEntityManager();
>>> EntityTransaction tx = em.getTransaction();
>>> tx.begin();
>>> SomeEntity s = new SomeEntity();
>>> s.put("en", "table");
>>> s.put("de", "Tish");
>>> s.put("pl", "stół");
>>> em.persist(s);
>>> tx.commit();
>>>
>>> em.clear();
>>>
>>> s = em.find(SomeEntity.class, s.getId());
>>>
>>> The entity is persisted in the database in the first transaction. 
>>> However, when the entity is read again, I get:
>>>
>>> Exception in thread "main" Local Exception Stack:
>>> Exception [EclipseLink-4002] (Eclipse Persistence Services - 
>>> 2.0.0.v20091127-r5931): 
>>> org.eclipse.persistence.exceptions.DatabaseException
>>> Internal Exception: org.postgresql.util.PSQLException: ERROR: 
>>> operator does not exist: character varying = bigint
>>>   Hint: No operator matches the given name and argument type(s). You 
>>> might need to add explicit type casts.
>>>   Position: 53
>>> Error Code: 0
>>> Call: SELECT VALUE, KEY FROM SomeMap WHERE (SomeEntity_ID = ?)
>>>       bind => [1]
>>> Query: ReadAllQuery(name="someSet" referenceClass=Pair sql="SELECT 
>>> VALUE, KEY FROM SomeMap WHERE (SomeEntity_ID = ?)")
>>>
>>>
>>> When I looked into the generated table for the collection, I noticed 
>>> that SomeEntity_ID is of type "character varying".
>>>
>>> What am I doing wrong here?
>>> A project is attached to this email with the whole source code.
>>>
>>> Regards,
>>> Rafał
>>>
>>>
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>
>>
>> _______________________________________________
>> eclipselink-users mailing list
>> eclipselink-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users




Back to the top