[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Persisting a Unidirectional OneToMany fails
|
Are the mappings listed the only ones on your object? The reason EclipseLink
does this is that it computes a commit order for your objects based on the
mappings so as to be able to properly address things like sequencing and foreign
keys. In most cases where you see the issue below, it is because due to the
mappings, we need to do the inserts in that order and hence do a two stage
insert where we update the foreign key later.
-Tom
On 18/10/2012 11:49 AM, Alon Gamliel wrote:
Hi Tom,
Yes, the foreign key is not NULL in database, and I understand now this was the problem.
However I couldn't find this demand in spec (JPA2), so in some way it is a bug, and as such I think it should be noted clearly in user-guide.
-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Tom Ware
Sent: Thursday, October 18, 2012 5:15 PM
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] Persisting a Unidirectional OneToMany fails
What do your tables look like?
It looks like the service_id field on tbl_service_parameters2 is "NOT NULL".
What happens if you allow null on that field?
On 18/10/2012 11:08 AM, Alon Gamliel wrote:
I'm trying to persist a very simple Unidirectional One to Many relationship, but EclipseLink (2.3.1) fails. Is this a bug or just a stupid mistake? my code is very simple. I also posted a bug on this issue, but it was rejected and I didn't understand the reason (https://bugs.eclipse.org/bugs/show_bug.cgi?id=391279).
Service Class (Parent):
-------------------------
@Entity
@Table(name = "tbl_service2")
public class Service implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="service_id")
public long serviceID;
@Column(name="name")
public String name;
@OneToMany(cascade={CascadeType.ALL})
@JoinColumn(name="service_id", referencedColumnName="service_id")
public Set<Parameter> parameters; }
Parameter Class (Child):
-------------------------
(Of course there is "service_id" foreign key field in the database, which is not represented in the class, as it's unidirectional relation).
@Entity
@Table(name = "tbl_service_parameters2") public class Parameter
implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="param_id")
public long parameterID;
@Column(name="name")
public String name;
}
And this is the code:
-------------------------
Service service = new Service();
service.parameters = new HashSet<Parameter>();
service.name = "test";
Parameter param = new Parameter();
param.name = "test";
service.parameters.add(param);
em.persist(service);
em.flush();
I get this excaption:
-------------------------
Internal Exception: java.sql.SQLException: Field 'service_id' doesn't
have a default value Error Code: 1364
Call: INSERT INTO tbl_service_parameters2 (name) VALUES (?)
bind => [test]
_______________________________________________
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