DataNucleus JIRA is now in read-only mode. Raise any new issues in GitHub against the plugin that it applies to. DataNucleus JIRA will remain for the foreseeable future but will eventually be discontinued
Issue Details (XML | Word | Printable)

Key: NUCRDBMS-654
Type: Improvement Improvement
Status: Closed Closed
Resolution: Cannot Reproduce
Priority: Major Major
Assignee: Unassigned
Reporter: Ivan
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

Support 1-N relationships using Foreign-Key with element table field not null

Created: 13/Mar/13 07:12 PM   Updated: 28/Nov/13 03:29 PM   Resolved: 27/Nov/13 05:09 PM
Component/s: None
Affects Version/s: 3.2.0.release
Fix Version/s: None

File Attachments: 1. Zip Archive NUCRDBMS-654.zip (96 kB)


Datastore: Microsoft SQL Server


 Description  « Hide
Updating the N-side of a 1-N relationship by adding an element fails if the table's field is set as NOT NULLable at the datastore level. Test case attached, in summary, code like this:

            tx.begin();
            account.setName("name2");
            account.getAddresses().clear();
            Address address2=new Address("address2");
            addresses.add(address2);
            account.getAddresses().add(address2);
            
            pm.makePersistent(account);
            
            tx.commit();

The insert is executed setting a null value, so the insert fails if the field is not nullable:

INSERT INTO TEST.ADDRESS (ADDRESS,ACCOUNT_ID) VALUES (<'address2'>,<null>)

After is executed the update:

UPDATE TEST.ADDRESS SET ACCOUNT_ID=<31> WHERE ID=<2>





Ivan made changes - 13/Mar/13 07:14 PM
Field Original Value New Value
Attachment NUCRDBMS-654.zip [ 11922 ]
Andy Jefferson added a comment - 27/Nov/13 05:09 PM
Test doesn't show any problem that I can see. Firstly if something is supposed to be not nullable then you should have
@Element(columns={@Column(name="ACCOUNT_ID", allowsNull="false")})

and when attaching the updated Account it issues SQL of
UPDATE `ACCOUNT` SET `NAME`=<'name2'> WHERE `ID`=<1>
DELETE FROM `ADDRESS` WHERE `ID`=<1>
INSERT INTO `ADDRESS` (`ADDRESS`,`ACCOUNT_ID`) VALUES (<'address2'>,<1>)

which is correct IMHO, and no exception is thrown. Suggest you update your test if meaning something else

Andy Jefferson made changes - 27/Nov/13 05:09 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Cannot Reproduce [ 5 ]
Andy Jefferson made changes - 28/Nov/13 03:29 PM
Status Resolved [ 5 ] Closed [ 6 ]