- This topic has 2 replies, 2 voices, and was last updated 15 years, 10 months ago by Mike Suiter.
-
AuthorPosts
-
Mike SuiterMemberI 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()); }
Riyad KallaMemberTo 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.
Mike SuiterMemberI 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.eventDateHere 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?
-
AuthorPosts