Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Error in Eclipselink with @ElementCollectionMap and @JoinColumn

Actually this is supported by EclipseLink, and seems to be working correctly
for inserts, but failing on the update.  Looking at the code in
DirectCollectionMapping and DirectMapMapping it is wrong for updates, but
right for insert, so please log a bug for this.


Guy Pelletier wrote:
> 
> You currently can not use a non-id field within the join columns of your 
> element collection.
> 
> Note: This is an optional component of the spec (section 10.1.21):
> 
> "Support for referenced columns that are not primary key columns of the 
> referenced table is optional. Applications that use such mappings will not 
> be portable."
> 
> Feel free to log an enhancement request.
> 
> Cheers,
> Guy
> 
> ----- Original Message ----- 
> From: "vide" <vidas.timukas@xxxxxxxxx>
> To: <eclipselink-users@xxxxxxxxxxx>
> Sent: Wednesday, March 10, 2010 8:22 AM
> Subject: [eclipselink-users] Error in Eclipselink with
> @ElementCollectionMap 
> and @JoinColumn
> 
> 
>>
>> Hello,
>>
>> I stuck with problem when I try to use @ElementCollection join to Map
>> with
>> @JoinColumn, which is not a primary key. When I try to update a Map,
>> JoinColumn value becomes null and Eclipselink return with error.
>>
>> My entity:
>> ---------------- 
>> @Entity
>> @Table(name = "cust")
>> public class Customer implements Serializable {
>>    private static final long serialVersionUID = 1L;
>>    @Id
>>    @GeneratedValue(strategy = GenerationType.IDENTITY)
>>    @Column(name = "id")
>>    private Long id;
>>    @Column(name = "name")
>>    private String name;
>>    @Column(name = "address", nullable = false)
>>    private String address;
>>
>>    @ElementCollection
>>    @CollectionTable(name = "address_info",
>>        joinColumns = {
>>            @JoinColumn(name = "x_address", referencedColumnName =
>> "address")
>>    })
>>    @MapKeyColumn(name = "info_tag")
>>    @Column(name = "info_value")
>>    private Map<String, String> extInfo;
>>
>>    public Customer() {
>>        extInfo = new HashMap<String, String>();
>>    }
>>
>>    public Customer(String name, String address) {
>>        this();
>>        this.name = name;
>>        this.address = address;
>>    }
>>
>>    ...Getters and setters
>> }
>>
>> Code:
>> ------------- 
>> Customer cust = new Customer("My Customer", "Arctic");
>> em.persist(cust);
>> em.flush();
>> em.refresh(cust);
>> cust.setInfo("postIndex", "12345");
>>
>> Error log:
>> ------------- 
>> FINE: INSERT INTO cust (address, name) VALUES (?, ?)
>>        bind => [Arctic, My Customer]
>> FINE: SELECT LAST_INSERT_ID()
>> FINE: SELECT id, address, name FROM cust WHERE (id = ?)
>>        bind => [1]
>> FINE: SELECT t0.info_value, t0.info_tag FROM address_info t0 WHERE
>> (t0.x_address = ?)
>>        bind => [Arctic]
>> FINE: INSERT INTO address_info (x_address, info_value, info_tag) VALUES 
>> (?,
>> ?, ?)
>>        bind => [null, 12345, postIndex]
>> FINE: SELECT 1
>> WARNING: Local Exception Stack:
>> Exception [EclipseLink-4002] (Eclipse Persistence Services -
>> 2.0.0.v20091127-r5931): 
>> org.eclipse.persistence.exceptions.DatabaseException
>> Internal Exception:
>> com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException:
>> Column 'x_address' cannot be null
>> Error Code: 1048
>> Call: INSERT INTO address_info (x_address, info_value, info_tag) VALUES 
>> (?,
>> ?, ?)
>>        bind => [null, 12345, postIndex]
>> Query: DataModifyQuery(sql="INSERT INTO address_info (x_address, 
>> info_value,
>> info_tag) VALUES (?, ?, ?)")
>>
>>
>> When I remove em.flush() and em.refresh(cust), everything works fine, 
>> until
>> next transaction, when I try to find inserted entity and make an update
>> to
>> Map, error returns. If I change JoinColumn to use entity's ID, problem
>> disappears. Why I can't use JoinColumn, different from ID column?
>>
>> Thanks
>>
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://old.nabble.com/Error-in-Eclipselink-with-%40ElementCollection-Map-and-%40JoinColumn-tp27849535p28005053.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top