facebook

Transaction inconsistantly fails on foreign key constraint

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #293812 Reply

    Mike Suiter
    Member

    I posted this on the Spring forum with no response, so I thought to try here. I have a Spring project using OpenJPA and used the MyEclipse reverse engineering. I have a problem that occurs about 50% of the time on a foreign key constraint. Here is what I’m trying to do:

    – I get a message in via Spring remoting.
    – From this message, I check to see if a JobNode record exists in the DB. If not, I add one.
    – I then create a JobNodeStateChange record which has a foreign key to the JobNode record. A single JobNode can have many JobNodeStateChange’s. I then save the JobNodeStateChange record.

    About 50% of the time this works just fine. The other 50%, I get a foreign key constraint error and the transaction rolls back. I use the exact same data and procedure each time. In my code, I save the JobNode first, then the JobNodeStateChange second. Does this not guarantee that they’ll be saved in that order in the transaction? If not, that might be my problem.

    I’m trying to track down if this is a MyEclipse JPA reverse engineering problem, Spring problem. OpenJPA problem, etc.

    Any suggestions? Here is my method.

    
        public void onNodeStateChanged(WPStateChangeEventMessage message) {
            System.out.println("onNodeStateChanged started for Node ID " + message.getJobNodeID() + " to state " + message.getToStateName());
            JobNodeId jobNodeId = new JobNodeId(message.getDsn(), message.getJobNodeID().getID(), message.getJobNodeID().getDB());
            JobNode jobNode = jobNodeDAO.findById(jobNodeId);
            
            if (jobNode == null) {
                System.out.println("    No Job Node record for Node ID " + message.getJobNodeID());
                jobNode = new JobNode();
                jobNode.setId(jobNodeId);
                jobNode.setNodeUuid(message.getProcessNodeUuid());
                jobNode.setName(message.getName());
                jobNode.setNodeTypeId(message.getNodeTypeID());
                jobNodeDAO.save(jobNode);
            }
            else
                System.out.println("    Found Job Node record for Node ID " + message.getJobNodeID());
    
            JobNodeStateChange jobNodeStateChange = new JobNodeStateChange();
            jobNodeStateChange.setEventUuid(message.getEventUuid());
            jobNodeStateChange.setEventDate(new Timestamp(message.getEventDt().getTime()));
            jobNodeStateChange.setFromState(message.getFromStateID());
            jobNodeStateChange.setToState(message.getToStateID());
            jobNodeStateChange.setResource(message.getResource());
            jobNodeStateChange.setJobNode(jobNode);
            jobNodeStateChangeDAO.save(jobNodeStateChange);
            
            System.out.println("onNodeStateChanged completed for Node ID " + message.getJobNodeID());
        }
    
    #293879 Reply

    Riyad Kalla
    Member

    To debug if it’s an OpenJPA issue or not (my first guess) I’d say change your provider to TopLink and Hibernate and see if the behavior changes.

    #294032 Reply

    Mike Suiter
    Member

    I switched over to Hibernate and redid the reverse engineering. Now I get the following error:


    @Temporal
    should be set on a java.util.Date or java.util.Calendar property: com.workpoint.bam.domain.Milestone.eventDate

    Here is what the generated code looks like

    
        @Temporal(TemporalType.TIMESTAMP)
        @Column(name="EVENT_DATE", nullable=false, length=23)
    
        public Timestamp getEventDate() {
            return this.eventDate;
        }

    It seems that Hibernate isn’t liking the Timestamp type. Any ideas on why the MyEclipse reverse engineering didn’t create code that Hibernate likes?

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Transaction inconsistantly fails on foreign key constraint

You must be logged in to post in the forum log in