Using @Id to set autoicrement field
msly Jul 22, 2005 6:57 PMI have a Sybase ASA database
I need to have the a column named survey_id autoincrement. Autoincrement is the type for ASA not Identity like ASE.
Here is the field definition
survey_id autoincrement
I have this working in a CMP 2.1 implementation but I am trying to get this going with EJB 3.0.
Here is the Entity Bean
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratorType;
//import javax.persistence.GeneratorType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "survey")
public class Survey {
private Integer surveyId;
private String surveyName;
private String surveyDescription;
private int surveyQuestionCount;
private String surveyPasswordProtect;
private String surveyPassword;
private String surveyActive;
private String userUsername;
public Survey () { }
public Survey(String active, String description, String name, String password, String protect, int count, String username) {
surveyActive = active;
surveyDescription = description;
surveyName = name;
surveyPassword = password;
surveyPasswordProtect = protect;
surveyQuestionCount = count;
userUsername = username;
}
@Column(name = "survey_active")
public String getSurveyActive() {
return surveyActive;
}
public void setSurveyActive(String surveyActive) {
this.surveyActive = surveyActive;
}
@Column(name = "survey_description")
public String getSurveyDescription() {
return surveyDescription;
}
public void setSurveyDescription(String surveyDescription) {
this.surveyDescription = surveyDescription;
}
@Id(generate = GeneratorType.AUTO)
@Column(name = "survey_id")
public Integer getSurveyId() {
return surveyId;
}
public void setSurveyId(Integer surveyId) {
this.surveyId = surveyId;
}
@Column(name = "survey_name")
public String getSurveyName() {
return surveyName;
}
public void setSurveyName(String surveyName) {
this.surveyName = surveyName;
}
@Column(name = "survey_password")
public String getSurveyPassword() {
return surveyPassword;
}
public void setSurveyPassword(String surveyPassword) {
this.surveyPassword = surveyPassword;
}
@Column(name = "survey_password_protect")
public String getSurveyPasswordProtect() {
return surveyPasswordProtect;
}
public void setSurveyPasswordProtect(String surveyPasswordProtect) {
this.surveyPasswordProtect = surveyPasswordProtect;
}
@Column(name = "survey_question_count")
public int getSurveyQuestionCount() {
return surveyQuestionCount;
}
public void setSurveyQuestionCount(int surveyQuestionCount) {
this.surveyQuestionCount = surveyQuestionCount;
}
@Column(name = "user_username")
public String getUserUsername() {
return userUsername;
}
public void setUserUsername(String userUsername) {
this.userUsername = userUsername;
}
}
1)Here are the errors with the following setting: @Id(generate = GeneratorType.IDENTITY)
15:18:44,015 WARN [JDBCExceptionReporter] SQL Error: 504, SQLState: 52W09
15:18:44,015 ERROR [JDBCExceptionReporter] ASA Error -265: Procedure 'identity' not found
2) Here is the error with the following setting: @Id
ids for this class must be manually assigned before calling save():
3) Here are the errors with the following setting @Id(generate = GeneratorType.AUTO)
16:07:27,515 WARN [JDBCExceptionReporter] SQL Error: 504, SQLState: 52W09
16:07:27,515 ERROR [JDBCExceptionReporter] ASA Error -265: Procedure 'identity' not found
What am I missing here? Any help would be appreciated.
Do i need some kind of override in an XML file?
Here is one more clue
If I convert the surveyId field of the bean to int and set the @Id(generate = GenratorType.NONE) it inserts a row with survey_d 0. It fails the second time of course.
Mike