[hibernate-issues] [Hibernate-JIRA] Created: (EJB-348) Problem with CasCadeType.ALL during persist when processing OneToMany hierarchy relationship

George Daswani (JIRA) noreply at atlassian.com
Wed Mar 26 19:41:33 EDT 2008


Problem with CasCadeType.ALL during persist when processing OneToMany hierarchy relationship
--------------------------------------------------------------------------------------------

                 Key: EJB-348
                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-348
             Project: Hibernate Entity Manager
          Issue Type: Bug
          Components: EntityManager
    Affects Versions: 3.3.2.GA
         Environment: 3.2.2.GA , Microsoft SQL Server 2000 SP4, JTDS 1.2.2 Drive
            Reporter: George Daswani
         Attachments: TestProject.zip

[Computer]

private Set<NetworkInterface> networkInterfaces ;

@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "computer")
@JoinColumn(name = "COMPUTER_ID")
public Set<NetworkInterface> getNetworkInterfaces()
--------------------- 
[Network Interface]

private Computer computer;
private Set<IPAddress> ipAddresses;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "CMP_ID", nullable = false)
public Computer getComputer()

@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "networkInterface")
@JoinColumn(name = "IP_ID")
public Set<IPAddress> getIPAddresses()
--------------------- 
[IPAddress]

private NetworkInterface networkInterface;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "NI_ID", nullable = false)
public NetworkInterface getNetworkInterface()

---------------------------------------------------------------------------------------------------
Note: works just fine with TopLink Essentials.

When two or more IP addresses are added to a network interface, Hibernate JPA errors out when persisting the "Computer".

Example:

Computer computer = new Computer();

// ASSIGNED ID
computer.setId("COMPUTER1");
computer.setAssetTag("AC1");

NetworkInterface networkInterface = new NetworkInterface();
networkInterface.setMacAddress("00:00:00:00:00:00");

computer.addNetworkInterface(networkInterface);
IPAddress ipAddress1 = new IPAddress();
ipAddress1.setIpAddress("192.168.1.1");

networkInterface.addIpAddress(ipAddress1);
IPAddress ipAddress2 = new IPAddress();
ipAddress2.setIpAddress("192.168.1.2");

networkInterface.addIpAddress(ipAddress2);

entityManager.persist(computer);

---------------- ERROR -----------
- INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK92788228A23'. The conflict occurred in database 'TestDB', table 'NI', column 'NI_ID'.
- Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
Caused by: java.sql.BatchUpdateException: INSERT statement conflicted with COLUMN FOREIGN KEY constraint 'FK92788228A23'. The conflict occurred in database 'TestDB', table 'NI', column 'NI_ID'.

seems like some sort of wrong INSERTION order.

I've attached the eclipse project with the - test case in "test/Test.java"



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list