Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] No inserts happen on table

Glad to hear it is working.  You may want to specify the mappedby="appUser" and remove the JoinColumn definition on the OneToMany to avoid the duplication. 

Best Regards,
Chris

On 09/06/2010 1:15 PM, Daoud AbdelMonem Faleh wrote:
Thanks Chris for the useful insights.
I made the following modifications for others reference:

AppUserProfile:
...
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="appUser",nullable=true)
private List<Address> address;
...

Address:
...
@ManyToOne
@JoinColumn(name="appUser", nullable=true)
private AppUser appUser;

In the service code I added
em.setFlushMode(FlushModeType.COMMIT);


Everything work fine! :)

With best Regards,
Daoud AbdelMonem Faleh.

Christopher Delahunt a écrit :
  
Hello,

It does say the problem, but the field will be set via the
AppUserProfile -> Address OneToMany relationship, which is set or
Address itself would not be persisted.  Unfortunately, EclipseLink
will not set the foreign keys in a uni-directional OneToMany
relationship in the initial insert statement.  It will correct the
foreign key here in a seperate Update to the database.  The reason for
this is because the Join column is defined within the AppUserProfile,
and so only gets discovered when AppUserProfile  gets processed while
Address processing may be done before that.
So if your database allows, you can set it to delay constraint
processing until the transaction commits or turn off the constraint on
this relationship.  If that is not possible, an alternative would be
to add a ManyToOne relationship from Address to AppUserProfile for the
foreign key.  This relationship will need to be set when ever an
address is added to the AppUserProfile , but will allow EclipseLink to
populate the foreign key in the insert statement.

Best Regards,
Chris

On 09/06/2010 12:07 PM, Dominik Dorn wrote:
    
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.0.2.v20100323-r6872): org.eclipse.persistence.exceptions
.DatabaseException
Internal Exception: org.postgresql.util.PSQLException: ERROR: null value
in column "username" violates not-null constraint
Error Code: 0
Call: INSERT INTO ADDRESS (ZIPCODE, TOWN, ADDRESSLINE2, ADDRESSLINE1,
COUNTRY) VALUES (?, ?, ?, ?, ?)
       bind => [1001, Tunis, null, some place, Tunisia]

this says it all... the column "username" does not get filled in your
database table,
probably because the user is not set in the address entity.

  
      
_______________________________________________
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