-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem: org.springframework.dao.DataIntegrityViolationExcep
PostPosted: Fri Mar 16, 2007 4:32 am 
Newbie

Joined: Thu Mar 15, 2007 12:22 am
Posts: 1
Oops! Something wrong!
Problem: org.springframework.dao.DataIntegrityViolationException: Hibernate operation: could not insert: [com.xibos.calendar.model.RepeatEventTypeOne]; SQL [insert into calendar_repeating_event_type_one (repeat_on, repeat_time_period, event_end_date, repeat_date, repeat_id) values (?, ?, ?, ?, ?)]; The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL070316005050770' defined on 'CALENDAR_REPEATING_EVENT_TYPE_ONE'.; nested exception is SQL Exception: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL070316005050770' defined on 'CALENDAR_REPEATING_EVENT_TYPE_ONE'. [Show Details]


The situation in background is :
I have two classes named RepeatEventTypeOne and RepeatEventType Two respectively and those will extends one abstract class RepeatEvent.

code of classes as given below.]


RepeatEvent.java
----------------
/*
* RepeatEvent.java
*
* Created on April 12, 2006, 2:42 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.xibos.calendar.model;

import java.util.Calendar;
import java.util.Date;
import java.util.List;


/**
* @author sajin
* @version $Id: RepeatEvent.java,v 1.12 2006/05/16 05:39:57 sajin Exp $
* @hibernate.class table="calendar_repeating_event" lazy="false"
*/
public abstract class RepeatEvent {
private Long id;
public abstract List getDates(Calendar startDate,Calendar endDate);
public abstract String getRepeatDescription(Calendar startDate);

/**
* @hibernate.id column="id" generator-class="identity" unsaved-value="null"
* type="java.lang.Long"
*/
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

}



RepearEventTypeOne.java
---------------------------------
/*
* RepeatingEventTypeOne.java
*
* Created on April 12, 2006, 2:56 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package com.xibos.calendar.model;

import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import com.xibos.calendar.ui.CalendarUIConstants;



/**
* @author sajin
* @version $Id: RepeatEventTypeOne.java,v 1.24 2006/05/16 07:47:05 sajin Exp $
* @hibernate.joined-subclass table="calendar_repeating_event_type_one" lazy="false" dynamic-insert="true" extends="com.xibos.calendar.model.RepeatEvent" dynamic-update="true"
* @hibernate.joined-subclass-key column="repeat_id" not-null="true"
*/
public class RepeatEventTypeOne extends RepeatEvent{
private String repeatOn;
private String repeatTimePeriod;
private Date repeatDate;
private Date eventEndDate;

/** Creates a new instance of RepeatingEventTypeOne */

public RepeatEventTypeOne() {
}

/**
* Returns a list of dates between the start and end dates with the specified interval.
*
* @param dateStart the startingDate
* @param dateEnd the endingDate
* @param interval the interval
* @return a List object of dates
*/
public List getDates(Calendar dateStart,Calendar dateEnd){
List dates=new ArrayList();

if(repeatOn.equalsIgnoreCase(CalendarUIConstants.EVERY)){
if(repeatTimePeriod.equalsIgnoreCase(CalendarUIConstants.DAY)){
dates=repeatInEveryDay(dateStart,dateEnd);
}else if(repeatTimePeriod.equalsIgnoreCase(CalendarUIConstants.MONTH)){
dates=repeatInEveryMonth(dateStart,dateEnd);
}else if(repeatTimePeriod.equalsIgnoreCase(CalendarUIConstants.WEEK)){
dates=repeatInEveryWeek(dateStart,dateEnd);
}else if(repeatTimePeriod.equalsIgnoreCase(CalendarUIConstants.YEAR)){
dates=repeatInEveryYear(dateStart,dateEnd);
}
}
return dates;
}


/**
* Returns a list of dates repeating everyday between the start and end dates
*
* @param dateStart the startingDate
* @param dateEnd the endingDate
* @return a List object of dates
*/
private List repeatInEveryDay(Calendar dateStart,Calendar dateEnd){
ArrayList dates=new ArrayList();
Calendar startDate=new GregorianCalendar();
Calendar repeatDay=new GregorianCalendar();

repeatDay.setTime(repeatDate);
if((repeatDay.after(dateStart)&&repeatDay.before(dateEnd))||repeatDay.after(dateEnd)){
startDate.setTime(repeatDay.getTime());
}else{
startDate.setTime(dateStart.getTime());
}
startDate.set(Calendar.SECOND,1);
while(startDate.before(dateEnd)&&isBefore(startDate.getTime(),eventEndDate)) {
dates.add(startDate.getTime());
startDate.add(Calendar.DATE,1);

}
return dates;

}

/**
* Returns a list of dates repeating every month between the start and end dates
*
* @param dateStart the startingDate
* @param dateEnd the endingDate
* @return a List object of dates
*/
private List repeatInEveryMonth(Calendar dateStart,Calendar dateEnd ) {
boolean isDAY=dateEnd.getTimeInMillis()-dateStart.getTimeInMillis()<=(24*60*60*1000)?true:false;
ArrayList dates=new ArrayList();
Calendar startDate=new GregorianCalendar();
Calendar repeatDay=new GregorianCalendar();
repeatDay.setTime(repeatDate);
if(repeatDay.after(dateStart)&&repeatDay.before(dateEnd)){
startDate.setTime(repeatDay.getTime());
}else{
startDate.setTime(dateStart.getTime());
}
startDate.set(Calendar.SECOND,1);
while(startDate.before(dateEnd)&&isBefore(startDate.getTime(),eventEndDate)){
if(isDAY&&startDate.get(Calendar.DATE)==repeatDay.get(Calendar.DATE)){
dates.add(startDate.getTime());
}else if(!isDAY){
startDate.set(Calendar.DATE,repeatDay.get(Calendar.DATE));
dates.add(startDate.getTime());
}
startDate.add(Calendar.MONTH,1);
}
return dates;
}


/**
* Returns a list of dates repeating every week between the start and end dates
*
* @param dateStart the startingDate
* @param dateEnd the endingDate
* @return a List object of dates
*/
private List repeatInEveryWeek(Calendar dateStart,Calendar dateEnd) {
ArrayList dates=new ArrayList();
Calendar startDate=new GregorianCalendar();
Calendar repeatDay=new GregorianCalendar();
repeatDay.setTime(repeatDate);
if(repeatDay.after(dateStart)&&repeatDay.before(dateEnd)){
startDate.setTime(repeatDay.getTime());
}else{
startDate.setTime(dateStart.getTime());
}

while(startDate.before(dateEnd)&&isBefore(startDate.getTime(),eventEndDate)){
if(startDate.get(Calendar.DAY_OF_WEEK)==repeatDay.get(Calendar.DAY_OF_WEEK)){

dates.add(startDate.getTime());
}
startDate.add(Calendar.DATE,1);
}
return dates;
}


/**
* Returns a list of dates repeating every year between the start and end dates
*
* @param dateStart the startingDate
* @param dateEnd the endingDate
* @return a List object of dates
*/
private List repeatInEveryYear(Calendar dateStart,Calendar dateEnd ) {
ArrayList dates=new ArrayList();
Calendar startDate=new GregorianCalendar();
Calendar repeatDay=new GregorianCalendar();
repeatDay.setTime(repeatDate);
repeatDay.set(Calendar.YEAR,dateStart.get(Calendar.YEAR));
boolean isDay=false;
if((dateEnd.get(Calendar.MONTH)-dateStart.get(Calendar.MONTH))<1&&(dateEnd.get(Calendar.YEAR)-dateStart.get(Calendar.YEAR))<1){
isDay=true;
}
if((repeatDay.after(dateStart)&&repeatDay.before(dateEnd))||isDay){
if(isBefore(dateStart.getTime(),eventEndDate)) {
if(isDay){
if((dateStart.get(Calendar.DATE)==repeatDay.get(Calendar.DATE))&&(dateStart.get(Calendar.MONTH)==repeatDay.get(Calendar.MONTH))) dates.add(startDate.getTime());
}else{ dates.add(repeatDay.getTime());}
}
}
return dates;
}


/**
*Returns the value of repeatOn
* @hibernate.property column="repeat_on" type="java.lang.String"
*/

public String getRepeatOn() {
return repeatOn;
}

/**
* Sets the value of repeatOn
*/
public void setRepeatOn(String repeatOn) {
this.repeatOn = repeatOn;
}

/**
* Returns the value of repeatTimePeriod
* @hibernate.property column="repeat_time_period" type="java.lang.String"
*/

public String getRepeatTimePeriod() {
return repeatTimePeriod;
}


/**
*Sets the value of repeatTimePeriod
*/
public void setRepeatTimePeriod(String repeatTimePeriod) {
this.repeatTimePeriod = repeatTimePeriod;
}


/**
*Checks whether an end date exists or not
*
*@return true if there is an end date
*
*/
public Boolean getHasEndDate() {
if(getEventEndDate()!=null)return true;
else return false;
}



/**
* Returns the eventEndDate
* @hibernate.property column="event_end_date" type="java.util.Date"
*/
public Date getEventEndDate() {
return eventEndDate;
}

/**
*Sets the eventEndDate
*@param eventEndDate event ending date
*/
public void setEventEndDate(Date eventEndDate) {
this.eventEndDate = eventEndDate;
}

/**
* Returns the repeatDate.
* @return Date
* @hibernate.property column="repeat_date" type="java.util.Date"
*/
public Date getRepeatDate() {
return repeatDate;
}

/**
*Sets the repeatDate
*@param repeatDate repeating date
*/
public void setRepeatDate(Date repeatDate) {
this.repeatDate = repeatDate;
}

/**
*Checks whether the given date is after end date
*
*@param date the date to be checked
*@param eventEndDate the end date
*
*@return true if the date is before end date
*
*/
private boolean isBefore(Date date,Date eventEndDate ){
boolean flag=true;
Calendar endDate=new GregorianCalendar();
if(eventEndDate!=null){
endDate.setTime(eventEndDate);
endDate.add(Calendar.DATE,1);
if(date.after(endDate.getTime())){
flag=false;
}
}
return flag;
}

/**
* Returns an object of type StringBuffer.
*
* @param startDate the Calendar Object to get start date value in description.
* @return hasCalendar boolean value.
*/
public String getRepeatDescription(Calendar dateStart){
DateFormat localFormat = DateFormat.getDateInstance();
StringBuffer description=new StringBuffer();
description.append("[Repeat on every "+repeatTimePeriod);
description.append(" from "+localFormat.format(dateStart.getTime()));
if(getHasEndDate()){description.append(" to "+localFormat.format(eventEndDate)+"]");} else{ description.append(" no end date ]");}
return description.toString();
}

}



RepeatEventTypeTwo.java
----------------------------
Same as RepeatEventTypeOne.java.......only some difference in fields.

My problem is while saving or updating.....in DERBY as database ....not all times but some time ...showing above error message.

There is no problem with MySQL database................PLZ HELP ME


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.